15c6c1daeSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> 35c6c1daeSBarry Smith #include <mat.h> 45c6c1daeSBarry Smith 55c6c1daeSBarry Smith 65c6c1daeSBarry Smith typedef struct { 75c6c1daeSBarry Smith MATFile *ep; 85c6c1daeSBarry Smith PetscMPIInt rank; 95c6c1daeSBarry Smith PetscFileMode btype; 105c6c1daeSBarry Smith } PetscViewer_Matlab; 115c6c1daeSBarry Smith 125c6c1daeSBarry Smith /*@C 135c6c1daeSBarry Smith PetscViewerMatlabPutArray - Puts an array into the MATLAB viewer. 145c6c1daeSBarry Smith 155c6c1daeSBarry Smith Not collective: only processor zero saves the array 165c6c1daeSBarry Smith 175c6c1daeSBarry Smith Input Parameters: 185c6c1daeSBarry Smith + mfile - the viewer 195c6c1daeSBarry Smith . m,n - the dimensions of the array 205c6c1daeSBarry Smith . array - the array (represented in one dimension) 215c6c1daeSBarry Smith - name - the name of the array 225c6c1daeSBarry Smith 235c6c1daeSBarry Smith Level: advanced 245c6c1daeSBarry Smith 2595452b02SPatrick Sanan Notes: 2695452b02SPatrick Sanan Only writes array values on processor 0. 275c6c1daeSBarry Smith 285c6c1daeSBarry Smith @*/ 295c6c1daeSBarry Smith PetscErrorCode PetscViewerMatlabPutArray(PetscViewer mfile,int m,int n,const PetscScalar *array,const char *name) 305c6c1daeSBarry Smith { 315c6c1daeSBarry Smith PetscErrorCode ierr; 322cb5e1ccSBarry Smith PetscViewer_Matlab *ml; 335c6c1daeSBarry Smith mxArray *mat; 345c6c1daeSBarry Smith 355c6c1daeSBarry Smith PetscFunctionBegin; 362cb5e1ccSBarry Smith if (!mfile) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null argument: probably PETSC_VIEWER_MATLAB_() failed"); 372cb5e1ccSBarry Smith ml = (PetscViewer_Matlab*)mfile->data; 385c6c1daeSBarry Smith if (!ml->rank) { 395c6c1daeSBarry Smith ierr = PetscInfo1(mfile,"Putting MATLAB array %s\n",name);CHKERRQ(ierr); 405c6c1daeSBarry Smith #if !defined(PETSC_USE_COMPLEX) 415c6c1daeSBarry Smith mat = mxCreateDoubleMatrix(m,n,mxREAL); 425c6c1daeSBarry Smith #else 435c6c1daeSBarry Smith mat = mxCreateDoubleMatrix(m,n,mxCOMPLEX); 445c6c1daeSBarry Smith #endif 45580bdb30SBarry Smith ierr = PetscArraycpy(mxGetPr(mat),array,m*n);CHKERRQ(ierr); 465c6c1daeSBarry Smith matPutVariable(ml->ep,name,mat); 475c6c1daeSBarry Smith 485c6c1daeSBarry Smith ierr = PetscInfo1(mfile,"Put MATLAB array %s\n",name);CHKERRQ(ierr); 495c6c1daeSBarry Smith } 505c6c1daeSBarry Smith PetscFunctionReturn(0); 515c6c1daeSBarry Smith } 525c6c1daeSBarry Smith 535c6c1daeSBarry Smith PetscErrorCode PetscViewerMatlabPutVariable(PetscViewer viewer,const char *name,void *mat) 545c6c1daeSBarry Smith { 55a297a907SKarl Rupp PetscViewer_Matlab *ml = (PetscViewer_Matlab*)viewer->data; 565c6c1daeSBarry Smith 575c6c1daeSBarry Smith PetscFunctionBegin; 585c6c1daeSBarry Smith matPutVariable(ml->ep,name,(mxArray*)mat); 595c6c1daeSBarry Smith PetscFunctionReturn(0); 605c6c1daeSBarry Smith } 615c6c1daeSBarry Smith 625c6c1daeSBarry Smith /*@C 635c6c1daeSBarry Smith PetscViewerMatlabGetArray - Gets a variable from a MATLAB viewer into an array 645c6c1daeSBarry Smith 655c6c1daeSBarry Smith Not Collective; only processor zero reads in the array 665c6c1daeSBarry Smith 675c6c1daeSBarry Smith Input Parameters: 685c6c1daeSBarry Smith + mfile - the MATLAB file viewer 695c6c1daeSBarry Smith . m,n - the dimensions of the array 705c6c1daeSBarry Smith . array - the array (represented in one dimension) 715c6c1daeSBarry Smith - name - the name of the array 725c6c1daeSBarry Smith 735c6c1daeSBarry Smith Level: advanced 745c6c1daeSBarry Smith 7595452b02SPatrick Sanan Notes: 7695452b02SPatrick Sanan Only reads in array values on processor 0. 775c6c1daeSBarry Smith 785c6c1daeSBarry Smith @*/ 795c6c1daeSBarry Smith PetscErrorCode PetscViewerMatlabGetArray(PetscViewer mfile,int m,int n,PetscScalar *array,const char *name) 805c6c1daeSBarry Smith { 815c6c1daeSBarry Smith PetscErrorCode ierr; 822cb5e1ccSBarry Smith PetscViewer_Matlab *ml; 835c6c1daeSBarry Smith mxArray *mat; 845c6c1daeSBarry Smith 855c6c1daeSBarry Smith PetscFunctionBegin; 862cb5e1ccSBarry Smith if (!mfile) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null argument: probably PETSC_VIEWER_MATLAB_() failed"); 872cb5e1ccSBarry Smith ml = (PetscViewer_Matlab*)mfile->data; 885c6c1daeSBarry Smith if (!ml->rank) { 895c6c1daeSBarry Smith ierr = PetscInfo1(mfile,"Getting MATLAB array %s\n",name);CHKERRQ(ierr); 905c6c1daeSBarry Smith mat = matGetVariable(ml->ep,name); 915c6c1daeSBarry Smith if (!mat) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unable to get array %s from matlab",name); 92580bdb30SBarry Smith ierr = PetscArraycpy(array,mxGetPr(mat),m*n);CHKERRQ(ierr); 935c6c1daeSBarry Smith ierr = PetscInfo1(mfile,"Got MATLAB array %s\n",name);CHKERRQ(ierr); 945c6c1daeSBarry Smith } 955c6c1daeSBarry Smith PetscFunctionReturn(0); 965c6c1daeSBarry Smith } 975c6c1daeSBarry Smith 985c6c1daeSBarry Smith PetscErrorCode PetscViewerFileSetMode_Matlab(PetscViewer viewer,PetscFileMode type) 995c6c1daeSBarry Smith { 1005c6c1daeSBarry Smith PetscViewer_Matlab *vmatlab = (PetscViewer_Matlab*)viewer->data; 1015c6c1daeSBarry Smith 1025c6c1daeSBarry Smith PetscFunctionBegin; 1035c6c1daeSBarry Smith vmatlab->btype = type; 1045c6c1daeSBarry Smith PetscFunctionReturn(0); 1055c6c1daeSBarry Smith } 1065c6c1daeSBarry Smith 1075c6c1daeSBarry Smith /* 1085c6c1daeSBarry Smith Actually opens the file 1095c6c1daeSBarry Smith */ 1105c6c1daeSBarry Smith PetscErrorCode PetscViewerFileSetName_Matlab(PetscViewer viewer,const char name[]) 1115c6c1daeSBarry Smith { 1125c6c1daeSBarry Smith PetscViewer_Matlab *vmatlab = (PetscViewer_Matlab*)viewer->data; 1135c6c1daeSBarry Smith PetscFileMode type = vmatlab->btype; 1145c6c1daeSBarry Smith 1155c6c1daeSBarry Smith PetscFunctionBegin; 1165c6c1daeSBarry Smith if (type == (PetscFileMode) -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Must call PetscViewerFileSetMode() before PetscViewerFileSetName()"); 1175c6c1daeSBarry Smith if (vmatlab->ep) matClose(vmatlab->ep); 1185c6c1daeSBarry Smith 1195c6c1daeSBarry Smith /* only first processor opens file */ 1205c6c1daeSBarry Smith if (!vmatlab->rank) { 121a297a907SKarl Rupp if (type == FILE_MODE_READ) vmatlab->ep = matOpen(name,"r"); 122*7e4fd573SVaclav Hapla else if (type == FILE_MODE_WRITE) vmatlab->ep = matOpen(name,"w"); 123*7e4fd573SVaclav Hapla else if (type == FILE_MODE_UNDEFINED) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ORDER, "Must call PetscViewerFileSetMode() before PetscViewerFileSetName()"); 124*7e4fd573SVaclav Hapla else SETERRQ1(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP, "Unsupported file mode %s",PetscFileModes[type]); 1255c6c1daeSBarry Smith } 1265c6c1daeSBarry Smith PetscFunctionReturn(0); 1275c6c1daeSBarry Smith } 1285c6c1daeSBarry Smith 1295c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy_Matlab(PetscViewer v) 1305c6c1daeSBarry Smith { 1315c6c1daeSBarry Smith PetscErrorCode ierr; 1325c6c1daeSBarry Smith PetscViewer_Matlab *vf = (PetscViewer_Matlab*)v->data; 1335c6c1daeSBarry Smith 1345c6c1daeSBarry Smith PetscFunctionBegin; 1355c6c1daeSBarry Smith if (vf->ep) matClose(vf->ep); 1365c6c1daeSBarry Smith ierr = PetscFree(vf);CHKERRQ(ierr); 1375c6c1daeSBarry Smith PetscFunctionReturn(0); 1385c6c1daeSBarry Smith } 1395c6c1daeSBarry Smith 1408556b5ebSBarry Smith /*MC 1418556b5ebSBarry Smith PETSCVIEWERMATLAB - A viewer that saves the variables into a MATLAB .mat file that may be read into MATLAB 1428556b5ebSBarry Smith with load('filename'). 1438556b5ebSBarry Smith 1448556b5ebSBarry Smith Level: intermediate 1458556b5ebSBarry Smith 1468556b5ebSBarry Smith Note: Currently can only save PETSc vectors to .mat files, not matrices (use the PETSCVIEWERBINARY and 1478556b5ebSBarry Smith ${PETSC_DIR}/share/petsc/matlab/PetscBinaryRead.m to read matrices into MATLAB). 1488556b5ebSBarry Smith 1498556b5ebSBarry Smith For parallel vectors obtained with DMCreateGlobalVector() or DMGetGlobalVector() the vectors are saved to 1508556b5ebSBarry Smith the .mat file in natural ordering. You can use DMView() to save the DMDA information to the .mat file 1518556b5ebSBarry Smith the fields in the MATLAB loaded da variable give the array dimensions so you can reshape the MATLAB 1528556b5ebSBarry Smith vector to the same multidimensional shape as it had in PETSc for plotting etc. For example, 1538556b5ebSBarry Smith 1548556b5ebSBarry Smith $ In your PETSc C/C++ code (assuming a two dimensional DMDA with one degree of freedom per node) 1558556b5ebSBarry Smith $ PetscObjectSetName((PetscObject)x,"x"); 1568556b5ebSBarry Smith $ VecView(x,PETSC_VIEWER_MATLAB_WORLD); 1578556b5ebSBarry Smith $ PetscObjectSetName((PetscObject)da,"da"); 1588556b5ebSBarry Smith $ DMView(x,PETSC_VIEWER_MATLAB_WORLD); 1598556b5ebSBarry Smith $ Then from MATLAB 1608556b5ebSBarry Smith $ load('matlaboutput.mat') % matlaboutput.mat is the default filename 1618556b5ebSBarry Smith $ xnew = zeros(da.n,da.m); 1628556b5ebSBarry Smith $ xnew(:) = x; % reshape one dimensional vector back to two dimensions 1638556b5ebSBarry Smith 1648556b5ebSBarry Smith If you wish to put the same variable into the .mat file several times you need to give it a new 1658556b5ebSBarry Smith name before each call to view. 1668556b5ebSBarry Smith 1678556b5ebSBarry Smith Use PetscViewerMatlabPutArray() to just put an array of doubles into the .mat file 1688556b5ebSBarry Smith 1698556b5ebSBarry Smith .seealso: PETSC_VIEWER_MATLAB_(),PETSC_VIEWER_MATLAB_SELF, PETSC_VIEWER_MATLAB_WORLD,PetscViewerCreate(), 1708556b5ebSBarry Smith PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERBINARY, PETSCVIEWERASCII, PETSCVIEWERDRAW, 1718556b5ebSBarry Smith PETSC_VIEWER_STDOUT_(), PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat 1728556b5ebSBarry Smith 1738556b5ebSBarry Smith M*/ 1748cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerCreate_Matlab(PetscViewer viewer) 1755c6c1daeSBarry Smith { 1765c6c1daeSBarry Smith PetscErrorCode ierr; 1775c6c1daeSBarry Smith PetscViewer_Matlab *e; 1785c6c1daeSBarry Smith 1795c6c1daeSBarry Smith PetscFunctionBegin; 180b00a9115SJed Brown ierr = PetscNewLog(viewer,&e);CHKERRQ(ierr); 18155b25c41SPierre Jolivet ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&e->rank);CHKERRMPI(ierr); 182*7e4fd573SVaclav Hapla e->btype = FILE_MODE_UNDEFINED; 1835c6c1daeSBarry Smith viewer->data = (void*) e; 184a297a907SKarl Rupp 185bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetName_C",PetscViewerFileSetName_Matlab);CHKERRQ(ierr); 186bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)viewer,"PetscViewerFileSetMode_C",PetscViewerFileSetMode_Matlab);CHKERRQ(ierr); 187a297a907SKarl Rupp 1885c6c1daeSBarry Smith viewer->ops->destroy = PetscViewerDestroy_Matlab; 1895c6c1daeSBarry Smith PetscFunctionReturn(0); 1905c6c1daeSBarry Smith } 1915c6c1daeSBarry Smith 1925c6c1daeSBarry Smith /*@C 1935c6c1daeSBarry Smith PetscViewerMatlabOpen - Opens a Matlab .mat file for output 1945c6c1daeSBarry Smith 195d083f849SBarry Smith Collective 1965c6c1daeSBarry Smith 1975c6c1daeSBarry Smith Input Parameters: 1985c6c1daeSBarry Smith + comm - MPI communicator 1995c6c1daeSBarry Smith . name - name of file 2005c6c1daeSBarry Smith - type - type of file 2015c6c1daeSBarry Smith $ FILE_MODE_WRITE - create new file for MATLAB output 2025c6c1daeSBarry Smith $ FILE_MODE_READ - open existing file for MATLAB input 2035c6c1daeSBarry Smith $ FILE_MODE_WRITE - open existing file for MATLAB output 2045c6c1daeSBarry Smith 2055c6c1daeSBarry Smith Output Parameter: 2065c6c1daeSBarry Smith . binv - PetscViewer for MATLAB output to use with the specified file 2075c6c1daeSBarry Smith 2085c6c1daeSBarry Smith Level: beginner 2095c6c1daeSBarry Smith 2105c6c1daeSBarry Smith Note: This PetscViewer should be destroyed with PetscViewerDestroy(). 2115c6c1daeSBarry Smith 2125c6c1daeSBarry Smith For writing files it only opens the file on processor 0 in the communicator. 2135c6c1daeSBarry Smith 2145c6c1daeSBarry Smith This only saves Vecs it cannot be used to save Mats. We recommend using the PETSCVIEWERBINARY to save objects to be loaded into MATLAB 2155c6c1daeSBarry Smith instead of this routine. 2165c6c1daeSBarry Smith 2175c6c1daeSBarry Smith 2186a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), PETSCVIEWERBINARY, PetscViewerBinaryOpen() 2195c6c1daeSBarry Smith VecView(), MatView(), VecLoad(), MatLoad() 2205c6c1daeSBarry Smith @*/ 2215c6c1daeSBarry Smith PetscErrorCode PetscViewerMatlabOpen(MPI_Comm comm,const char name[],PetscFileMode type,PetscViewer *binv) 2225c6c1daeSBarry Smith { 2235c6c1daeSBarry Smith PetscErrorCode ierr; 2245c6c1daeSBarry Smith 2255c6c1daeSBarry Smith PetscFunctionBegin; 2265c6c1daeSBarry Smith ierr = PetscViewerCreate(comm,binv);CHKERRQ(ierr); 2275c6c1daeSBarry Smith ierr = PetscViewerSetType(*binv,PETSCVIEWERMATLAB);CHKERRQ(ierr); 2285c6c1daeSBarry Smith ierr = PetscViewerFileSetMode(*binv,type);CHKERRQ(ierr); 2295c6c1daeSBarry Smith ierr = PetscViewerFileSetName(*binv,name);CHKERRQ(ierr); 2305c6c1daeSBarry Smith PetscFunctionReturn(0); 2315c6c1daeSBarry Smith } 2325c6c1daeSBarry Smith 2335c6c1daeSBarry Smith static PetscMPIInt Petsc_Viewer_Matlab_keyval = MPI_KEYVAL_INVALID; 2345c6c1daeSBarry Smith 2355c6c1daeSBarry Smith /*@C 2365c6c1daeSBarry Smith PETSC_VIEWER_MATLAB_ - Creates a Matlab PetscViewer shared by all processors 2375c6c1daeSBarry Smith in a communicator. 2385c6c1daeSBarry Smith 239d083f849SBarry Smith Collective 2405c6c1daeSBarry Smith 2415c6c1daeSBarry Smith Input Parameter: 2425c6c1daeSBarry Smith . comm - the MPI communicator to share the Matlab PetscViewer 2435c6c1daeSBarry Smith 2445c6c1daeSBarry Smith Level: intermediate 2455c6c1daeSBarry Smith 2465c6c1daeSBarry Smith Options Database Keys: 247e1bc860dSBarry Smith . -viewer_matlab_filename <name> 2485c6c1daeSBarry Smith 2495c6c1daeSBarry Smith Environmental variables: 250e1bc860dSBarry Smith . PETSC_VIEWER_MATLAB_FILENAME 2515c6c1daeSBarry Smith 2525c6c1daeSBarry Smith Notes: 2535c6c1daeSBarry Smith Unlike almost all other PETSc routines, PETSC_VIEWER_MATLAB_ does not return 2545c6c1daeSBarry Smith an error code. The matlab PetscViewer is usually used in the form 2555c6c1daeSBarry Smith $ XXXView(XXX object,PETSC_VIEWER_MATLAB_(comm)); 2565c6c1daeSBarry Smith 2575c6c1daeSBarry Smith Use PETSC_VIEWER_SOCKET_() or PetscViewerSocketOpen() to communicator with an interactive MATLAB session. 2585c6c1daeSBarry Smith 2595c6c1daeSBarry Smith .seealso: PETSC_VIEWER_MATLAB_WORLD, PETSC_VIEWER_MATLAB_SELF, PetscViewerMatlabOpen(), PetscViewerCreate(), 2605c6c1daeSBarry Smith PetscViewerDestroy() 2615c6c1daeSBarry Smith @*/ 2625c6c1daeSBarry Smith PetscViewer PETSC_VIEWER_MATLAB_(MPI_Comm comm) 2635c6c1daeSBarry Smith { 2645c6c1daeSBarry Smith PetscErrorCode ierr; 2655c6c1daeSBarry Smith PetscBool flg; 2665c6c1daeSBarry Smith PetscViewer viewer; 2675c6c1daeSBarry Smith char fname[PETSC_MAX_PATH_LEN]; 2685c6c1daeSBarry Smith MPI_Comm ncomm; 2695c6c1daeSBarry Smith 2705c6c1daeSBarry Smith PetscFunctionBegin; 271efca3c55SSatish Balay ierr = PetscCommDuplicate(comm,&ncomm,NULL);if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(0);} 2725c6c1daeSBarry Smith if (Petsc_Viewer_Matlab_keyval == MPI_KEYVAL_INVALID) { 27312801b39SBarry Smith ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Matlab_keyval,0); 2742cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);} 2755c6c1daeSBarry Smith } 27647435625SJed Brown ierr = MPI_Comm_get_attr(ncomm,Petsc_Viewer_Matlab_keyval,(void**)&viewer,(int*)&flg); 2772cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);} 2785c6c1daeSBarry Smith if (!flg) { /* PetscViewer not yet created */ 2795c6c1daeSBarry Smith ierr = PetscOptionsGetenv(ncomm,"PETSC_VIEWER_MATLAB_FILENAME",fname,PETSC_MAX_PATH_LEN,&flg); 2802cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);} 2815c6c1daeSBarry Smith if (!flg) { 2825c6c1daeSBarry Smith ierr = PetscStrcpy(fname,"matlaboutput.mat"); 2832cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);} 2845c6c1daeSBarry Smith } 2855c6c1daeSBarry Smith ierr = PetscViewerMatlabOpen(ncomm,fname,FILE_MODE_WRITE,&viewer); 2862cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);} 2875c6c1daeSBarry Smith ierr = PetscObjectRegisterDestroy((PetscObject)viewer); 2882cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);} 28947435625SJed Brown ierr = MPI_Comm_set_attr(ncomm,Petsc_Viewer_Matlab_keyval,(void*)viewer); 2902cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);} 2915c6c1daeSBarry Smith } 2925c6c1daeSBarry Smith ierr = PetscCommDestroy(&ncomm); 2932cb5e1ccSBarry Smith if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_MATLAB_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);} 2945c6c1daeSBarry Smith PetscFunctionReturn(viewer); 2955c6c1daeSBarry Smith } 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith 2985c6c1daeSBarry Smith 2995c6c1daeSBarry Smith 3005c6c1daeSBarry Smith 301