Re: [petsc-users] Better understanding VecScatter

2018-10-04 Thread Matthew Knepley
On Thu, Oct 4, 2018 at 8:56 AM Phil Tooley 
wrote:

> Hi all,
>
> I am trying to understand how to create a custom scatter from petsc
> ordering in a local vector to natural ordering in a global vector.
>
> I have a 3D DMDA and local vector containing field data and am
> calculating the x y and z gradients into their own local vectors.  I
> then need to scatter these gradients to different parts of a single
> vector so they are arranged [x_1 .. x_n y_1 .. y_n z_1 .. z_n] with
> natural ordering.  (This is for use in a custom numerical scheme that I
> have been asked to parallelise)
>

I may not be understanding correctly, but it sounds like this can be done
simply
using two DMs. The first DM is your original one holding the field values.
The
second one would set dof = dim in your new DM but everything else the same.
You can use


https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DMDA/DMDACreateCompatibleDMDA.html

Then stick the gradients in a global vector for the new DM. Then do
GlobalToNatural
for that DM.

Is this what you want?

  Thanks,

 Matt


> I can of course do this using multiple scatters but I need to perform
> this operation regularly and would like to express it as a single
> scatter operation if possible.
>
> I know I need to get the relevant AO from my DMDA and use it to
> construct appropriate ISs to build the scatter context but I am unsure
> how exactly to go about this.
>
> Can someone point me in the right direction please?
>
> Many Thanks
>
> Phil
>
> --
> 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/ 


Re: [petsc-users] Better understanding VecScatter

2018-10-04 Thread Mark Adams
So if you have three processors you would want the first processor to have
all x gradients, etc.?

You could use ISCreateGeneral:
https://www.mcs.anl.gov/petsc/petsc-current/src/dm/examples/tutorials/ex6.c.html

You need to create an integer array with the global indices that you want
to bring to your new vector locally.

On Thu, Oct 4, 2018 at 8:56 AM Phil Tooley 
wrote:

> Hi all,
>
> I am trying to understand how to create a custom scatter from petsc
> ordering in a local vector to natural ordering in a global vector.
>
> I have a 3D DMDA and local vector containing field data and am
> calculating the x y and z gradients into their own local vectors.  I
> then need to scatter these gradients to different parts of a single
> vector so they are arranged [x_1 .. x_n y_1 .. y_n z_1 .. z_n] with
> natural ordering.  (This is for use in a custom numerical scheme that I
> have been asked to parallelise)
>
> I can of course do this using multiple scatters but I need to perform
> this operation regularly and would like to express it as a single
> scatter operation if possible.
>
> I know I need to get the relevant AO from my DMDA and use it to
> construct appropriate ISs to build the scatter context but I am unsure
> how exactly to go about this.
>
> Can someone point me in the right direction please?
>
> Many Thanks
>
> Phil
>
> --
> Phil Tooley
> Research Software Engineering
> University of Sheffield
>
>


[petsc-users] Better understanding VecScatter

2018-10-04 Thread Phil Tooley
Hi all,

I am trying to understand how to create a custom scatter from petsc
ordering in a local vector to natural ordering in a global vector.

I have a 3D DMDA and local vector containing field data and am
calculating the x y and z gradients into their own local vectors.  I
then need to scatter these gradients to different parts of a single
vector so they are arranged [x_1 .. x_n y_1 .. y_n z_1 .. z_n] with
natural ordering.  (This is for use in a custom numerical scheme that I
have been asked to parallelise)

I can of course do this using multiple scatters but I need to perform
this operation regularly and would like to express it as a single
scatter operation if possible.

I know I need to get the relevant AO from my DMDA and use it to
construct appropriate ISs to build the scatter context but I am unsure
how exactly to go about this.

Can someone point me in the right direction please?

Many Thanks

Phil

-- 
Phil Tooley
Research Software Engineering
University of Sheffield