[Trilinos-Users] Ghost nodes in Epetra_Vector

Heroux, Michael A maherou at sandia.gov
Sat Apr 11 14:13:20 MDT 2009


The easiest way to accomplish this is to first create the "ghosted" vector using the standard allocation techniques.  Then you can (carefully) construct the non-ghosted vector using View mode.  The only thing you need to be careful about is that standard_x is using a view of the values in ghost_x.  Therefore, if ghost_x is deleted before standard_x, the values of standard_x are no longer valid.

If you have a more complicated ghost value pattern than just one-dimensional, the approach below will work, but you need to put all of local values contiguously.

The following code should approximate what you need.

// Use your definitions of standard_map and ghost_map from below
Epetra_Vector ghost_x(ghost_map);

double * standard_x_vals = &(ghost_x[0]); // Point to address of first entry in ghost x vector
if (comm.MyPID()!=0) standard_x_vals++; // If not on the first processor, the local elements start at second entry in ghost x vector

Epetra_Vector standard_x(View, standard_map, standard_x_vals);

Epetra_Import importer(ghost_map, standard_map);

// Initialize standard_x values ...

  standard_x[0] = ...

// Update ghost values
ghost_x.Import(standard_x, importer, Insert);

// Use ghost_x to perform calculations that need local and ghost values.

I hope this helps.


On 4/8/09 10:52 AM, "Charles Boivin" <charles.boivin at mayahtt.com> wrote:


I am trying to perform a simple task, and I think I am not getting something
that should be relatively obvious. I am trying to accomodate having 'ghost
values' in a distributed vector.

Say I have a total of 6 elements in the vector, and 2 processes. A
"standard" map would be to have the elements distributed:

Process 0: 1 2 3
Process 1: 4 5 6

However, when working on element 3, access to the value at element 4 is
needed, and similarly, access to node 3 is needed when working on node 4.
So, really, the 'work' vector should be:

Process 0: 1 2 3 4
Process 1: 3 4 5 6

If I were to code this without Trilinos, I'd define vector of size 4, and
make sure the value for element 3 on process 1 is copied from process 0, and
the value of element 4 on process 1 is copied from process 1. Then whatever
operates on my values wouldn't have to know where the actual values came
from, just that they are available in the same vector, and it would only
change the values of (1,2,3) and (4,5,6) on the respective processes. On the
next cycle, the ghost values are fetched again and so on.

My question is how to accomplish the same thing elegantly using Trilinos. I
have gone through the Epetra_Import and Epetra_Export examples, and it
always seems like I need two vectors.

I created a map, say Map1, with elements (1,2,3) on one process and elements
(4,5,6) on the other process. I then created a vector, let's call it X,
based on that map. I created another map, say Map2, with elements (1,2,3,4)
on process0 and (3,4,5,6) on process1. I created vector Y based on that map.

Using an Epetra_Import object, I can then call Y.Import() to get the proper
values in vector Y. That works. It would imply that Y is now the vector that
I work on, since it has the proper size. Any changes made to Y, however, are
not automatically reflected on X; I'd then do a X.Export() using the
importer to get the new values back in X.

It seems like I now have two copies of elements 1, 2, 3 on process 0 and
elements 4, 5, 6 on process 1. Is that the case? Also, if I do have two
copies, both the import and export calls are effectively copying values
between two arrays on the same process.

Am I missing something, or is what I want to do not possible? I'd like one
vector defined, but with room for the ghost nodes, and some mechanism to
fetch the values of these ghost nodes from where they are "local". I guess I
only need a 'one-way' transfer of data, i.e. from the local value to the
ghost value. Changes to the ghost values on other processes would be
ignored. Can this be done with Epetra?

Thanks a lot,

Charles Boivin

Trilinos-Users mailing list
Trilinos-Users at software.sandia.gov

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://software.sandia.gov/pipermail/trilinos-users/attachments/20090411/a25e7115/attachment.html 

More information about the Trilinos-Users mailing list