Actual source code: ex138.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: static char help[] = "Tests MatGetColumnNorms() for matrix read from file.";

  4: #include <petscmat.h>

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

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

 29:   MatGetSize(A,NULL,&n);
 30:   PetscMalloc1(n,&norms);

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

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

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

 50:   PetscFree(norms);
 51:   MatDestroy(&A);
 52:   PetscFinalize();
 53:   return 0;
 54: }