[petsc-users] Read in sequential, solve in parallel

Moinier, Pierre (UK) Pierre.Moinier at baesystems.com
Wed Sep 29 04:46:14 CDT 2010


Dear Developers,
 
I have a Matrix and a Right Hand Side (RHS) in an ASCII format stored in
2 different files. I have written the code that reads the data and solve
the system in sequential. I would like to solve the same problem in
parallel. I read the FAQ section that says:
 
Never read or write in parallel an ASCII matrix file, instead for
reading: read in sequentially then save the matrix with the binary
viewer PetscBinaryViewerOpen() and load the matrix in parallel with
MatLoad().
 
So far, I did not manage to implement this. Could any one help me?
 
My matrix is in the Matrix Market format. I have put below my current
implementation.
 
Kind regards,
 
    -Pierre.
 
 
 
  PetscInitialize(&argc,&argv,(char *)0,help);
  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
  if (size != 1) SETERRQ(1,"This is a uniprocessor example only!");
 
  /* Read in matrix */
  ierr =
PetscOptionsGetString(PETSC_NULL,"-fin",filein,127,PETSC_NULL);CHKERRQ(i
err);
  ierr = PetscFOpen(PETSC_COMM_SELF,filein,"r",&file);CHKERRQ(ierr);
  
 
  /* find out size of sparse matrix .... */
  fgets(buf,PETSC_MAX_PATH_LEN-1,file);
  printf("%s",buf);
  fscanf(file,"%d %d %d\n",&M,&N,&nz);
 
  ierr = PetscPrintf(PETSC_COMM_SELF,"M: %d, N: %d, nz:
%d\n",M,N,nz);CHKERRQ(ierr);
 
  MatCreate(PETSC_COMM_WORLD,&A);
  MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,M,N);
  MatSetType(A,MATAIJ);
  MatSetUp(A);
 
  for (i=0; i<nz; i++){
    fscanf(file,"%d %d %le\n",&I,&J,(double*)&val);
    I = I-1; J = J-1;
    ierr = MatSetValues(A,1,&I,1,&J,&val,INSERT_VALUES);CHKERRQ(ierr);
  }
 
  ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
 
  if (file !=stdin) fclose(file);
  ierr = PetscPrintf(PETSC_COMM_SELF,"Reading matrix
completes.\n");CHKERRQ(ierr);


********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20100929/07ac4b3b/attachment.htm>


More information about the petsc-users mailing list