Actual source code: ex100.c

petsc-3.9.4 2018-09-11
Report Typos and Errors

  2: static char help[] = "Tests vatious routines in MatMAIJ format.\n";

  4:  #include <petscmat.h>
  5: #define IMAX 15
  6: int main(int argc,char **args)
  7: {
  8:   Mat            A,B,MA;
  9:   PetscViewer    fd;
 10:   char           file[PETSC_MAX_PATH_LEN];
 11:   PetscInt       m,n,M,N,dof=1;
 12:   PetscMPIInt    rank,size;
 14:   PetscBool      flg;

 16:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 17:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 18:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 20: #if defined(PETSC_USE_COMPLEX)
 21:   SETERRQ(PETSC_COMM_WORLD,1,"This example does not work with complex numbers");
 22: #else

 24:   /* Load aij matrix A */
 25:   PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);
 26:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f option");
 27:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 28:   MatCreate(PETSC_COMM_WORLD,&A);
 29:   MatLoad(A,fd);
 30:   PetscViewerDestroy(&fd);

 32:   /* Get dof, then create maij matrix MA */
 33:   PetscOptionsGetInt(NULL,NULL,"-dof",&dof,NULL);
 34:   MatCreateMAIJ(A,dof,&MA);
 35:   MatGetLocalSize(MA,&m,&n);
 36:   MatGetSize(MA,&M,&N);

 38:   if (size == 1) {
 39:     MatConvert(MA,MATSEQAIJ,MAT_INITIAL_MATRIX,&B);
 40:   } else {
 41:     MatConvert(MA,MATMPIAIJ,MAT_INITIAL_MATRIX,&B);
 42:   }

 44:   /* Test MatMult() */
 45:   MatMultEqual(MA,B,10,&flg);
 46:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMul() for MAIJ matrix");
 47:   /* Test MatMultAdd() */
 48:   MatMultAddEqual(MA,B,10,&flg);
 49:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMulAdd() for MAIJ matrix");

 51:   /* Test MatMultTranspose() */
 52:   MatMultTransposeEqual(MA,B,10,&flg);
 53:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMulAdd() for MAIJ matrix");

 55:   /* Test MatMultTransposeAdd() */
 56:   MatMultTransposeAddEqual(MA,B,10,&flg);
 57:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_CONV_FAILED,"Error: MatMulTransposeAdd() for MAIJ matrix");

 59:   MatDestroy(&MA);
 60:   MatDestroy(&A);
 61:   MatDestroy(&B);
 62: #endif
 63:   PetscFinalize();
 64:   return ierr;
 65: }


 68: /*TEST

 70:    build:
 71:       requires: !complex

 73:    test:
 74:       nsize: {{1 3}}
 75:       requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
 76:       args: -f ${DATAFILESPATH}/matrices/arco1 -dof {{1 2 3 4 5 6 8 9 16}} -viewer_binary_skip_info

 78: TEST*/