[petsc-users] scattering strategies

Jed Brown jedbrown at mcs.anl.gov
Mon Oct 17 15:22:06 CDT 2011


On Mon, Oct 17, 2011 at 15:17, Wienand Drenth <w.drenth at gmail.com> wrote:

> I have a question regarding the utilization of the VecScatter routines to
> collect and distribute data from all processors to one, and vice versa. This
> in relation to file I/O. The setting is roughly as follows:
>
> At a certain stage in my computation, I have computed in parallel some
> results. Let these results be in an array X (X is a native C or Fortran
> array, not a Petsc vector. X might be multidimensional as well). The Xs of
> all processors together constitute my global result, and I would like to
> write it to disk. However, X itself is of course only part of the total. So
> I need to grab from all processors the pieces of X into one single
> structure.
> Furthermore, the X's are in a Petsc ordering (1 ... n for processor 1, n+1
> .... n2 for processor 2, etc) which does not reflect the ordering defined by
> the user. So before writing I need to permute the values of X accordingly.
>

Simple solution:

Make a DMDA to represent your multi-dimensional layout, put your array
values into the Vec you get from the DM, and call VecView(). It will do a
parallel write and your vector will end up in the natural ordering. You can
VecLoad() it later or read it with other software.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111017/51eb5394/attachment.htm>


More information about the petsc-users mailing list