15c6c1daeSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscviewer.h" I*/ 3e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 4e04113cfSBarry Smith #include <petscviewersaws.h> 5bfb97211SBarry Smith #endif 65c6c1daeSBarry Smith 7140e18c1SBarry Smith PetscFunctionList PetscViewerList = 0; 85c6c1daeSBarry Smith 99af95d99SBarry Smith #include "../src/sys/utils/hash.h" 109af95d99SBarry Smith 119af95d99SBarry Smith 12*9de0f6ecSBarry Smith PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton = NULL; 13*9de0f6ecSBarry Smith KHASH_SET_INIT_STR(HTPrinted) 14*9de0f6ecSBarry Smith struct _n_PetscOptionsHelpPrinted{ 15*9de0f6ecSBarry Smith khash_t(HTPrinted) *printed; 16*9de0f6ecSBarry Smith PetscSegBuffer strings; 17*9de0f6ecSBarry Smith }; 18*9de0f6ecSBarry Smith 19*9de0f6ecSBarry Smith #undef __FUNCT__ 20*9de0f6ecSBarry Smith #define __FUNCT__ "PetscOptionsHelpPrintedDestroy" 21*9de0f6ecSBarry Smith PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted *hp) 2294d6a431SBarry Smith { 239af95d99SBarry Smith PetscErrorCode ierr; 24*9de0f6ecSBarry Smith 25*9de0f6ecSBarry Smith PetscFunctionBegin; 26*9de0f6ecSBarry Smith if (!*hp) PetscFunctionReturn(0); 27*9de0f6ecSBarry Smith kh_destroy(HTPrinted,(*hp)->printed); 28*9de0f6ecSBarry Smith ierr = PetscSegBufferDestroy(&(*hp)->strings);CHKERRQ(ierr); 29*9de0f6ecSBarry Smith ierr = PetscFree(*hp);CHKERRQ(ierr); 30*9de0f6ecSBarry Smith PetscFunctionReturn(0); 31*9de0f6ecSBarry Smith } 32*9de0f6ecSBarry Smith 33*9de0f6ecSBarry Smith #undef __FUNCT__ 34*9de0f6ecSBarry Smith #define __FUNCT__ "PetscOptionsHelpPrintedCreate" 35*9de0f6ecSBarry Smith /*@C 36*9de0f6ecSBarry Smith PetscOptionsHelpPrintedCreate - Creates an object used to manage tracking which help messages have 37*9de0f6ecSBarry Smith been printed so they will not be printed again. 38*9de0f6ecSBarry Smith 39*9de0f6ecSBarry Smith Not collective 40*9de0f6ecSBarry Smith 41*9de0f6ecSBarry Smith Level: developer 42*9de0f6ecSBarry Smith 43*9de0f6ecSBarry Smith .seealso: PetscOptionsHelpPrintedCheck(), PetscOptionsHelpPrintChecked() 44*9de0f6ecSBarry Smith @*/ 45*9de0f6ecSBarry Smith PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted *hp) 46*9de0f6ecSBarry Smith { 47*9de0f6ecSBarry Smith PetscErrorCode ierr; 48*9de0f6ecSBarry Smith 49*9de0f6ecSBarry Smith PetscFunctionBegin; 50*9de0f6ecSBarry Smith ierr = PetscNew(hp);CHKERRQ(ierr); 51*9de0f6ecSBarry Smith (*hp)->printed = kh_init(HTPrinted); 52*9de0f6ecSBarry Smith ierr = PetscSegBufferCreate(sizeof(char),10000,&(*hp)->strings);CHKERRQ(ierr); 53*9de0f6ecSBarry Smith PetscFunctionReturn(0); 54*9de0f6ecSBarry Smith } 55*9de0f6ecSBarry Smith 56*9de0f6ecSBarry Smith #undef __FUNCT__ 57*9de0f6ecSBarry Smith #define __FUNCT__ "PetscOptionsHelpPrintedCheck" 58*9de0f6ecSBarry Smith /*@C 59*9de0f6ecSBarry Smith PetscOptionsHelpPrintedCheck - Checks if a particular pre, name pair has previous been entered (meaning the help message was printed) 60*9de0f6ecSBarry Smith 61*9de0f6ecSBarry Smith Not collective 62*9de0f6ecSBarry Smith 63*9de0f6ecSBarry Smith Input Parameters: 64*9de0f6ecSBarry Smith + hp - the object used to manage tracking what help messages have been printed 65*9de0f6ecSBarry Smith . pre - the prefix part of the string, many be NULL 66*9de0f6ecSBarry Smith - name - the string to look for (cannot be NULL) 67*9de0f6ecSBarry Smith 68*9de0f6ecSBarry Smith Output Parameter: 69*9de0f6ecSBarry Smith . found - PETSC_TRUE if the string was already set 70*9de0f6ecSBarry Smith 71*9de0f6ecSBarry Smith Level: intermediate 72*9de0f6ecSBarry Smith 73*9de0f6ecSBarry Smith 74*9de0f6ecSBarry Smith .seealso: PetscOptionsHelpPrintedCreate() 75*9de0f6ecSBarry Smith @*/ 76*9de0f6ecSBarry Smith PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted hp,const char *pre,const char* name,PetscBool *found) 77*9de0f6ecSBarry Smith { 78*9de0f6ecSBarry Smith size_t l1,l2; 79*9de0f6ecSBarry Smith char *both; 80*9de0f6ecSBarry Smith khint_t newitem; 81*9de0f6ecSBarry Smith PetscErrorCode ierr; 82*9de0f6ecSBarry Smith 83*9de0f6ecSBarry Smith PetscFunctionBegin; 84*9de0f6ecSBarry Smith ierr = PetscStrlen(pre,&l1);CHKERRQ(ierr); 85*9de0f6ecSBarry Smith ierr = PetscStrlen(name,&l2);CHKERRQ(ierr); 86*9de0f6ecSBarry Smith if (l1+l2 == 0) { 87*9de0f6ecSBarry Smith *found = PETSC_FALSE; 88*9de0f6ecSBarry Smith PetscFunctionReturn(0); 89*9de0f6ecSBarry Smith } 90*9de0f6ecSBarry Smith ierr = PetscSegBufferGet(hp->strings,l1+l2+1,&both);CHKERRQ(ierr); 91*9de0f6ecSBarry Smith ierr = PetscStrcpy(both,pre);CHKERRQ(ierr); 92*9de0f6ecSBarry Smith ierr = PetscStrcat(both,name);CHKERRQ(ierr); 93*9de0f6ecSBarry Smith kh_put(HTPrinted,hp->printed,both,&newitem); 94*9de0f6ecSBarry Smith if (!newitem) { 95*9de0f6ecSBarry Smith ierr = PetscSegBufferUnuse(hp->strings,l1+l2+1);CHKERRQ(ierr); 96*9de0f6ecSBarry Smith } 97*9de0f6ecSBarry Smith *found = newitem ? PETSC_FALSE : PETSC_TRUE; 98*9de0f6ecSBarry Smith PetscFunctionReturn(0); 9994d6a431SBarry Smith } 10094d6a431SBarry Smith 1012bf49c77SBarry Smith #undef __FUNCT__ 1022bf49c77SBarry Smith #define __FUNCT__ "PetscOptionsGetViewer" 1032bf49c77SBarry Smith /*@C 1042bf49c77SBarry Smith PetscOptionsGetViewer - Gets a viewer appropriate for the type indicated by the user 1052bf49c77SBarry Smith 1062bf49c77SBarry Smith Collective on MPI_Comm 1072bf49c77SBarry Smith 1082bf49c77SBarry Smith Input Parameters: 1092bf49c77SBarry Smith + comm - the communicator to own the viewer 1100298fd71SBarry Smith . pre - the string to prepend to the name or NULL 1112bf49c77SBarry Smith - name - the option one is seeking 1122bf49c77SBarry Smith 1132bf49c77SBarry Smith Output Parameter: 114bb1d7374SBarry Smith + viewer - the viewer, pass NULL if not needed 115bb1d7374SBarry Smith . format - the PetscViewerFormat requested by the user, pass NULL if not needed 1162bf49c77SBarry Smith - set - PETSC_TRUE if found, else PETSC_FALSE 1172bf49c77SBarry Smith 1182bf49c77SBarry Smith Level: intermediate 1192bf49c77SBarry Smith 1202bf49c77SBarry Smith Notes: If no value is provided ascii:stdout is used 121d1da0b69SBarry Smith $ ascii[:[filename][:[format][:append]]] defaults to stdout - format can be one of ascii_info, ascii_info_detail, or ascii_matlab, 122d1da0b69SBarry Smith for example ascii::ascii_info prints just the information about the object not all details 123d1da0b69SBarry Smith unless :append is given filename opens in write mode, overwriting what was already there 124d1da0b69SBarry Smith $ binary[:[filename][:[format][:append]]] defaults to the file binaryoutput 12520610d12SBarry Smith $ draw[:drawtype] for example, draw:tikz or draw:x 1262bf49c77SBarry Smith $ socket[:port] defaults to the standard output port 1272a359c20SBarry Smith $ saws[:communicatorname] publishes object to the Scientific Application Webserver (SAWs) 1282bf49c77SBarry Smith 129cffb1e40SBarry Smith Use PetscViewerDestroy() after using the viewer, otherwise a memory leak will occur 1302bf49c77SBarry Smith 13127b0f280SBarry Smith If PETSc is configured with --with-viewfromoptions=0 this function always returns with *set of PETSC_FALSE 13227b0f280SBarry Smith 1332bf49c77SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), 1342bf49c77SBarry Smith PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool() 1352bf49c77SBarry Smith PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(), 1362bf49c77SBarry Smith PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(), 1372bf49c77SBarry Smith PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(), 1382bf49c77SBarry Smith PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(), 139a264d7a6SBarry Smith PetscOptionsFList(), PetscOptionsEList() 1402bf49c77SBarry Smith @*/ 141cffb1e40SBarry Smith PetscErrorCode PetscOptionsGetViewer(MPI_Comm comm,const char pre[],const char name[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set) 1422bf49c77SBarry Smith { 1432bf49c77SBarry Smith char *value; 1442bf49c77SBarry Smith PetscErrorCode ierr; 14520610d12SBarry Smith PetscBool flag,hashelp; 1462bf49c77SBarry Smith 1472bf49c77SBarry Smith PetscFunctionBegin; 1482bf49c77SBarry Smith PetscValidCharPointer(name,3); 1492bf49c77SBarry Smith 15027b0f280SBarry Smith if (set) *set = PETSC_FALSE; 15127b0f280SBarry Smith #if defined(PETSC_SKIP_VIEWFROMOPTIONS) 15227b0f280SBarry Smith PetscFunctionReturn(0); 15327b0f280SBarry Smith #endif 15427b0f280SBarry Smith 155c5929fdfSBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-help",&hashelp);CHKERRQ(ierr); 15620610d12SBarry Smith if (hashelp) { 157*9de0f6ecSBarry Smith PetscBool found; 1589af95d99SBarry Smith 159*9de0f6ecSBarry Smith if (!PetscOptionsHelpPrintedSingleton) { 160*9de0f6ecSBarry Smith ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr); 1619af95d99SBarry Smith } 162*9de0f6ecSBarry Smith ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,pre,name,&found);CHKERRQ(ierr); 163*9de0f6ecSBarry Smith if (!found) { 16494d6a431SBarry Smith if (viewer) { 16594d6a431SBarry Smith ierr = (*PetscHelpPrintf)(comm,"\n -%s%s ascii[:[filename][:[format][:append]]]: %s (%s)\n",pre ? pre : "",name+1,"Prints object to stdout or ASCII file","PetscOptionsGetViewer");CHKERRQ(ierr); 16694d6a431SBarry Smith ierr = (*PetscHelpPrintf)(comm," -%s%s binary[:[filename][:[format][:append]]]: %s (%s)\n",pre ? pre : "",name+1,"Saves object to a binary file","PetscOptionsGetViewer");CHKERRQ(ierr); 16794d6a431SBarry Smith ierr = (*PetscHelpPrintf)(comm," -%s%s draw[:drawtype]: %s (%s)\n",pre ? pre : "",name+1,"Draws object","PetscOptionsGetViewer");CHKERRQ(ierr); 16894d6a431SBarry Smith ierr = (*PetscHelpPrintf)(comm," -%s%s socket[:port]: %s (%s)\n",pre ? pre : "",name+1,"Pushes object to a Unix socket","PetscOptionsGetViewer");CHKERRQ(ierr); 16994d6a431SBarry Smith ierr = (*PetscHelpPrintf)(comm," -%s%s saws[:communicatorname]: %s (%s)\n\n",pre ? pre : "",name+1,"Publishes object to SAWs","PetscOptionsGetViewer");CHKERRQ(ierr); 17094d6a431SBarry Smith } else { 17194d6a431SBarry Smith ierr = (*PetscHelpPrintf)(comm," -%s%s\n",pre ? pre : "",name+1);CHKERRQ(ierr); 17294d6a431SBarry Smith } 17394d6a431SBarry Smith } 17420610d12SBarry Smith } 175685405a1SBarry Smith 176e3f3e4b6SBarry Smith if (format) *format = PETSC_VIEWER_DEFAULT; 177c5929fdfSBarry Smith ierr = PetscOptionsFindPair_Private(NULL,pre,name,&value,&flag);CHKERRQ(ierr); 1782bf49c77SBarry Smith if (flag) { 1792bf49c77SBarry Smith if (set) *set = PETSC_TRUE; 1802bf49c77SBarry Smith if (!value) { 181bb1d7374SBarry Smith if (viewer) { 1822bf49c77SBarry Smith ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr); 183706a11cbSBarry Smith ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr); 184bb1d7374SBarry Smith } 1852bf49c77SBarry Smith } else { 18635d27ee3SJed Brown char *loc0_vtype,*loc1_fname,*loc2_fmt = NULL,*loc3_fmode = NULL; 1872bf49c77SBarry Smith PetscInt cnt; 188a75e6a4aSMatthew G. Knepley const char *viewers[] = {PETSCVIEWERASCII,PETSCVIEWERBINARY,PETSCVIEWERDRAW,PETSCVIEWERSOCKET,PETSCVIEWERMATLAB,PETSCVIEWERSAWS,PETSCVIEWERVTK,PETSCVIEWERHDF5,0}; 1892bf49c77SBarry Smith 19035d27ee3SJed Brown ierr = PetscStrallocpy(value,&loc0_vtype);CHKERRQ(ierr); 19135d27ee3SJed Brown ierr = PetscStrchr(loc0_vtype,':',&loc1_fname);CHKERRQ(ierr); 19235d27ee3SJed Brown if (loc1_fname) { 19335d27ee3SJed Brown *loc1_fname++ = 0; 19435d27ee3SJed Brown ierr = PetscStrchr(loc1_fname,':',&loc2_fmt);CHKERRQ(ierr); 19535d27ee3SJed Brown } 19635d27ee3SJed Brown if (loc2_fmt) { 19735d27ee3SJed Brown *loc2_fmt++ = 0; 19835d27ee3SJed Brown ierr = PetscStrchr(loc2_fmt,':',&loc3_fmode);CHKERRQ(ierr); 19935d27ee3SJed Brown } 20035d27ee3SJed Brown if (loc3_fmode) *loc3_fmode++ = 0; 20135d27ee3SJed Brown ierr = PetscStrendswithwhich(*loc0_vtype ? loc0_vtype : "ascii",viewers,&cnt);CHKERRQ(ierr); 20235d27ee3SJed Brown if (cnt > (PetscInt) sizeof(viewers)-1) SETERRQ1(comm,PETSC_ERR_ARG_OUTOFRANGE,"Unknown viewer type: %s",loc0_vtype); 203bb1d7374SBarry Smith if (viewer) { 20435d27ee3SJed Brown if (!loc1_fname) { 20543b63833SBarry Smith switch (cnt) { 20643b63833SBarry Smith case 0: 2072bf49c77SBarry Smith ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr); 20843b63833SBarry Smith break; 20943b63833SBarry Smith case 1: 210aa1c909bSJed Brown if (!(*viewer = PETSC_VIEWER_BINARY_(comm))) CHKERRQ(PETSC_ERR_PLIB); 21143b63833SBarry Smith break; 21243b63833SBarry Smith case 2: 213aa1c909bSJed Brown if (!(*viewer = PETSC_VIEWER_DRAW_(comm))) CHKERRQ(PETSC_ERR_PLIB); 21443b63833SBarry Smith break; 215b58ca069SBarry Smith #if defined(PETSC_USE_SOCKET_VIEWER) 21643b63833SBarry Smith case 3: 217aa1c909bSJed Brown if (!(*viewer = PETSC_VIEWER_SOCKET_(comm))) CHKERRQ(PETSC_ERR_PLIB); 21843b63833SBarry Smith break; 219b58ca069SBarry Smith #endif 22043b63833SBarry Smith #if defined(PETSC_HAVE_MATLAB_ENGINE) 22143b63833SBarry Smith case 4: 222aa1c909bSJed Brown if (!(*viewer = PETSC_VIEWER_MATLAB_(comm))) CHKERRQ(PETSC_ERR_PLIB); 22343b63833SBarry Smith break; 22443b63833SBarry Smith #endif 225e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 226bfb97211SBarry Smith case 5: 227e04113cfSBarry Smith if (!(*viewer = PETSC_VIEWER_SAWS_(comm))) CHKERRQ(PETSC_ERR_PLIB); 228bfb97211SBarry Smith break; 229bfb97211SBarry Smith #endif 230a75e6a4aSMatthew G. Knepley #if defined(PETSC_HAVE_HDF5) 231a75e6a4aSMatthew G. Knepley case 7: 232a75e6a4aSMatthew G. Knepley if (!(*viewer = PETSC_VIEWER_HDF5_(comm))) CHKERRQ(PETSC_ERR_PLIB); 233a75e6a4aSMatthew G. Knepley break; 234a75e6a4aSMatthew G. Knepley #endif 235aa1c909bSJed Brown default: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported viewer %s",loc0_vtype); 2367f677774SBarry Smith } 237706a11cbSBarry Smith ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr); 2387f677774SBarry Smith } else { 23935d27ee3SJed Brown if (loc2_fmt && !*loc1_fname && (cnt == 0)) { /* ASCII format without file name */ 2407f677774SBarry Smith ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr); 241706a11cbSBarry Smith ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr); 2427f677774SBarry Smith } else { 2433550efbcSJed Brown PetscFileMode fmode; 2442bf49c77SBarry Smith ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr); 24535d27ee3SJed Brown ierr = PetscViewerSetType(*viewer,*loc0_vtype ? loc0_vtype : "ascii");CHKERRQ(ierr); 2463550efbcSJed Brown fmode = FILE_MODE_WRITE; 2473550efbcSJed Brown if (loc3_fmode && *loc3_fmode) { /* Has non-empty file mode ("write" or "append") */ 24835d27ee3SJed Brown ierr = PetscEnumFind(PetscFileModes,loc3_fmode,(PetscEnum*)&fmode,&flag);CHKERRQ(ierr); 2493550efbcSJed Brown if (!flag) SETERRQ1(comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown file mode: %s",loc3_fmode); 2507f677774SBarry Smith } 2513550efbcSJed Brown ierr = PetscViewerFileSetMode(*viewer,flag?fmode:FILE_MODE_WRITE);CHKERRQ(ierr); 25235d27ee3SJed Brown ierr = PetscViewerFileSetName(*viewer,loc1_fname);CHKERRQ(ierr); 253d1da0b69SBarry Smith ierr = PetscViewerDrawSetDrawType(*viewer,loc1_fname);CHKERRQ(ierr); 25405315717SToby Isaac } 25505315717SToby Isaac } 256bb1d7374SBarry Smith } 257bb1d7374SBarry Smith if (viewer) { 258bb1d7374SBarry Smith ierr = PetscViewerSetUp(*viewer);CHKERRQ(ierr); 259bb1d7374SBarry Smith } 26035d27ee3SJed Brown if (loc2_fmt && *loc2_fmt) { 26135d27ee3SJed Brown ierr = PetscEnumFind(PetscViewerFormats,loc2_fmt,(PetscEnum*)format,&flag);CHKERRQ(ierr); 26235d27ee3SJed Brown if (!flag) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unknown viewer format %s",loc2_fmt);CHKERRQ(ierr); 2637f677774SBarry Smith } 26435d27ee3SJed Brown ierr = PetscFree(loc0_vtype);CHKERRQ(ierr); 2652bf49c77SBarry Smith } 2662bf49c77SBarry Smith } 2672bf49c77SBarry Smith PetscFunctionReturn(0); 2682bf49c77SBarry Smith } 2692bf49c77SBarry Smith 2702bf49c77SBarry Smith #undef __FUNCT__ 2715c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate" 2725c6c1daeSBarry Smith /*@ 2735c6c1daeSBarry Smith PetscViewerCreate - Creates a viewing context 2745c6c1daeSBarry Smith 2755c6c1daeSBarry Smith Collective on MPI_Comm 2765c6c1daeSBarry Smith 2775c6c1daeSBarry Smith Input Parameter: 2785c6c1daeSBarry Smith . comm - MPI communicator 2795c6c1daeSBarry Smith 2805c6c1daeSBarry Smith Output Parameter: 2815c6c1daeSBarry Smith . inviewer - location to put the PetscViewer context 2825c6c1daeSBarry Smith 2835c6c1daeSBarry Smith Level: advanced 2845c6c1daeSBarry Smith 2855c6c1daeSBarry Smith Concepts: graphics^creating PetscViewer 2865c6c1daeSBarry Smith Concepts: file input/output^creating PetscViewer 2875c6c1daeSBarry Smith Concepts: sockets^creating PetscViewer 2885c6c1daeSBarry Smith 2895c6c1daeSBarry Smith .seealso: PetscViewerDestroy(), PetscViewerSetType(), PetscViewerType 2905c6c1daeSBarry Smith 2915c6c1daeSBarry Smith @*/ 2925c6c1daeSBarry Smith PetscErrorCode PetscViewerCreate(MPI_Comm comm,PetscViewer *inviewer) 2935c6c1daeSBarry Smith { 2945c6c1daeSBarry Smith PetscViewer viewer; 2955c6c1daeSBarry Smith PetscErrorCode ierr; 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith PetscFunctionBegin; 2985c6c1daeSBarry Smith *inviewer = 0; 299607a6623SBarry Smith ierr = PetscViewerInitializePackage();CHKERRQ(ierr); 30073107ff1SLisandro Dalcin ierr = PetscHeaderCreate(viewer,PETSC_VIEWER_CLASSID,"PetscViewer","PetscViewer","Viewer",comm,PetscViewerDestroy,NULL);CHKERRQ(ierr); 3015c6c1daeSBarry Smith *inviewer = viewer; 3025c6c1daeSBarry Smith viewer->data = 0; 3035c6c1daeSBarry Smith PetscFunctionReturn(0); 3045c6c1daeSBarry Smith } 3055c6c1daeSBarry Smith 3065c6c1daeSBarry Smith #undef __FUNCT__ 3075c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetType" 3085c6c1daeSBarry Smith /*@C 3095c6c1daeSBarry Smith PetscViewerSetType - Builds PetscViewer for a particular implementation. 3105c6c1daeSBarry Smith 3115c6c1daeSBarry Smith Collective on PetscViewer 3125c6c1daeSBarry Smith 3135c6c1daeSBarry Smith Input Parameter: 3145c6c1daeSBarry Smith + viewer - the PetscViewer context 3158f6c3df8SBarry Smith - type - for example, PETSCVIEWERASCII 3165c6c1daeSBarry Smith 3175c6c1daeSBarry Smith Options Database Command: 3185c6c1daeSBarry Smith . -draw_type <type> - Sets the type; use -help for a list 3195c6c1daeSBarry Smith of available methods (for instance, ascii) 3205c6c1daeSBarry Smith 3215c6c1daeSBarry Smith Level: advanced 3225c6c1daeSBarry Smith 3235c6c1daeSBarry Smith Notes: 3245c6c1daeSBarry Smith See "include/petscviewer.h" for available methods (for instance, 3258f6c3df8SBarry Smith PETSCVIEWERSOCKET) 3265c6c1daeSBarry Smith 3276a9046bcSBarry Smith .seealso: PetscViewerCreate(), PetscViewerGetType(), PetscViewerType, PetscViewerPushFormat() 3285c6c1daeSBarry Smith @*/ 3295c6c1daeSBarry Smith PetscErrorCode PetscViewerSetType(PetscViewer viewer,PetscViewerType type) 3305c6c1daeSBarry Smith { 3315c6c1daeSBarry Smith PetscErrorCode ierr,(*r)(PetscViewer); 3325c6c1daeSBarry Smith PetscBool match; 3335c6c1daeSBarry Smith 3345c6c1daeSBarry Smith PetscFunctionBegin; 3355c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 3365c6c1daeSBarry Smith PetscValidCharPointer(type,2); 3375c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,type,&match);CHKERRQ(ierr); 3385c6c1daeSBarry Smith if (match) PetscFunctionReturn(0); 3395c6c1daeSBarry Smith 3405c6c1daeSBarry Smith /* cleanup any old type that may be there */ 3415c6c1daeSBarry Smith if (viewer->data) { 3425c6c1daeSBarry Smith ierr = (*viewer->ops->destroy)(viewer);CHKERRQ(ierr); 343a297a907SKarl Rupp 3440298fd71SBarry Smith viewer->ops->destroy = NULL; 3455c6c1daeSBarry Smith viewer->data = 0; 3465c6c1daeSBarry Smith } 3475c6c1daeSBarry Smith ierr = PetscMemzero(viewer->ops,sizeof(struct _PetscViewerOps));CHKERRQ(ierr); 3485c6c1daeSBarry Smith 3491c9cd337SJed Brown ierr = PetscFunctionListFind(PetscViewerList,type,&r);CHKERRQ(ierr); 3505c6c1daeSBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscViewer type given: %s",type); 3515c6c1daeSBarry Smith 3525c6c1daeSBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)viewer,type);CHKERRQ(ierr); 3535c6c1daeSBarry Smith ierr = (*r)(viewer);CHKERRQ(ierr); 3545c6c1daeSBarry Smith PetscFunctionReturn(0); 3555c6c1daeSBarry Smith } 3565c6c1daeSBarry Smith 3575c6c1daeSBarry Smith #undef __FUNCT__ 3585c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerRegister" 3591c84c290SBarry Smith /*@C 3601c84c290SBarry Smith PetscViewerRegister - Adds a viewer 3611c84c290SBarry Smith 3621c84c290SBarry Smith Not Collective 3631c84c290SBarry Smith 3641c84c290SBarry Smith Input Parameters: 3651c84c290SBarry Smith + name_solver - name of a new user-defined viewer 3661c84c290SBarry Smith - routine_create - routine to create method context 3671c84c290SBarry Smith 3681c84c290SBarry Smith Level: developer 3691c84c290SBarry Smith Notes: 3701c84c290SBarry Smith PetscViewerRegister() may be called multiple times to add several user-defined viewers. 3711c84c290SBarry Smith 3721c84c290SBarry Smith Sample usage: 3731c84c290SBarry Smith .vb 374bdf89e91SBarry Smith PetscViewerRegister("my_viewer_type",MyViewerCreate); 3751c84c290SBarry Smith .ve 3761c84c290SBarry Smith 3771c84c290SBarry Smith Then, your solver can be chosen with the procedural interface via 3781c84c290SBarry Smith $ PetscViewerSetType(viewer,"my_viewer_type") 3791c84c290SBarry Smith or at runtime via the option 3801c84c290SBarry Smith $ -viewer_type my_viewer_type 3811c84c290SBarry Smith 3821c84c290SBarry Smith Concepts: registering^Viewers 3831c84c290SBarry Smith 3841c84c290SBarry Smith .seealso: PetscViewerRegisterAll(), PetscViewerRegisterDestroy() 3851c84c290SBarry Smith @*/ 386bdf89e91SBarry Smith PetscErrorCode PetscViewerRegister(const char *sname,PetscErrorCode (*function)(PetscViewer)) 3875c6c1daeSBarry Smith { 3885c6c1daeSBarry Smith PetscErrorCode ierr; 3895c6c1daeSBarry Smith 3905c6c1daeSBarry Smith PetscFunctionBegin; 391a240a19fSJed Brown ierr = PetscFunctionListAdd(&PetscViewerList,sname,function);CHKERRQ(ierr); 3925c6c1daeSBarry Smith PetscFunctionReturn(0); 3935c6c1daeSBarry Smith } 3945c6c1daeSBarry Smith 3955c6c1daeSBarry Smith #undef __FUNCT__ 3965c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetFromOptions" 3975c6c1daeSBarry Smith /*@C 3985c6c1daeSBarry Smith PetscViewerSetFromOptions - Sets the graphics type from the options database. 3995c6c1daeSBarry Smith Defaults to a PETSc X windows graphics. 4005c6c1daeSBarry Smith 4015c6c1daeSBarry Smith Collective on PetscViewer 4025c6c1daeSBarry Smith 4035c6c1daeSBarry Smith Input Parameter: 4045c6c1daeSBarry Smith . PetscViewer - the graphics context 4055c6c1daeSBarry Smith 4065c6c1daeSBarry Smith Level: intermediate 4075c6c1daeSBarry Smith 4085c6c1daeSBarry Smith Notes: 4095c6c1daeSBarry Smith Must be called after PetscViewerCreate() before the PetscViewer is used. 4105c6c1daeSBarry Smith 4115c6c1daeSBarry Smith Concepts: PetscViewer^setting options 4125c6c1daeSBarry Smith 4135c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 4145c6c1daeSBarry Smith 4155c6c1daeSBarry Smith @*/ 4165c6c1daeSBarry Smith PetscErrorCode PetscViewerSetFromOptions(PetscViewer viewer) 4175c6c1daeSBarry Smith { 4185c6c1daeSBarry Smith PetscErrorCode ierr; 4195c6c1daeSBarry Smith char vtype[256]; 4205c6c1daeSBarry Smith PetscBool flg; 4215c6c1daeSBarry Smith 4225c6c1daeSBarry Smith PetscFunctionBegin; 4235c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4245c6c1daeSBarry Smith 4255c6c1daeSBarry Smith if (!PetscViewerList) { 426607a6623SBarry Smith ierr = PetscViewerRegisterAll();CHKERRQ(ierr); 4275c6c1daeSBarry Smith } 4285c6c1daeSBarry Smith ierr = PetscObjectOptionsBegin((PetscObject)viewer);CHKERRQ(ierr); 429a264d7a6SBarry Smith ierr = PetscOptionsFList("-viewer_type","Type of PetscViewer","None",PetscViewerList,(char*)(((PetscObject)viewer)->type_name ? ((PetscObject)viewer)->type_name : PETSCVIEWERASCII),vtype,256,&flg);CHKERRQ(ierr); 4305c6c1daeSBarry Smith if (flg) { 4315c6c1daeSBarry Smith ierr = PetscViewerSetType(viewer,vtype);CHKERRQ(ierr); 4325c6c1daeSBarry Smith } 4335c6c1daeSBarry Smith /* type has not been set? */ 4345c6c1daeSBarry Smith if (!((PetscObject)viewer)->type_name) { 4355c6c1daeSBarry Smith ierr = PetscViewerSetType(viewer,PETSCVIEWERASCII);CHKERRQ(ierr); 4365c6c1daeSBarry Smith } 4375c6c1daeSBarry Smith if (viewer->ops->setfromoptions) { 438e55864a3SBarry Smith ierr = (*viewer->ops->setfromoptions)(PetscOptionsObject,viewer);CHKERRQ(ierr); 4395c6c1daeSBarry Smith } 4405c6c1daeSBarry Smith 4415c6c1daeSBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 4420633abcbSJed Brown ierr = PetscObjectProcessOptionsHandlers(PetscOptionsObject,(PetscObject)viewer);CHKERRQ(ierr); 443ce1779c8SBarry Smith ierr = PetscViewerViewFromOptions(viewer,NULL,"-viewer_view");CHKERRQ(ierr); 4445c6c1daeSBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 4455c6c1daeSBarry Smith PetscFunctionReturn(0); 4465c6c1daeSBarry Smith } 447816f7b76SBarry Smith 448816f7b76SBarry Smith #undef __FUNCT__ 449816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlStart" 450816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlStart(PetscViewer viewer,PetscInt *mcnt,PetscInt *cnt) 451816f7b76SBarry Smith { 452816f7b76SBarry Smith PetscErrorCode ierr; 453816f7b76SBarry Smith PetscFunctionBegin; 454816f7b76SBarry Smith ierr = PetscViewerBinaryGetFlowControl(viewer,mcnt);CHKERRQ(ierr); 455816f7b76SBarry Smith ierr = PetscViewerBinaryGetFlowControl(viewer,cnt);CHKERRQ(ierr); 456816f7b76SBarry Smith PetscFunctionReturn(0); 457816f7b76SBarry Smith } 458816f7b76SBarry Smith 459816f7b76SBarry Smith #undef __FUNCT__ 460816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlStepMaster" 461816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlStepMaster(PetscViewer viewer,PetscInt i,PetscInt *mcnt,PetscInt cnt) 462816f7b76SBarry Smith { 463816f7b76SBarry Smith PetscErrorCode ierr; 464816f7b76SBarry Smith MPI_Comm comm; 465816f7b76SBarry Smith 466816f7b76SBarry Smith PetscFunctionBegin; 467816f7b76SBarry Smith ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); 468816f7b76SBarry Smith if (i >= *mcnt) { 469816f7b76SBarry Smith *mcnt += cnt; 470816f7b76SBarry Smith ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr); 471816f7b76SBarry Smith } 472816f7b76SBarry Smith PetscFunctionReturn(0); 473816f7b76SBarry Smith } 474816f7b76SBarry Smith 475816f7b76SBarry Smith #undef __FUNCT__ 476816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlEndMaster" 477816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlEndMaster(PetscViewer viewer,PetscInt *mcnt) 478816f7b76SBarry Smith { 479816f7b76SBarry Smith PetscErrorCode ierr; 480816f7b76SBarry Smith MPI_Comm comm; 481816f7b76SBarry Smith PetscFunctionBegin; 482816f7b76SBarry Smith ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); 483816f7b76SBarry Smith *mcnt = 0; 484816f7b76SBarry Smith ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr); 485816f7b76SBarry Smith PetscFunctionReturn(0); 486816f7b76SBarry Smith } 487816f7b76SBarry Smith 488816f7b76SBarry Smith #undef __FUNCT__ 489816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlStepWorker" 490816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlStepWorker(PetscViewer viewer,PetscMPIInt rank,PetscInt *mcnt) 491816f7b76SBarry Smith { 492816f7b76SBarry Smith PetscErrorCode ierr; 493816f7b76SBarry Smith MPI_Comm comm; 494816f7b76SBarry Smith PetscFunctionBegin; 495816f7b76SBarry Smith ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); 496816f7b76SBarry Smith while (PETSC_TRUE) { 497816f7b76SBarry Smith if (rank < *mcnt) break; 498816f7b76SBarry Smith ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr); 499816f7b76SBarry Smith } 500816f7b76SBarry Smith PetscFunctionReturn(0); 501816f7b76SBarry Smith } 502816f7b76SBarry Smith 503816f7b76SBarry Smith #undef __FUNCT__ 504816f7b76SBarry Smith #define __FUNCT__ "PetscViewerFlowControlEndWorker" 505816f7b76SBarry Smith PetscErrorCode PetscViewerFlowControlEndWorker(PetscViewer viewer,PetscInt *mcnt) 506816f7b76SBarry Smith { 507816f7b76SBarry Smith PetscErrorCode ierr; 508816f7b76SBarry Smith MPI_Comm comm; 509816f7b76SBarry Smith PetscFunctionBegin; 510816f7b76SBarry Smith ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); 511816f7b76SBarry Smith while (PETSC_TRUE) { 512816f7b76SBarry Smith ierr = MPI_Bcast(mcnt,1,MPIU_INT,0,comm);CHKERRQ(ierr); 513816f7b76SBarry Smith if (!*mcnt) break; 514816f7b76SBarry Smith } 515816f7b76SBarry Smith PetscFunctionReturn(0); 516816f7b76SBarry Smith } 517