[petsc-users] about VecScatter

likunt at caltech.edu likunt at caltech.edu
Sat May 10 23:40:55 CDT 2014


Dear Jed,

Thanks for your reply. Below is a more complete version of the code. I
need to loop over all the elements of aM to compute a new Vector called
result. But this process is very slow, I would appreciate if you can give
advice on speeding it up. Many thanks.

//////////////////////////////////////////////////////////////
Vec M,N,result;
DM  da;
DMDACreate1d(PETSC_COMM_WORLD,DMDA_BOUNDARY_NONE,NODE,1,1,NULL,&da);
DMCreateGlobalVector(da, &M);
//set values of M ..
VecScatterCreateToAll(M,&scatter_ctx,&N);
VecScatterBegin(scatter_ctx,M,N,INSERT_VALUES,SCATTER_FORWARD);
VecScatterEnd(scatter_ctx,M,N,INSERT_VALUES,SCATTER_FORWARD);
VecGetArray(N, &aM);

DMDAGetCorners(da, &xs, 0, 0, &xm, 0, 0);
for(i=xs; i<xs+xm; i++)
{
   val=0.0;
   for(j=0; j<NODE; j++)
   {
      val=val+aM[j];

   }
   VecSetValues(result, 1, i, val, INSERT_VALUES);
}

VecRestoreArray(N, &aM);
VecAssemblyBegin(result);
VecAssemblyEnd(result);
////////////////////////////////////////////////////////////


> likunt at caltech.edu writes:
>
>> Dear Petsc developers,
>>
>> I have a vector object M, I need all the elements of it in all the
>> processors.
>>
>> Here is a part of my code
>>
>> //////////////////////////////////////////////////////////////
>> Vec M;
>> VecScatterCreateToAll(M,&scatter_ctx,&N);
>> VecScatterBegin(scatter_ctx,M,N,INSERT_VALUES,SCATTER_FORWARD);
>> VecScatterEnd(scatter_ctx,M,N,INSERT_VALUES,SCATTER_FORWARD);
>>
>> VecGetArray(N, &aM);
>>
>> for(i=xs; i<xs+xm; i++)
>
> What are xs and xm in this setting.  What do you intend?
>
>> {
>>    //within the loop, requires all the elements of aM
>> }
>> ////////////////////////////////////////////////////////////
>>
>> but this seems not working well.
>
> The phrase "not working" should never appear unqualified in polite
> conversation.  Send steps to reproduce, what you expect, and what you
> observe.
>
>> Would you please suggest a more efficient way? Thank you.
>




More information about the petsc-users mailing list