Actual source code: ex138.c

petsc-3.14.6 2021-03-30
Report Typos and Errors

  2: static char help[] = "Tests MatGetColumnNorms() for matrix read from file.";

  4: #include <petscmat.h>

  6: int main(int argc,char **args)
  7: {
  8:   Mat            A;
 10:   PetscReal      *norms;
 11:   char           file[PETSC_MAX_PATH_LEN];
 12:   PetscBool      flg;
 13:   PetscViewer    fd;
 14:   PetscInt       n;
 15:   PetscMPIInt    rank;

 17:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 18:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 19:   PetscOptionsGetString(NULL,NULL,"-f",file,sizeof(file),&flg);
 20:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f option");
 21:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);
 22:   MatCreate(PETSC_COMM_WORLD,&A);
 23:   MatSetFromOptions(A);
 24:   MatLoad(A,fd);
 25:   PetscViewerDestroy(&fd);

 27:   MatGetSize(A,NULL,&n);
 28:   PetscMalloc1(n,&norms);

 30:   MatGetColumnNorms(A,NORM_2,norms);
 31:   if (!rank) {
 32:     PetscPrintf(PETSC_COMM_SELF,"NORM_2:\n");
 33:     PetscRealView(n,norms,PETSC_VIEWER_STDOUT_SELF);
 34:   }

 36:   MatGetColumnNorms(A,NORM_1,norms);
 37:   if (!rank) {
 38:     PetscPrintf(PETSC_COMM_SELF,"NORM_1:\n");
 39:     PetscRealView(n,norms,PETSC_VIEWER_STDOUT_SELF);
 40:   }

 42:   MatGetColumnNorms(A,NORM_INFINITY,norms);
 43:   if (!rank) {
 44:     PetscPrintf(PETSC_COMM_SELF,"NORM_INFINITY:\n");
 45:     PetscRealView(n,norms,PETSC_VIEWER_STDOUT_SELF);
 46:   }

 48:   PetscFree(norms);
 49:   MatDestroy(&A);
 50:   PetscFinalize();
 51:   return ierr;
 52: }

 54: /*TEST

 56:    test:
 57:       suffix: 1
 58:       nsize: 2
 59:       requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
 60:       args: -f ${DATAFILESPATH}/matrices/small -mat_type aij
 61:       output_file: output/ex138.out

 63:    test:
 64:       suffix: 2
 65:       nsize: 2
 66:       requires: datafilespath !complex double !define(PETSC_USE_64BIT_INDICES)
 67:       args: -f ${DATAFILESPATH}/matrices/small -mat_type baij -matload_block_size {{2 3}}
 68:       output_file: output/ex138.out

 70: TEST*/