4
$\begingroup$

I'm working with someone else's code that uses PETSc 3.0.0-p9.

They have a vector at the end of the computation that is distributed among a number of different processors, and I want to output that vector to a file.

Unfortunately, the way they do it doesn't appear to work. Is there an easy way to write (the real part) of a vector to a file in PETSc?

The current way it is done is to write the PETScVector to a C++ STL vector (on all processors), and then write the vector out to a file (on one processor).

This approach doesn't work, because only the values on that processor are written to file.

Is there a "standard PETSc" way of outputting a vector to a file?

Thanks!

$\endgroup$
  • $\begingroup$ Could you provide more details about what you have tried before, and the error messages that it produced? $\endgroup$ – Paul Jan 31 '12 at 19:21
  • $\begingroup$ Hopefully this is better. $\endgroup$ – Andrew Spott Jan 31 '12 at 19:28
5
$\begingroup$

Normally you can use VecView() for everything. You probably want to open the PetscViewer using PetscViewerBinaryOpen, in which case VecView() will write efficiently in parallel to the binary file.. You can read it from a PETSc program using VecLoad(), from MATLAB/Octave with PetscBinaryRead() (add $PETSC_DIR/bin/matlab/ to your path), or from Python (scripts in $PETSC_DIR/bin/pythonscripts/).

If you are concerned about ordering or something else, please clarify the question.

$\endgroup$
  • $\begingroup$ This is right, but now I would recommend using the HDF5 output if you want to process the data with other tools. $\endgroup$ – Matt Knepley Sep 16 '15 at 11:14
0
$\begingroup$

I use the command ‘VecGather’ to gather all the vectors to the root node, then perform the output on the root node.

I think the other way is to write every local result by every node in the cluster into the NFS share system. Some visualization software such as Visit can support the parallel file format.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.