Actual source code: ex138.c

petsc-3.3-p6 2013-02-11
  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(PETSC_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,PETSC_NULL,&n);
 30:   PetscMalloc(n*sizeof(PetscReal),&norms);
 31:   MatGetColumnNorms(A,NORM_2,norms);
 32:   if (!rank) {
 33:     PetscRealView(n,norms,PETSC_VIEWER_STDOUT_SELF);
 34:   }

 36:   PetscFree(norms);
 37:   MatDestroy(&A);
 38:   PetscFinalize();
 39:   return 0;
 40: }