[petsc-users] Indexing/using a 3D DMDA as a 1D vector

Matthew Knepley knepley at gmail.com
Wed Sep 12 09:56:29 CDT 2018


On Wed, Sep 12, 2018 at 9:31 AM Phil Tooley <phil.tooley at sheffield.ac.uk>
wrote:

> I will preface this by saying I am new to PETSc and am still trying to
> get my head around all of the layout mapping that is done.  That means I
> may well have fundamentally misunderstood something, but hopefully
> someone will be able to to put me right.
>
> In my application I have some 3D pixel data which I want to manipulate
> using finite difference methods and then transform by viewing as a 1-D
> vector and multiplying by a large sparse matrix operator.
>
> I would assume that the correct way to do this is by creating a DMDA to
> hold the image data and ghosting appropriately to apply my finite
> difference operations.  Then I had hoped that I could use some form of
> application ordering to allow viewing the data as a vector that can be
> multiplied with my operator matrix.  This is where I have come unstuck,
> I may just be missing something obivous but I can't figure out how to do
> this.  Can anyone point me in the correct direction please?
>

Okay, the initial intuition is correct. You can use a DMDA to organize your
pixel data.
Note that DMDA only holds metadata about the Cartesian mesh. It never holds
data.
All data is held in Vec objects. So when you load data, it is loaded into a
Vec. Thus
you automatically have a 1D representation.

It might not be the 1D representation you are looking for. In a running
program, we
organize the data so it is lexicographic _per subdomain_. However, lots of
users want
it organized lexicographically for the entire domain. Thus we have a
convenience feature,
that when you output or input a vector, we convert to the "natural"
ordering. You can also
get the natural ordering yourself using a GlobalToNatural scatter.

Feel free to mail with more questions.

  Thanks,

     Matt


> Many Thanks
>
> --
> Phil Tooley
> Research Software Engineering
> University of Sheffield
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180912/9a0852f3/attachment.html>


More information about the petsc-users mailing list