本文整理汇总了C++中PetscViewerFlush函数的典型用法代码示例。如果您正苦于以下问题:C++ PetscViewerFlush函数的具体用法?C++ PetscViewerFlush怎么用?C++ PetscViewerFlush使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PetscViewerFlush函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SNESView_NASM
PetscErrorCode SNESView_NASM(SNES snes, PetscViewer viewer)
{
SNES_NASM *nasm = (SNES_NASM*)snes->data;
PetscErrorCode ierr;
PetscMPIInt rank,size;
PetscInt i,N,bsz;
PetscBool iascii,isstring;
PetscViewer sviewer;
MPI_Comm comm;
PetscFunctionBegin;
ierr = PetscObjectGetComm((PetscObject)snes,&comm);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSTRING,&isstring);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
ierr = MPI_Allreduce(&nasm->n,&N,1,MPIU_INT,MPI_SUM,comm);CHKERRQ(ierr);
if (iascii) {
ierr = PetscViewerASCIIPrintf(viewer, " Nonlinear Additive Schwarz: total subdomain blocks = %D\n",N);CHKERRQ(ierr);
if (nasm->same_local_solves) {
if (nasm->subsnes) {
ierr = PetscViewerASCIIPrintf(viewer," Local solve is the same for all blocks:\n");CHKERRQ(ierr);
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
ierr = PetscViewerGetSingleton(viewer,&sviewer);CHKERRQ(ierr);
if (!rank) {
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
ierr = SNESView(nasm->subsnes[0],sviewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
ierr = PetscViewerRestoreSingleton(viewer,&sviewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
} else {
/* print the solver on each block */
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer," [%d] number of local blocks = %D\n",(int)rank,nasm->n);CHKERRQ(ierr);
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer," Local solve info for each block is in the following SNES objects:\n");CHKERRQ(ierr);
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer,"- - - - - - - - - - - - - - - - - -\n");CHKERRQ(ierr);
ierr = PetscViewerGetSingleton(viewer,&sviewer);CHKERRQ(ierr);
for (i=0; i<nasm->n; i++) {
ierr = VecGetLocalSize(nasm->x[i],&bsz);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(sviewer,"[%d] local block number %D, size = %D\n",(int)rank,i,bsz);CHKERRQ(ierr);
ierr = SNESView(nasm->subsnes[i],sviewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(sviewer,"- - - - - - - - - - - - - - - - - -\n");CHKERRQ(ierr);
}
ierr = PetscViewerRestoreSingleton(viewer,&sviewer);CHKERRQ(ierr);
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
} else if (isstring) {
ierr = PetscViewerStringSPrintf(viewer," blocks=%D,type=%s",N,SNESNASMTypes[nasm->type]);CHKERRQ(ierr);
ierr = PetscViewerGetSingleton(viewer,&sviewer);CHKERRQ(ierr);
if (nasm->subsnes && !rank) {ierr = SNESView(nasm->subsnes[0],sviewer);CHKERRQ(ierr);}
ierr = PetscViewerRestoreSingleton(viewer,&sviewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例2: MatPartitioningView_Parmetis
PetscErrorCode MatPartitioningView_Parmetis(MatPartitioning part,PetscViewer viewer)
{
MatPartitioning_Parmetis *parmetis = (MatPartitioning_Parmetis *)part->data;
PetscErrorCode ierr;
int rank;
PetscBool iascii;
PetscFunctionBegin;
ierr = MPI_Comm_rank(((PetscObject)part)->comm,&rank);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
if (parmetis->parallel == 2) {
ierr = PetscViewerASCIIPrintf(viewer," Using parallel coarse grid partitioner\n");CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPrintf(viewer," Using sequential coarse grid partitioner\n");CHKERRQ(ierr);
}
ierr = PetscViewerASCIIPrintf(viewer," Using %d fold factor\n",parmetis->foldfactor);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer," [%d]Number of cuts found %d\n",rank,parmetis->cuts);CHKERRQ(ierr);
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
} else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for this Parmetis partitioner",((PetscObject)viewer)->type_name);
PetscFunctionReturn(0);
}
示例3: ISView_Block
PetscErrorCode ISView_Block(IS is, PetscViewer viewer)
{
IS_Block *sub = (IS_Block*)is->data;
PetscErrorCode ierr;
PetscInt i,n = sub->n,*idx = sub->idx;
PetscBool iascii;
PetscFunctionBegin;
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
if (is->isperm) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block Index set is permutation\n");CHKERRQ(ierr);
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block size %D\n",is->bs);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Number of block indices in set %D\n",n);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"The first indices of each block are\n");CHKERRQ(ierr);
for (i=0; i<n; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block %D Index %D\n",i,idx[i]);CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例4: PetscViewerFileSetName_VTK
PetscErrorCode PetscViewerFileSetName_VTK(PetscViewer viewer,const char name[])
{
PetscViewer_VTK *vtk = (PetscViewer_VTK*)viewer->data;
PetscErrorCode ierr;
PetscBool isvtk,isvts,isvtu,isvtr;
size_t len;
PetscFunctionBegin;
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscFree(vtk->filename);CHKERRQ(ierr);
ierr = PetscStrlen(name,&len);CHKERRQ(ierr);
ierr = PetscStrcasecmp(name+len-4,".vtk",&isvtk);CHKERRQ(ierr);
ierr = PetscStrcasecmp(name+len-4,".vts",&isvts);CHKERRQ(ierr);
ierr = PetscStrcasecmp(name+len-4,".vtu",&isvtu);CHKERRQ(ierr);
ierr = PetscStrcasecmp(name+len-4,".vtr",&isvtr);CHKERRQ(ierr);
if (isvtk) {
if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr);}
if (viewer->format != PETSC_VIEWER_ASCII_VTK) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vtk' extension",name,PetscViewerFormats[viewer->format]);
} else if (isvts) {
if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_VTK_VTS);CHKERRQ(ierr);}
if (viewer->format != PETSC_VIEWER_VTK_VTS) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vts' extension",name,PetscViewerFormats[viewer->format]);
} else if (isvtu) {
if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_VTK_VTU);CHKERRQ(ierr);}
if (viewer->format != PETSC_VIEWER_VTK_VTU) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vtu' extension",name,PetscViewerFormats[viewer->format]);
} else if (isvtr) {
if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_VTK_VTR);CHKERRQ(ierr);}
if (viewer->format != PETSC_VIEWER_VTK_VTR) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vtr' extension",name,PetscViewerFormats[viewer->format]);
} else SETERRQ1(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_UNKNOWN_TYPE,"File '%s' has unrecognized extension",name);
ierr = PetscStrallocpy(name,&vtk->filename);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例5: DMView_Cartesian_Ascii
PetscErrorCode DMView_Cartesian_Ascii(const ALE::Obj<ALE::CartesianMesh>& mesh, PetscViewer viewer)
{
PetscViewerFormat format;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscViewerGetFormat(viewer, &format);
CHKERRQ(ierr);
if (format == PETSC_VIEWER_ASCII_VTK) {
#if 0
ierr = VTKViewer::writeHeader(viewer);
CHKERRQ(ierr);
ierr = VTKViewer::writeVertices(mesh, viewer);
CHKERRQ(ierr);
ierr = VTKViewer::writeElements(mesh, viewer);
CHKERRQ(ierr);
#endif
} else {
int dim = mesh->getDimension();
ierr = PetscViewerASCIIPrintf(viewer, "Mesh in %d dimensions:\n", dim);
CHKERRQ(ierr);
/* FIX: Need to globalize */
ierr = PetscViewerASCIIPrintf(viewer, " %d vertices\n", mesh->getSieve()->getNumVertices());
CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer, " %d cells\n", mesh->getSieve()->getNumCells());
CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);
CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例6: ISColoringDestroy
/*@C
ISColoringView - Views a coloring context.
Collective on ISColoring
Input Parameters:
+ iscoloring - the coloring context
- viewer - the viewer
Level: advanced
.seealso: ISColoringDestroy(), ISColoringGetIS(), MatColoring
@*/
PetscErrorCode ISColoringView(ISColoring iscoloring,PetscViewer viewer)
{
PetscInt i;
PetscErrorCode ierr;
PetscBool iascii;
IS *is;
PetscFunctionBegin;
PetscValidPointer(iscoloring,1);
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(iscoloring->comm,&viewer);CHKERRQ(ierr);
}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
MPI_Comm comm;
PetscMPIInt rank;
ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Number of colors %d\n",rank,iscoloring->n);CHKERRQ(ierr);
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
} else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for ISColoring",((PetscObject)viewer)->type_name);
ierr = ISColoringGetIS(iscoloring,PETSC_IGNORE,&is);CHKERRQ(ierr);
for (i=0; i<iscoloring->n; i++) {
ierr = ISView(iscoloring->is[i],viewer);CHKERRQ(ierr);
}
ierr = ISColoringRestoreIS(iscoloring,&is);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例7: DMLabelView_Ascii
static PetscErrorCode DMLabelView_Ascii(DMLabel label, PetscViewer viewer)
{
PetscInt v;
PetscMPIInt rank;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank);CHKERRQ(ierr);
ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
if (label) {
ierr = PetscViewerASCIIPrintf(viewer, "Label '%s':\n", label->name);CHKERRQ(ierr);
if (label->bt) {ierr = PetscViewerASCIIPrintf(viewer, " Index has been calculated in [%D, %D)\n", label->pStart, label->pEnd);CHKERRQ(ierr);}
for (v = 0; v < label->numStrata; ++v) {
const PetscInt value = label->stratumValues[v];
PetscInt p;
for (p = 0; p < label->stratumSizes[v]; ++p) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer, "[%d]: %D (%D)\n", rank, label->points[v][p], value);CHKERRQ(ierr);
}
}
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例8: PetscMallocDump
/*@C
PetscMemoryShowUsage - Shows the amount of memory currently being used
in a communicator.
Collective on PetscViewer
Input Parameter:
+ viewer - the viewer that defines the communicator
- message - string printed before values
Level: intermediate
Concepts: memory usage
.seealso: PetscMallocDump(), PetscMemoryGetCurrentUsage()
@*/
PetscErrorCode PetscMemoryShowUsage(PetscViewer viewer,const char message[])
{
PetscLogDouble allocated,maximum,resident,residentmax;
PetscErrorCode ierr;
PetscMPIInt rank;
MPI_Comm comm;
PetscFunctionBegin;
if (!viewer) viewer = PETSC_VIEWER_STDOUT_WORLD;
ierr = PetscMallocGetCurrentUsage(&allocated);CHKERRQ(ierr);
ierr = PetscMallocGetMaximumUsage(&maximum);CHKERRQ(ierr);
ierr = PetscMemoryGetCurrentUsage(&resident);CHKERRQ(ierr);
ierr = PetscMemoryGetMaximumUsage(&residentmax);CHKERRQ(ierr);
if (residentmax > 0) residentmax = PetscMax(resident,residentmax);
ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer,message);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
if (resident && residentmax && allocated) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Current space PetscMalloc()ed %g, max space PetscMalloced() %g\n[%d]Current process memory %g max process memory %g\n",rank,allocated,maximum,rank,resident,residentmax);CHKERRQ(ierr);
} else if (resident && residentmax) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Run with -malloc to get statistics on PetscMalloc() calls\n[%d]Current process memory %g max process memory %g\n",rank,rank,resident,residentmax);CHKERRQ(ierr);
} else if (resident && allocated) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Current space PetscMalloc()ed %g, max space PetscMalloced() %g\n[%d]Current process memory %g, run with -memory_info to get max memory usage\n",rank,allocated,maximum,rank,resident);CHKERRQ(ierr);
} else if (allocated) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d]Current space PetscMalloc()ed %g, max space PetscMalloced() %g\n[%d]OS cannot compute process memory\n",rank,allocated,maximum,rank);CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIIPrintf(viewer,"Run with -malloc to get statistics on PetscMalloc() calls\nOS cannot compute process memory\n");CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例9: PetscSectionVecView_ASCII
PetscErrorCode PetscSectionVecView_ASCII(PetscSection s, Vec v, PetscViewer viewer)
{
PetscScalar *array;
PetscInt p, i;
PetscMPIInt rank;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer), &rank);CHKERRQ(ierr);
ierr = VecGetArray(v, &array);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer, PETSC_TRUE);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer, "Process %d:\n", rank);CHKERRQ(ierr);
for (p = 0; p < s->pEnd - s->pStart; ++p) {
if ((s->bc) && (s->bc->atlasDof[p] > 0)) {
PetscInt b;
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " (%4d) dim %2d offset %3d", p+s->pStart, s->atlasDof[p], s->atlasOff[p]);CHKERRQ(ierr);
for (i = s->atlasOff[p]; i < s->atlasOff[p]+s->atlasDof[p]; ++i) {
PetscScalar v = array[i];
#if defined(PETSC_USE_COMPLEX)
if (PetscImaginaryPart(v) > 0.0) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer," %g + %g i", (double)PetscRealPart(v), (double)PetscImaginaryPart(v));CHKERRQ(ierr);
} else if (PetscImaginaryPart(v) < 0.0) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer," %g - %g i", (double)PetscRealPart(v),(double)(-PetscImaginaryPart(v)));CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)PetscRealPart(v));CHKERRQ(ierr);
}
#else
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)v);CHKERRQ(ierr);
#endif
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " constrained");CHKERRQ(ierr);
for (b = 0; b < s->bc->atlasDof[p]; ++b) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " %d", s->bcIndices[s->bc->atlasOff[p]+b]);CHKERRQ(ierr);
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\n");CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " (%4d) dim %2d offset %3d", p+s->pStart, s->atlasDof[p], s->atlasOff[p]);CHKERRQ(ierr);
for (i = s->atlasOff[p]; i < s->atlasOff[p]+s->atlasDof[p]; ++i) {
PetscScalar v = array[i];
#if defined(PETSC_USE_COMPLEX)
if (PetscImaginaryPart(v) > 0.0) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer," %g + %g i", (double)PetscRealPart(v), (double)PetscImaginaryPart(v));CHKERRQ(ierr);
} else if (PetscImaginaryPart(v) < 0.0) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer," %g - %g i", (double)PetscRealPart(v),(double)(-PetscImaginaryPart(v)));CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)PetscRealPart(v));CHKERRQ(ierr);
}
#else
ierr = PetscViewerASCIISynchronizedPrintf(viewer, " %g", (double)v);CHKERRQ(ierr);
#endif
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer, "\n");CHKERRQ(ierr);
}
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = VecRestoreArray(v, &array);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例10: output
/*@C
PetscRandomView - Views a random number generator object.
Collective on PetscRandom
Input Parameters:
+ rnd - The random number generator context
- viewer - an optional visualization context
Notes:
The available visualization contexts include
+ PETSC_VIEWER_STDOUT_SELF - standard output (default)
- PETSC_VIEWER_STDOUT_WORLD - synchronized standard
output where only the first processor opens
the file. All other processors send their
data to the first processor to print.
You can change the format the vector is printed using the
option PetscViewerSetFormat().
Level: beginner
.seealso: PetscRealView(), PetscScalarView(), PetscIntView()
@*/
PetscErrorCode PetscRandomView(PetscRandom rnd,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii;
#if defined(PETSC_HAVE_SAWS)
PetscBool issaws;
#endif
PetscFunctionBegin;
PetscValidHeaderSpecific(rnd,PETSC_RANDOM_CLASSID,1);
PetscValidType(rnd,1);
if (!viewer) {
ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)rnd),&viewer);
CHKERRQ(ierr);
}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(rnd,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
CHKERRQ(ierr);
#if defined(PETSC_HAVE_SAWS)
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);
CHKERRQ(ierr);
#endif
if (iascii) {
PetscMPIInt rank;
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)rnd,viewer);
CHKERRQ(ierr);
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)rnd),&rank);
CHKERRQ(ierr);
ierr = PetscViewerASCIIPushSynchronized(viewer);
CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Random type %s, seed %D\n",rank,((PetscObject)rnd)->type_name,rnd->seed);
CHKERRQ(ierr);
ierr = PetscViewerFlush(viewer);
CHKERRQ(ierr);
ierr = PetscViewerASCIIPopSynchronized(viewer);
CHKERRQ(ierr);
#if defined(PETSC_HAVE_SAWS)
} else if (issaws) {
PetscMPIInt rank;
const char *name;
ierr = PetscObjectGetName((PetscObject)rnd,&name);
CHKERRQ(ierr);
ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
CHKERRQ(ierr);
if (!((PetscObject)rnd)->amsmem && !rank) {
char dir[1024];
ierr = PetscObjectViewSAWs((PetscObject)rnd,viewer);
CHKERRQ(ierr);
ierr = PetscSNPrintf(dir,1024,"/PETSc/Objects/%s/Low",name);
CHKERRQ(ierr);
PetscStackCallSAWs(SAWs_Register,(dir,&rnd->low,1,SAWs_READ,SAWs_DOUBLE));
}
#endif
}
PetscFunctionReturn(0);
}
示例11: AOView_MemoryScalable
PetscErrorCode AOView_MemoryScalable(AO ao,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscMPIInt rank,size;
AO_MemoryScalable *aomems = (AO_MemoryScalable*)ao->data;
PetscBool iascii;
PetscMPIInt tag_app,tag_petsc;
PetscLayout map = aomems->map;
PetscInt *app,*app_loc,*petsc,*petsc_loc,len,i,j;
MPI_Status status;
PetscFunctionBegin;
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (!iascii) SETERRQ1(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Viewer type %s not supported for AO MemoryScalable",((PetscObject)viewer)->type_name);
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)ao),&rank);CHKERRQ(ierr);
ierr = MPI_Comm_size(PetscObjectComm((PetscObject)ao),&size);CHKERRQ(ierr);
ierr = PetscObjectGetNewTag((PetscObject)ao,&tag_app);CHKERRQ(ierr);
ierr = PetscObjectGetNewTag((PetscObject)ao,&tag_petsc);CHKERRQ(ierr);
if (!rank) {
ierr = PetscViewerASCIIPrintf(viewer,"Number of elements in ordering %D\n",ao->N);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer, "PETSc->App App->PETSc\n");CHKERRQ(ierr);
ierr = PetscMalloc2(map->N,&app,map->N,&petsc);CHKERRQ(ierr);
len = map->n;
/* print local AO */
ierr = PetscViewerASCIIPrintf(viewer,"Process [%D]\n",rank);CHKERRQ(ierr);
for (i=0; i<len; i++) {
ierr = PetscViewerASCIIPrintf(viewer,"%3D %3D %3D %3D\n",i,aomems->app_loc[i],i,aomems->petsc_loc[i]);CHKERRQ(ierr);
}
/* recv and print off-processor's AO */
for (i=1; i<size; i++) {
len = map->range[i+1] - map->range[i];
app_loc = app + map->range[i];
petsc_loc = petsc+ map->range[i];
ierr = MPI_Recv(app_loc,(PetscMPIInt)len,MPIU_INT,i,tag_app,PetscObjectComm((PetscObject)ao),&status);CHKERRQ(ierr);
ierr = MPI_Recv(petsc_loc,(PetscMPIInt)len,MPIU_INT,i,tag_petsc,PetscObjectComm((PetscObject)ao),&status);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(viewer,"Process [%D]\n",i);CHKERRQ(ierr);
for (j=0; j<len; j++) {
ierr = PetscViewerASCIIPrintf(viewer,"%3D %3D %3D %3D\n",map->range[i]+j,app_loc[j],map->range[i]+j,petsc_loc[j]);CHKERRQ(ierr);
}
}
ierr = PetscFree2(app,petsc);CHKERRQ(ierr);
} else {
/* send values */
ierr = MPI_Send((void*)aomems->app_loc,map->n,MPIU_INT,0,tag_app,PetscObjectComm((PetscObject)ao));CHKERRQ(ierr);
ierr = MPI_Send((void*)aomems->petsc_loc,map->n,MPIU_INT,0,tag_petsc,PetscObjectComm((PetscObject)ao));CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
示例12: PetscSFCreate
/*@C
PetscSFView - view a star forest
Collective
Input Arguments:
+ sf - star forest
- viewer - viewer to display graph, for example PETSC_VIEWER_STDOUT_WORLD
Level: beginner
.seealso: PetscSFCreate(), PetscSFSetGraph()
@*/
PetscErrorCode PetscSFView(PetscSF sf,PetscViewer viewer)
{
PetscErrorCode ierr;
PetscBool iascii;
PetscViewerFormat format;
PetscFunctionBegin;
PetscValidHeaderSpecific(sf,PETSCSF_CLASSID,1);
if (!viewer) {ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)sf),&viewer);CHKERRQ(ierr);}
PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
PetscCheckSameComm(sf,1,viewer,2);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
PetscMPIInt rank;
PetscInt i,j;
ierr = PetscObjectPrintClassNamePrefixType((PetscObject)sf,viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
if (sf->ops->View) {ierr = (*sf->ops->View)(sf,viewer);CHKERRQ(ierr);}
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)sf),&rank);CHKERRQ(ierr);
ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Number of roots=%D, leaves=%D, remote ranks=%D\n",rank,sf->nroots,sf->nleaves,sf->nranks);CHKERRQ(ierr);
for (i=0; i<sf->nleaves; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %D <- (%D,%D)\n",rank,sf->mine ? sf->mine[i] : i,sf->remote[i].rank,sf->remote[i].index);CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Roots referenced by my leaves, by rank\n",rank);CHKERRQ(ierr);
for (i=0; i<sf->nranks; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %d: %D edges\n",rank,sf->ranks[i],sf->roffset[i+1]-sf->roffset[i]);CHKERRQ(ierr);
for (j=sf->roffset[i]; j<sf->roffset[i+1]; j++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %D <- %D\n",rank,sf->rmine[j],sf->rremote[j]);CHKERRQ(ierr);
}
}
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
示例13: main
int main(int argc,char **argv)
{
Mat mat,submat,*submatrices;
PetscInt m = 10,n = 10,i = 4,tmp;
PetscErrorCode ierr;
IS irkeep,ickeep;
PetscScalar value = 1.0;
PetscViewer sviewer;
PetscInitialize(&argc,&argv,(char *)0,help);
ierr = PetscViewerSetFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_COMMON);CHKERRQ(ierr);
ierr = PetscViewerSetFormat(PETSC_VIEWER_STDOUT_SELF,PETSC_VIEWER_ASCII_COMMON);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&mat);CHKERRQ(ierr);
ierr = MatSetSizes(mat,PETSC_DECIDE,PETSC_DECIDE,m,n);CHKERRQ(ierr);
ierr = MatSetFromOptions(mat);CHKERRQ(ierr);
for (i=0; i<m; i++) {
value = (PetscReal)i+1; tmp = i % 5;
ierr = MatSetValues(mat,1,&tmp,1,&i,&value,INSERT_VALUES);CHKERRQ(ierr);
}
ierr = MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD,"Original matrix\n");CHKERRQ(ierr);
ierr = MatView(mat,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
/* Form submatrix with rows 2-4 and columns 4-8 */
ierr = ISCreateStride(PETSC_COMM_SELF,3,2,1,&irkeep);CHKERRQ(ierr);
ierr = ISCreateStride(PETSC_COMM_SELF,5,4,1,&ickeep);CHKERRQ(ierr);
ierr = MatGetSubMatrices(mat,1,&irkeep,&ickeep,MAT_INITIAL_MATRIX,&submatrices);CHKERRQ(ierr);
submat = *submatrices;
ierr = PetscFree(submatrices);CHKERRQ(ierr);
/*
sviewer will cause the submatrices (one per processor) to be printed in the correct order
*/
ierr = PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD,"Submatrices\n");CHKERRQ(ierr);
ierr = PetscViewerGetSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);CHKERRQ(ierr);
ierr = MatView(submat,sviewer);CHKERRQ(ierr);
ierr = PetscViewerRestoreSingleton(PETSC_VIEWER_STDOUT_WORLD,&sviewer);CHKERRQ(ierr);
ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
/* Zero the original matrix */
ierr = PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_WORLD,"Original zeroed matrix\n");CHKERRQ(ierr);
ierr = MatZeroEntries(mat);CHKERRQ(ierr);
ierr = MatView(mat,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
ierr = ISDestroy(&irkeep);CHKERRQ(ierr);
ierr = ISDestroy(&ickeep);CHKERRQ(ierr);
ierr = MatDestroy(&submat);CHKERRQ(ierr);
ierr = MatDestroy(&mat);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
示例14: ISView_Stride
PetscErrorCode ISView_Stride(IS is,PetscViewer viewer)
{
IS_Stride *sub = (IS_Stride*)is->data;
PetscInt i,n = sub->n;
PetscMPIInt rank,size;
PetscBool iascii;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
if (iascii) {
ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)is),&rank);CHKERRQ(ierr);
ierr = MPI_Comm_size(PetscObjectComm((PetscObject)is),&size);CHKERRQ(ierr);
if (size == 1) {
if (is->isperm) {
ierr = PetscViewerASCIIPrintf(viewer,"Index set is permutation\n");CHKERRQ(ierr);
}
ierr = PetscViewerASCIIPrintf(viewer,"Number of indices in (stride) set %D\n",n);CHKERRQ(ierr);
for (i=0; i<n; i++) {
ierr = PetscViewerASCIIPrintf(viewer,"%D %D\n",i,sub->first + i*sub->step);CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
} else {
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
if (is->isperm) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Index set is permutation\n",rank);CHKERRQ(ierr);
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Number of indices in (stride) set %D\n",rank,n);CHKERRQ(ierr);
for (i=0; i<n; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %D %D\n",rank,i,sub->first + i*sub->step);CHKERRQ(ierr);
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
}
}
PetscFunctionReturn(0);
}
示例15: ISView_General
PetscErrorCode ISView_General(IS is,PetscViewer viewer)
{
IS_General *sub = (IS_General*)is->data;
PetscErrorCode ierr;
PetscInt i,n,*idx = sub->idx;
PetscBool iascii,isbinary,ishdf5;
PetscFunctionBegin;
ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr);
if (iascii) {
MPI_Comm comm;
PetscMPIInt rank,size;
ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr);
ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_TRUE);CHKERRQ(ierr);
if (size > 1) {
if (is->isperm) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Index set is permutation\n",rank);CHKERRQ(ierr);
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] Number of indices in set %D\n",rank,n);CHKERRQ(ierr);
for (i=0; i<n; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"[%d] %D %D\n",rank,i,idx[i]);CHKERRQ(ierr);
}
} else {
if (is->isperm) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Index set is permutation\n");CHKERRQ(ierr);
}
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Number of indices in set %D\n",n);CHKERRQ(ierr);
for (i=0; i<n; i++) {
ierr = PetscViewerASCIISynchronizedPrintf(viewer,"%D %D\n",i,idx[i]);CHKERRQ(ierr);
}
}
ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
ierr = PetscViewerASCIISynchronizedAllow(viewer,PETSC_FALSE);CHKERRQ(ierr);
} else if (isbinary) {
ierr = ISView_General_Binary(is,viewer);CHKERRQ(ierr);
} else if (ishdf5) {
#if defined(PETSC_HAVE_HDF5)
ierr = ISView_General_HDF5(is,viewer);CHKERRQ(ierr);
#endif
}
PetscFunctionReturn(0);
}