15c6c1daeSBarry Smith 25c6c1daeSBarry Smith #include <../src/sys/classes/viewer/impls/ascii/asciiimpl.h> /*I "petscsys.h" I*/ 35c6c1daeSBarry Smith 45c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/ 55c6c1daeSBarry Smith /* 65c6c1daeSBarry Smith The variable Petsc_Viewer_Stdout_keyval is used to indicate an MPI attribute that 75c6c1daeSBarry Smith is attached to a communicator, in this case the attribute is a PetscViewer. 85c6c1daeSBarry Smith */ 95c6c1daeSBarry Smith static PetscMPIInt Petsc_Viewer_Stdout_keyval = MPI_KEYVAL_INVALID; 105c6c1daeSBarry Smith 115c6c1daeSBarry Smith #undef __FUNCT__ 125c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIGetStdout" 135c6c1daeSBarry Smith /*@C 145c6c1daeSBarry Smith PetscViewerASCIIGetStdout - Creates a ASCII PetscViewer shared by all processors 155c6c1daeSBarry Smith in a communicator. Error returning version of PETSC_VIEWER_STDOUT_() 165c6c1daeSBarry Smith 175c6c1daeSBarry Smith Collective on MPI_Comm 185c6c1daeSBarry Smith 195c6c1daeSBarry Smith Input Parameter: 205c6c1daeSBarry Smith . comm - the MPI communicator to share the PetscViewer 215c6c1daeSBarry Smith 225c6c1daeSBarry Smith Level: beginner 235c6c1daeSBarry Smith 245c6c1daeSBarry Smith Notes: 255c6c1daeSBarry Smith This should be used in all PETSc source code instead of PETSC_VIEWER_STDOUT_() 265c6c1daeSBarry Smith 275c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_(), PetscViewerASCIIOpen(), PETSC_VIEWER_STDERR_, PETSC_VIEWER_STDOUT_WORLD, 285c6c1daeSBarry Smith PETSC_VIEWER_STDOUT_SELF 295c6c1daeSBarry Smith 305c6c1daeSBarry Smith @*/ 315c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIGetStdout(MPI_Comm comm,PetscViewer *viewer) 325c6c1daeSBarry Smith { 335c6c1daeSBarry Smith PetscErrorCode ierr; 345c6c1daeSBarry Smith PetscBool flg; 355c6c1daeSBarry Smith MPI_Comm ncomm; 365c6c1daeSBarry Smith 375c6c1daeSBarry Smith PetscFunctionBegin; 380298fd71SBarry Smith ierr = PetscCommDuplicate(comm,&ncomm,NULL);CHKERRQ(ierr); 395c6c1daeSBarry Smith if (Petsc_Viewer_Stdout_keyval == MPI_KEYVAL_INVALID) { 405c6c1daeSBarry Smith ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,MPI_NULL_DELETE_FN,&Petsc_Viewer_Stdout_keyval,0);CHKERRQ(ierr); 415c6c1daeSBarry Smith } 425c6c1daeSBarry Smith ierr = MPI_Attr_get(ncomm,Petsc_Viewer_Stdout_keyval,(void**)viewer,(PetscMPIInt*)&flg);CHKERRQ(ierr); 435c6c1daeSBarry Smith if (!flg) { /* PetscViewer not yet created */ 445c6c1daeSBarry Smith ierr = PetscViewerASCIIOpen(ncomm,"stdout",viewer);CHKERRQ(ierr); 455c6c1daeSBarry Smith ierr = PetscObjectRegisterDestroy((PetscObject)*viewer);CHKERRQ(ierr); 465c6c1daeSBarry Smith ierr = MPI_Attr_put(ncomm,Petsc_Viewer_Stdout_keyval,(void*)*viewer);CHKERRQ(ierr); 475c6c1daeSBarry Smith } 485c6c1daeSBarry Smith ierr = PetscCommDestroy(&ncomm);CHKERRQ(ierr); 495c6c1daeSBarry Smith PetscFunctionReturn(0); 505c6c1daeSBarry Smith } 515c6c1daeSBarry Smith 525c6c1daeSBarry Smith #undef __FUNCT__ 535c6c1daeSBarry Smith #define __FUNCT__ "PETSC_VIEWER_STDOUT_" 545c6c1daeSBarry Smith /*@C 555c6c1daeSBarry Smith PETSC_VIEWER_STDOUT_ - Creates a ASCII PetscViewer shared by all processors 565c6c1daeSBarry Smith in a communicator. 575c6c1daeSBarry Smith 585c6c1daeSBarry Smith Collective on MPI_Comm 595c6c1daeSBarry Smith 605c6c1daeSBarry Smith Input Parameter: 615c6c1daeSBarry Smith . comm - the MPI communicator to share the PetscViewer 625c6c1daeSBarry Smith 635c6c1daeSBarry Smith Level: beginner 645c6c1daeSBarry Smith 655c6c1daeSBarry Smith Notes: 665c6c1daeSBarry Smith Unlike almost all other PETSc routines, this does not return 675c6c1daeSBarry Smith an error code. Usually used in the form 685c6c1daeSBarry Smith $ XXXView(XXX object,PETSC_VIEWER_STDOUT_(comm)); 695c6c1daeSBarry Smith 705c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_(), PetscViewerASCIIOpen(), PETSC_VIEWER_STDERR_, PETSC_VIEWER_STDOUT_WORLD, 715c6c1daeSBarry Smith PETSC_VIEWER_STDOUT_SELF 725c6c1daeSBarry Smith 735c6c1daeSBarry Smith @*/ 745c6c1daeSBarry Smith PetscViewer PETSC_VIEWER_STDOUT_(MPI_Comm comm) 755c6c1daeSBarry Smith { 765c6c1daeSBarry Smith PetscErrorCode ierr; 775c6c1daeSBarry Smith PetscViewer viewer; 785c6c1daeSBarry Smith 795c6c1daeSBarry Smith PetscFunctionBegin; 805c6c1daeSBarry Smith ierr = PetscViewerASCIIGetStdout(comm,&viewer); 815c6c1daeSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_STDOUT_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," "); PetscFunctionReturn(0);} 825c6c1daeSBarry Smith PetscFunctionReturn(viewer); 835c6c1daeSBarry Smith } 845c6c1daeSBarry Smith 855c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/ 865c6c1daeSBarry Smith /* 875c6c1daeSBarry Smith The variable Petsc_Viewer_Stderr_keyval is used to indicate an MPI attribute that 885c6c1daeSBarry Smith is attached to a communicator, in this case the attribute is a PetscViewer. 895c6c1daeSBarry Smith */ 905c6c1daeSBarry Smith static PetscMPIInt Petsc_Viewer_Stderr_keyval = MPI_KEYVAL_INVALID; 915c6c1daeSBarry Smith 925c6c1daeSBarry Smith #undef __FUNCT__ 935c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIGetStderr" 945c6c1daeSBarry Smith /*@C 955c6c1daeSBarry Smith PetscViewerASCIIGetStderr - Creates a ASCII PetscViewer shared by all processors 965c6c1daeSBarry Smith in a communicator. Error returning version of PETSC_VIEWER_STDERR_() 975c6c1daeSBarry Smith 985c6c1daeSBarry Smith Collective on MPI_Comm 995c6c1daeSBarry Smith 1005c6c1daeSBarry Smith Input Parameter: 1015c6c1daeSBarry Smith . comm - the MPI communicator to share the PetscViewer 1025c6c1daeSBarry Smith 1035c6c1daeSBarry Smith Level: beginner 1045c6c1daeSBarry Smith 1055c6c1daeSBarry Smith Notes: 1065c6c1daeSBarry Smith This should be used in all PETSc source code instead of PETSC_VIEWER_STDERR_() 1075c6c1daeSBarry Smith 1085c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_(), PetscViewerASCIIOpen(), PETSC_VIEWER_STDERR_, PETSC_VIEWER_STDERR_WORLD, 1095c6c1daeSBarry Smith PETSC_VIEWER_STDERR_SELF 1105c6c1daeSBarry Smith 1115c6c1daeSBarry Smith @*/ 1125c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIGetStderr(MPI_Comm comm,PetscViewer *viewer) 1135c6c1daeSBarry Smith { 1145c6c1daeSBarry Smith PetscErrorCode ierr; 1155c6c1daeSBarry Smith PetscBool flg; 1165c6c1daeSBarry Smith MPI_Comm ncomm; 1175c6c1daeSBarry Smith 1185c6c1daeSBarry Smith PetscFunctionBegin; 1190298fd71SBarry Smith ierr = PetscCommDuplicate(comm,&ncomm,NULL);CHKERRQ(ierr); 1205c6c1daeSBarry Smith if (Petsc_Viewer_Stderr_keyval == MPI_KEYVAL_INVALID) { 1215c6c1daeSBarry Smith ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,MPI_NULL_DELETE_FN,&Petsc_Viewer_Stderr_keyval,0);CHKERRQ(ierr); 1225c6c1daeSBarry Smith } 1235c6c1daeSBarry Smith ierr = MPI_Attr_get(ncomm,Petsc_Viewer_Stderr_keyval,(void**)viewer,(PetscMPIInt*)&flg);CHKERRQ(ierr); 1245c6c1daeSBarry Smith if (!flg) { /* PetscViewer not yet created */ 1255c6c1daeSBarry Smith ierr = PetscViewerASCIIOpen(ncomm,"stderr",viewer);CHKERRQ(ierr); 1265c6c1daeSBarry Smith ierr = PetscObjectRegisterDestroy((PetscObject)*viewer);CHKERRQ(ierr); 1275c6c1daeSBarry Smith ierr = MPI_Attr_put(ncomm,Petsc_Viewer_Stderr_keyval,(void*)*viewer);CHKERRQ(ierr); 1285c6c1daeSBarry Smith } 1295c6c1daeSBarry Smith ierr = PetscCommDestroy(&ncomm);CHKERRQ(ierr); 1305c6c1daeSBarry Smith PetscFunctionReturn(0); 1315c6c1daeSBarry Smith } 1325c6c1daeSBarry Smith 1335c6c1daeSBarry Smith #undef __FUNCT__ 1345c6c1daeSBarry Smith #define __FUNCT__ "PETSC_VIEWER_STDERR_" 1355c6c1daeSBarry Smith /*@C 1365c6c1daeSBarry Smith PETSC_VIEWER_STDERR_ - Creates a ASCII PetscViewer shared by all processors 1375c6c1daeSBarry Smith in a communicator. 1385c6c1daeSBarry Smith 1395c6c1daeSBarry Smith Collective on MPI_Comm 1405c6c1daeSBarry Smith 1415c6c1daeSBarry Smith Input Parameter: 1425c6c1daeSBarry Smith . comm - the MPI communicator to share the PetscViewer 1435c6c1daeSBarry Smith 1445c6c1daeSBarry Smith Level: beginner 1455c6c1daeSBarry Smith 1465c6c1daeSBarry Smith Note: 1475c6c1daeSBarry Smith Unlike almost all other PETSc routines, this does not return 1485c6c1daeSBarry Smith an error code. Usually used in the form 1495c6c1daeSBarry Smith $ XXXView(XXX object,PETSC_VIEWER_STDERR_(comm)); 1505c6c1daeSBarry Smith 1515c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_, PetscViewerASCIIOpen(), PETSC_VIEWER_STDOUT_, PETSC_VIEWER_STDOUT_WORLD, 1525c6c1daeSBarry Smith PETSC_VIEWER_STDOUT_SELF, PETSC_VIEWER_STDERR_WORLD, PETSC_VIEWER_STDERR_SELF 1535c6c1daeSBarry Smith @*/ 1545c6c1daeSBarry Smith PetscViewer PETSC_VIEWER_STDERR_(MPI_Comm comm) 1555c6c1daeSBarry Smith { 1565c6c1daeSBarry Smith PetscErrorCode ierr; 1575c6c1daeSBarry Smith PetscViewer viewer; 1585c6c1daeSBarry Smith 1595c6c1daeSBarry Smith PetscFunctionBegin; 1605c6c1daeSBarry Smith ierr = PetscViewerASCIIGetStderr(comm,&viewer); 1615c6c1daeSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_STDERR_",__FILE__,__SDIR__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," "); PetscFunctionReturn(0);} 1625c6c1daeSBarry Smith PetscFunctionReturn(viewer); 1635c6c1daeSBarry Smith } 1645c6c1daeSBarry Smith 1655c6c1daeSBarry Smith 1665c6c1daeSBarry Smith PetscMPIInt Petsc_Viewer_keyval = MPI_KEYVAL_INVALID; 1675c6c1daeSBarry Smith #undef __FUNCT__ 1685c6c1daeSBarry Smith #define __FUNCT__ "Petsc_DelViewer" 1695c6c1daeSBarry Smith /* 1705c6c1daeSBarry Smith Called with MPI_Comm_free() is called on a communicator that has a viewer as an attribute. The viewer is not actually destroyed because that is managed by 1715c6c1daeSBarry Smith PetscObjectDestroyRegisterAll(). PetscViewerASCIIGetStdout() registers the viewer with PetscObjectDestroyRegister() to be destroyed when PetscFinalize() is called. 1725c6c1daeSBarry Smith 1735c6c1daeSBarry Smith This is called by MPI, not by users. 1745c6c1daeSBarry Smith 1755c6c1daeSBarry Smith */ 176*8cc058d9SJed Brown PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelViewer(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state) 1775c6c1daeSBarry Smith { 1785c6c1daeSBarry Smith PetscErrorCode ierr; 1795c6c1daeSBarry Smith 1805c6c1daeSBarry Smith PetscFunctionBegin; 1815c6c1daeSBarry Smith ierr = PetscInfo1(0,"Removing viewer data attribute in an MPI_Comm %ld\n",(long)comm);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr); 1825c6c1daeSBarry Smith PetscFunctionReturn(MPI_SUCCESS); 1835c6c1daeSBarry Smith } 1845c6c1daeSBarry Smith 1855c6c1daeSBarry Smith #undef __FUNCT__ 1865c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIOpen" 1875c6c1daeSBarry Smith /*@C 1885c6c1daeSBarry Smith PetscViewerASCIIOpen - Opens an ASCII file as a PetscViewer. 1895c6c1daeSBarry Smith 1905c6c1daeSBarry Smith Collective on MPI_Comm 1915c6c1daeSBarry Smith 1925c6c1daeSBarry Smith Input Parameters: 1935c6c1daeSBarry Smith + comm - the communicator 1945c6c1daeSBarry Smith - name - the file name 1955c6c1daeSBarry Smith 1965c6c1daeSBarry Smith Output Parameter: 1975c6c1daeSBarry Smith . lab - the PetscViewer to use with the specified file 1985c6c1daeSBarry Smith 1995c6c1daeSBarry Smith Level: beginner 2005c6c1daeSBarry Smith 2015c6c1daeSBarry Smith Notes: 2025c6c1daeSBarry Smith This PetscViewer can be destroyed with PetscViewerDestroy(). 2035c6c1daeSBarry Smith 2045c6c1daeSBarry Smith If a multiprocessor communicator is used (such as PETSC_COMM_WORLD), 2055c6c1daeSBarry Smith then only the first processor in the group opens the file. All other 2065c6c1daeSBarry Smith processors send their data to the first processor to print. 2075c6c1daeSBarry Smith 2085c6c1daeSBarry Smith Each processor can instead write its own independent output by 2095c6c1daeSBarry Smith specifying the communicator PETSC_COMM_SELF. 2105c6c1daeSBarry Smith 2115c6c1daeSBarry Smith As shown below, PetscViewerASCIIOpen() is useful in conjunction with 2125c6c1daeSBarry Smith MatView() and VecView() 2135c6c1daeSBarry Smith .vb 2145c6c1daeSBarry Smith PetscViewerASCIIOpen(PETSC_COMM_WORLD,"mat.output",&viewer); 2155c6c1daeSBarry Smith MatView(matrix,viewer); 2165c6c1daeSBarry Smith .ve 2175c6c1daeSBarry Smith 2185c6c1daeSBarry Smith Concepts: PetscViewerASCII^creating 2195c6c1daeSBarry Smith Concepts: printf 2205c6c1daeSBarry Smith Concepts: printing 2215c6c1daeSBarry Smith Concepts: accessing remote file 2225c6c1daeSBarry Smith Concepts: remote file 2235c6c1daeSBarry Smith 2245c6c1daeSBarry Smith .seealso: MatView(), VecView(), PetscViewerDestroy(), PetscViewerBinaryOpen(), 2255c6c1daeSBarry Smith PetscViewerASCIIGetPointer(), PetscViewerSetFormat(), PETSC_VIEWER_STDOUT_, PETSC_VIEWER_STDERR_, 2265c6c1daeSBarry Smith PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_STDOUT_SELF, 2275c6c1daeSBarry Smith @*/ 2285c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIOpen(MPI_Comm comm,const char name[],PetscViewer *lab) 2295c6c1daeSBarry Smith { 2305c6c1daeSBarry Smith PetscErrorCode ierr; 2315c6c1daeSBarry Smith PetscViewerLink *vlink,*nv; 2325c6c1daeSBarry Smith PetscBool flg,eq; 2335c6c1daeSBarry Smith size_t len; 2345c6c1daeSBarry Smith 2355c6c1daeSBarry Smith PetscFunctionBegin; 2365c6c1daeSBarry Smith ierr = PetscStrlen(name,&len);CHKERRQ(ierr); 2375c6c1daeSBarry Smith if (!len) { 2385c6c1daeSBarry Smith ierr = PetscViewerASCIIGetStdout(comm,lab);CHKERRQ(ierr); 2395c6c1daeSBarry Smith ierr = PetscObjectReference((PetscObject)*lab);CHKERRQ(ierr); 2405c6c1daeSBarry Smith PetscFunctionReturn(0); 2415c6c1daeSBarry Smith } 2425c6c1daeSBarry Smith if (Petsc_Viewer_keyval == MPI_KEYVAL_INVALID) { 2435c6c1daeSBarry Smith ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelViewer,&Petsc_Viewer_keyval,(void*)0);CHKERRQ(ierr); 2445c6c1daeSBarry Smith } 2452bf49c77SBarry Smith /* 2462bf49c77SBarry Smith It would be better to move this code to PetscFileSetName() but since it must return a preexiting communicator 2472bf49c77SBarry Smith we cannot do that, since PetscFileSetName() takes a communicator that already exists. 2482bf49c77SBarry Smith 2492bf49c77SBarry Smith Plus if the original communicator that created the file has since been close this will not detect the old 2502bf49c77SBarry Smith communictor and hence will overwrite the old data. It may be better to simply remove all this code 2512bf49c77SBarry Smith */ 2525c6c1daeSBarry Smith /* make sure communicator is a PETSc communicator */ 2530298fd71SBarry Smith ierr = PetscCommDuplicate(comm,&comm,NULL);CHKERRQ(ierr); 2545c6c1daeSBarry Smith /* has file already been opened into a viewer */ 2555c6c1daeSBarry Smith ierr = MPI_Attr_get(comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg);CHKERRQ(ierr); 2565c6c1daeSBarry Smith if (flg) { 2575c6c1daeSBarry Smith while (vlink) { 2585c6c1daeSBarry Smith ierr = PetscStrcmp(name,((PetscViewer_ASCII*)(vlink->viewer->data))->filename,&eq);CHKERRQ(ierr); 2595c6c1daeSBarry Smith if (eq) { 2605c6c1daeSBarry Smith ierr = PetscObjectReference((PetscObject)vlink->viewer);CHKERRQ(ierr); 2615c6c1daeSBarry Smith *lab = vlink->viewer; 2625c6c1daeSBarry Smith ierr = PetscCommDestroy(&comm);CHKERRQ(ierr); 2635c6c1daeSBarry Smith PetscFunctionReturn(0); 2645c6c1daeSBarry Smith } 2655c6c1daeSBarry Smith vlink = vlink->next; 2665c6c1daeSBarry Smith } 2675c6c1daeSBarry Smith } 2685c6c1daeSBarry Smith ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr); 2695c6c1daeSBarry Smith ierr = PetscViewerSetType(*lab,PETSCVIEWERASCII);CHKERRQ(ierr); 2705c6c1daeSBarry Smith if (name) { 2715c6c1daeSBarry Smith ierr = PetscViewerFileSetName(*lab,name);CHKERRQ(ierr); 2725c6c1daeSBarry Smith } 2735c6c1daeSBarry Smith /* save viewer into communicator if needed later */ 2745c6c1daeSBarry Smith ierr = PetscNew(PetscViewerLink,&nv);CHKERRQ(ierr); 2755c6c1daeSBarry Smith nv->viewer = *lab; 2765c6c1daeSBarry Smith if (!flg) { 2775c6c1daeSBarry Smith ierr = MPI_Attr_put(comm,Petsc_Viewer_keyval,nv);CHKERRQ(ierr); 2785c6c1daeSBarry Smith } else { 2795c6c1daeSBarry Smith ierr = MPI_Attr_get(comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg);CHKERRQ(ierr); 2805c6c1daeSBarry Smith if (vlink) { 2815c6c1daeSBarry Smith while (vlink->next) vlink = vlink->next; 2825c6c1daeSBarry Smith vlink->next = nv; 2835c6c1daeSBarry Smith } else { 2845c6c1daeSBarry Smith ierr = MPI_Attr_put(comm,Petsc_Viewer_keyval,nv);CHKERRQ(ierr); 2855c6c1daeSBarry Smith } 2865c6c1daeSBarry Smith } 2875c6c1daeSBarry Smith ierr = PetscCommDestroy(&comm);CHKERRQ(ierr); 2885c6c1daeSBarry Smith PetscFunctionReturn(0); 2895c6c1daeSBarry Smith } 2905c6c1daeSBarry Smith 2915c6c1daeSBarry Smith #undef __FUNCT__ 2925c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIIOpenWithFILE" 2935c6c1daeSBarry Smith /*@C 2945c6c1daeSBarry Smith PetscViewerASCIIOpenWithFILE - Given an open file creates an ASCII viewer that prints to it. 2955c6c1daeSBarry Smith 2965c6c1daeSBarry Smith Collective on MPI_Comm 2975c6c1daeSBarry Smith 2985c6c1daeSBarry Smith Input Parameters: 2995c6c1daeSBarry Smith + comm - the communicator 3005c6c1daeSBarry Smith - fd - the FILE pointer 3015c6c1daeSBarry Smith 3025c6c1daeSBarry Smith Output Parameter: 3035c6c1daeSBarry Smith . lab - the PetscViewer to use with the specified file 3045c6c1daeSBarry Smith 3055c6c1daeSBarry Smith Level: beginner 3065c6c1daeSBarry Smith 3075c6c1daeSBarry Smith Notes: 3085c6c1daeSBarry Smith This PetscViewer can be destroyed with PetscViewerDestroy(), but the fd will NOT be closed. 3095c6c1daeSBarry Smith 3105c6c1daeSBarry Smith If a multiprocessor communicator is used (such as PETSC_COMM_WORLD), 3115c6c1daeSBarry Smith then only the first processor in the group uses the file. All other 3125c6c1daeSBarry Smith processors send their data to the first processor to print. 3135c6c1daeSBarry Smith 3145c6c1daeSBarry Smith Concepts: PetscViewerASCII^creating 3155c6c1daeSBarry Smith Concepts: printf 3165c6c1daeSBarry Smith Concepts: printing 3175c6c1daeSBarry Smith Concepts: accessing remote file 3185c6c1daeSBarry Smith Concepts: remote file 3195c6c1daeSBarry Smith 3205c6c1daeSBarry Smith .seealso: MatView(), VecView(), PetscViewerDestroy(), PetscViewerBinaryOpen(), 3215c6c1daeSBarry Smith PetscViewerASCIIGetPointer(), PetscViewerSetFormat(), PETSC_VIEWER_STDOUT_, PETSC_VIEWER_STDERR_, 3225c6c1daeSBarry Smith PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_STDOUT_SELF, PetscViewerASCIIOpen() 3235c6c1daeSBarry Smith @*/ 3245c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIIOpenWithFILE(MPI_Comm comm,FILE *fd,PetscViewer *lab) 3255c6c1daeSBarry Smith { 3265c6c1daeSBarry Smith PetscErrorCode ierr; 3275c6c1daeSBarry Smith 3285c6c1daeSBarry Smith PetscFunctionBegin; 3295c6c1daeSBarry Smith ierr = PetscViewerCreate(comm,lab);CHKERRQ(ierr); 3305c6c1daeSBarry Smith ierr = PetscViewerSetType(*lab,PETSCVIEWERASCII);CHKERRQ(ierr); 3315c6c1daeSBarry Smith ierr = PetscViewerASCIISetFILE(*lab,fd);CHKERRQ(ierr); 3325c6c1daeSBarry Smith PetscFunctionReturn(0); 3335c6c1daeSBarry Smith } 3345c6c1daeSBarry Smith 3355c6c1daeSBarry Smith #undef __FUNCT__ 3365c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerASCIISetFILE" 3375c6c1daeSBarry Smith PetscErrorCode PetscViewerASCIISetFILE(PetscViewer viewer,FILE *fd) 3385c6c1daeSBarry Smith { 3395c6c1daeSBarry Smith PetscViewer_ASCII *vascii = (PetscViewer_ASCII*)viewer->data; 3405c6c1daeSBarry Smith 3415c6c1daeSBarry Smith PetscFunctionBegin; 3425c6c1daeSBarry Smith vascii->fd = fd; 3435c6c1daeSBarry Smith vascii->closefile = PETSC_FALSE; 3445c6c1daeSBarry Smith PetscFunctionReturn(0); 3455c6c1daeSBarry Smith } 3465c6c1daeSBarry Smith 3475c6c1daeSBarry Smith 3485c6c1daeSBarry Smith 349