[petsc-users] Using PETSc with a custom data structure
Jed Brown
jed at 59A2.org
Sat May 7 11:22:35 CDT 2011
On Sat, May 7, 2011 at 17:46, Milan Mitrovic <milanm at student.ethz.ch> wrote:
> As far as I've seen the solvers were made to work with the petsc
> vector data type, but I need to use it with a different data structure
> that is already scattered onto different processors. Is there a way to
> create a custom version of petsc vector that would just wrap around
> the existing data? Something similar to how sundials provides a way to
> wrap custom data types.
>
> If there is a way to do this cleanly the wrappers could get included
> into ppm, so I thought that I should ask what the best way of doing
> this would be.
>
You absolutely can, wrap your existing data, but let's discuss your needs
first.
How is the existing data stored? If it is in a contiguous array, then you
can use VecCreateMPIWithArray or VecCreateGhostWithArray or VecPlaceArray as
appropriate to have PETSc use your data structures without a copy.
If it is not in a contiguous array, then you can essentially write your own
(partial) Vec implementation and PETSc will use that. However, PETSc
matrices (Mat) will not magically work with your new Vec implementation
unless you provide access to the values as a contiguous array. This will
force you to manage your own matrices and will significantly limit the
number of preconditioners you have available. Also, many Vec operations will
be much faster if you just make a copy so that they can all use a contiguous
array.
The bottom line is that if your storage format is not contiguous, then it is
very likely that end-to-end performance will be better if you make a copy,
and it will give you access to many more solver combinations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110507/9679b266/attachment.htm>
More information about the petsc-users
mailing list