[petsc-users] Preprocessing Matrix Market matrices and right hand sides

Najeeb Ahmad nahmad16 at ku.edu.tr
Sat May 26 14:34:31 CDT 2018


Hi,

I am trying to load a matrix and a right hand side into Petsc from a file.
The matrix and rhs are preprocessed from matrix market format using the
following python script:

import scipy.io, PetscBinaryIO

A = scipy.io.mmread('sherman2.mtx')
PetscBinaryIO.PetscBinaryIO().writeMatSciPy(open('sherman2','w'), A)

B = scipy.io.mmread('sherman2_rhs1.mtx')
PetscBinaryIO.PetscBinaryIO().writeVec(open('sherman2_rhs','w'), B)

The binary matrix sherman2 and rhs sherman2_rhs are then being loaded into
Petsc using the following code:

 PetscErrorCode    ierr;
  PetscViewer         fd;                     /* viewer */
  Mat                  A;           /* linear system matrix */
  Vec                  b;           /* RHS */
  char              file[2][PETSC_MAX_PATH_LEN];
  PetscBool         flg, PetscPreLoad = PETSC_FALSE;
  PetscDraw           dc;
  PetscInt            size;
  PetscReal           value;

  PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
  //PetscPrintf(MPI_COMM
  ierr =
PetscOptionsGetString(PETSC_NULL,PETSC_NULL,"-f",file[0],PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
  if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate binary file with the
-f option");
  // Load Matrix A
  ierr =
PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[0],FILE_MODE_READ,&fd);CHKERRQ(ierr);

  ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
  ierr = MatSetFromOptions(A);CHKERRQ(ierr);
  ierr = MatLoad(A,fd);CHKERRQ(ierr);
  ierr = MatView(A, PETSC_VIEWER_STDOUT_WORLD);


  // Load RHS
  flg  = PETSC_FALSE;
  ierr =
PetscOptionsGetString(PETSC_NULL,PETSC_NULL,"-rhs",file[1],PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
  if (!flg) SETERRQ(PETSC_COMM_WORLD,1,"Must indicate rhs file with the
-rhs option");

  ierr = VecCreate(PETSC_COMM_WORLD, &b);CHKERRQ(ierr);
  ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
  ierr =
PetscViewerBinaryOpen(PETSC_COMM_WORLD,file[1],FILE_MODE_READ,&fd);CHKERRQ(ierr);
  ierr = VecSetFromOptions(b);CHKERRQ(ierr);

  ierr = VecLoad(b,fd);CHKERRQ(ierr);


While the matrix loads correctly, when I try to load the vector b, the
behavior of the program becomes unexpected afterwards. For instance, if I
try to view the vector, sometimes it prints and sometimes not and even when
it prints, it only shows some entries in process 0 and then stops.

AM I DOING SOMETHING WRONG IN PREPROCESSING? Or am I missing something?

Thank you



-- 
*Najeeb Ahmad*


*Research and Teaching Assistant*
*PARallel and MultiCORE Computing Laboratory (ParCoreLab) *

*Computer Science and Engineering*
*Koç University, Istanbul, Turkey*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180527/6980da52/attachment.html>


More information about the petsc-users mailing list