[petsc-users] Error while reading/writing petsc file

Nelson David Rufus nelrufus at umich.edu
Mon Mar 5 12:52:40 CST 2018


Hello,

I am writing a vector on a petsc binary file and subsequently reading the
same in another part of the code.
This works well for smaller vector sizes but fails for a large vector
(vectorsize=2048000000; PetscScalar=PetscComplex). For a large vector, when
the read vector is probed for values, I seems to me that it is populated
with uninitialized values.

This size is close to the int32 limit (2^31 -1) but does not really breach
it. Hence i am nt using 64 bit integer. Can you please help me figure out
what might be going wrong here.? I'm appending with this mail snippets of
the code which read wnd write the petsc file.
//*********************************************************************************************************************************************
//
// Snippet which writes v (a vector constructed using global size) to  the
file. Note that this snippet is part of a parallel code
//
      PetscViewer viewer;
      error =
PetscViewerBinaryOpen(PETSC_COMM_WORLD,fileName.c_str(),FILE_MODE_WRITE,&viewer);
      checkPETScError(error, "unbale to open binary file");

      error = VecView(v,viewer);
      checkPETScError(error, "unable to use VecView");

      error = PetscViewerDestroy(&viewer);
      checkPETScError(error,"unable to destry viewer");

      //
      // cleanup
      //
      error = VecDestroy(&v);
      checkPETScError(error,"unable to destroy vector");


      error = PetscOptionsSetValue(NULL,"-viewer_binary_mpiio","");
      checkPETScError(error, "error in PetscOptionsSetValue");

//*******************************************************************************************************************************
//
// Snippet which reads v (this is part of a serial code)
//
PetscViewer viewer;
  error =
PetscViewerBinaryOpen(PETSC_COMM_WORLD,fileName.c_str(),FILE_MODE_READ,&viewer);
  checkPETScError(error, "unbale to open binary file");

  error = VecLoad(v,viewer);
  checkPETScError(error, "unable to use VecView");

  error = PetscViewerDestroy(&viewer);
  checkPETScError(error,"unable to destry viewer");

   //
  // write to console
  //
  //error = VecView(v,PETSC_VIEWER_STDOUT_WORLD);
  //checkPETScError(error, "unable to write to console");

  //
  // copy petsc vec to stl vector
  //
  std::vector<std::complex<double> > dummy(vecSize);
  PetscScalar *pointerX;
  VecGetArray(v, &pointerX);
  std::copy(&(pointerX[0]),&(pointerX[vecSize]),dummy.begin());
  VecRestoreArray(v, &pointerX);

  // subsequently dummy is written to an stl vector.
//*********************************************************************************************************************************************


Thanks,
-
Nelson David Rufus
PhD Student
Computational Materials Physics Group
Mechanical Engineering
University of Michigan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180305/a65c22b0/attachment.html>


More information about the petsc-users mailing list