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: int main(int argc,char **args)
  8: {
  9:   Mat         C,A,B;
 10:   int         ierr,i,j,ntypes = 9,size;
 11:   MatType     type[9] = {MATMPIAIJ, MATMPIROWBS, MATMPIBDIAG,MATMPIDENSE,
 12:                          MATMPIBAIJ,MATSEQDENSE,MATSEQAIJ,  MATSEQBDIAG,MATSEQBAIJ};
 13:   char        file[128];
 14:   Vec         v;
 15:   PetscViewer fd;

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

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

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

 35: 
 36:   for (i=0; i<ntypes; i++) {
 37:     MatConvert(C,type[i],&A);
 38:     for (j=0; j<ntypes; j++) {
 39:       MatConvert(A,type[i],&B);
 40:       MatDestroy(B);
 41:     }
 42:     MatDestroy(A);
 43:   }

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

 52:   MatDestroy(C);
 53:   VecDestroy(v);

 55:   PetscFinalize();
 56:   return 0;
 57: }