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().nn";

 5:  #include petscmat.h

  7: #undef __FUNCT__
  9: int main(int argc,char **args)
 10: {
 11:   Mat         C,A,B;
 12:   int         ierr,i,j,ntypes = 9,size;
 13:   MatType     type[9] = {MATMPIAIJ, MATMPIROWBS, MATMPIBDIAG,MATMPIDENSE,
 14:                          MATMPIBAIJ,MATSEQDENSE,MATSEQAIJ,  MATSEQBDIAG,MATSEQBAIJ};
 15:   char        file[128];
 16:   Vec         v;
 17:   PetscViewer fd;

 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[i],&B);
 42:       MatDestroy(B);
 43:     }
 44:     MatDestroy(A);
 45:   }

 47:   if (size == 1) {
 48:     PetscViewerBinaryOpen(PETSC_COMM_WORLD,"testmat",PETSC_BINARY_CREATE,&fd);
 49:     MatView(C,fd);
 50:     VecView(v,fd);
 51:     PetscViewerDestroy(fd);
 52:   }

 54:   MatDestroy(C);
 55:   VecDestroy(v);

 57:   PetscFinalize();
 58:   return 0;
 59: }