[petsc-users] ghost points, DMs, and vector operations

gideon.simpson at gmail.com gideon.simpson at gmail.com
Sat Feb 25 00:02:37 CST 2017


Yes, when I was talking about vector operations, i.e., VecAXPY,  I was doing them on the global vectors.  So what I'm understanding from you is that the ghost points only appear after I go to the local data structure, is that correct?

-gideon

> On Feb 25, 2017, at 12:30 AM, Jed Brown <jed at jedbrown.org> wrote:
> 
> Gideon Simpson <gideon.simpson at gmail.com> writes:
> 
>> I’ve got a simple problem where I use a DM to handle a representation of a vector complex numbers, storing the real and imaginary components at each lattice point. I also have ghost points at either end, i.e.:
>> 
>> DMDACreate1d (PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED, N, 2 , 1 , NULL, &dm ) ;
>> 
>> I have a few related questions:
>> 
>> 1.  Is there a quick way to zero out the ghost points, other than to do 
>> 
>> DMGetLocalVector(dm,&local);    
>> DMGlobalToLocalBegin(dm,global,INSERT_VALUES,local);
>> DMGlobalToLocalEnd(dm,global,INSERT_VALUES,local);
>> DMDAVecGetArray(dm, local, &array);
>> DMDAGetLocalInfo(dm, &info);
>>  if(info.xs == 0){
>>    array[-1].u =0.0;
>>    array[-1].v =0.0;
>>  }
>>  if(info.xs + info.xm == info.mx){
>>    array[info.mx].u =0.0;
>>    array[info.mx].v =0.0;
>>  }
>> /* call restores after */
> 
> You can do it this way to make the loop independent of the number of
> ghost points, though you likely have to do something different if you
> have a different number of ghosts.  I.e., the simplification only works
> for toy problems; for anything real you need to write the loops.
> 
>  for (i=info.gxs; i<0; i++) array[i] = 0;
>  for (i=info.mx; i<info.gxs+info.gxm; i++) array[i] = 0;
> 
> You can also just VecZeroEntries(local) before the global-to-local.
> 
>> My point is, I don’t really need to interfere with any of the entries, just the values in those two ghost points.
>> 
>> 2.  If I take a dot product of two such vectors (associated with the dm, as arrays of complex numbers in terms of real and imaginary parts), does the dot product operate on the ghost points too, or just the “real” values?  
> 
> Local vectors are strictly local, and inner products of local vectors
> rarely makes sense.  You probably want a global vector
> (DMCreateGlobalVector), in which case the dot product is ... global.
> 
>> 3.  If I apply a VecCopy, VecAXPY, or any similar operation  to such vectors, do they also operate on the ghost points?
> 
> "ghost points" aren't special in any way.  Local vectors are serial
> vectors that contain ghost points.  Global vectors are parallel vectors
> that don't have ghost points.


More information about the petsc-users mailing list