[petsc-users] about VecScatter
Matthew Knepley
knepley at gmail.com
Sun May 11 06:27:25 CDT 2014
On Sat, May 10, 2014 at 11:40 PM, <likunt at caltech.edu> wrote:
> 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);
>
1) Everything below is nonsensical. The values of M are already in N.
2) Sending all values to a single process is inherently slow. It should not
be done in parallel computing
Matt
> 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.
> >
>
>
>
--
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140511/2818ea16/attachment.html>
More information about the petsc-users
mailing list