Actual source code: ex55.c

  1: /*$Id: ex55.c,v 1.18 2001/04/10 19:35:44 bsmith Exp $*/

  3: static char help[] = "Tests converting a matrix to another format with MatConvert().\n\n";

 5:  #include petscmat.h

  9: int main(int argc,char **args)
 10: {
 11:   Mat         C,A,B,D;
 12:   int         ierr,i,j,ntypes = 2,size;
 13:   MatType     type[9] = {MATSEQAIJ,MATSEQBAIJ,MATMPIROWBS};
 14:   char        file[128];
 15:   Vec         v;
 16:   PetscViewer fd;
 17:   PetscTruth  equal;

 19:   PetscInitialize(&argc,&args,(char *)0,help);
 20:   PetscOptionsGetString(PETSC_NULL,"-f",file,127,PETSC_NULL);
 21:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 22:   if (size > 1) ntypes = 5;

 24:   /* 
 25:      Open binary file.  Note that we use PETSC_BINARY_RDONLY to indicate
 26:      reading from this file.
 27:   */
 28:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,PETSC_BINARY_RDONLY,&fd);

 30:   /*
 31:      Load the matrix and vector; then destroy the viewer.
 32:   */
 33:   MatLoad(fd,MATMPIAIJ,&C);
 34:   VecLoad(fd,&v);
 35:   PetscViewerDestroy(fd);

 37: 
 38:   for (i=0; i<ntypes; i++) {
 39:     MatConvert(C,type[i],&A);
 40:     for (j=0; j<ntypes; j++) {
 41:       MatConvert(A,type[j],&B);
 42:       MatConvert(B,type[i],&D);
 43:       MatEqual(A,D,&equal);
 44:       if (!equal){
 45:         MatView(A,PETSC_VIEWER_STDOUT_WORLD);
 46:         MatView(B,PETSC_VIEWER_STDOUT_WORLD);
 47:         MatView(D,PETSC_VIEWER_STDOUT_WORLD);
 48:         SETERRQ2(1,"Error in conversion from %s to %s",type[i],type[j]);
 49:       }
 50:       MatDestroy(B);
 51:       MatDestroy(D);
 52:     }
 53:     MatDestroy(A);
 54:   }


 57:   MatDestroy(C);
 58:   VecDestroy(v);

 60:   PetscFinalize();
 61:   return 0;
 62: }