[petsc-dev] Efficient shifting vectors one position in array of vectors.

Wim Vanroose wim at vanroo.se
Wed Aug 30 07:45:24 CDT 2017


Dear Petsc Developers,

We are writing a pipelined CG with deep pipelines.    For this algorithm I
need to
store   "pipe_l +1"  auxiliary variables  Z_Vec.    I create these vectors
as follows:

 Vec *Z_VEC;
 ierr = KSPCreateVecs(ksp,pipe_l+1,&Z_VEC,0,NULL);CHKERRQ(ierr);


Then we have a loop of iterations.   However at some point I have to drop
the last
the auxiliary vector and shift the remaining vectors one position, and
replace the first vector with the result of a matvec.

This is in the current prototype implemented as

      for(int i = pipe_l;  i>0; i--){
        VecCopy( Z_VEC[i-1], Z_VEC[i] );
      }

      ierr = MatMult(A, Z_VEC[1], Z_VEC[0]);CHKERRQ(ierr);

It looks very inefficient to me to copy the vector, if we only want to
shift the data.

Do you have examples code where this is done more efficiently?  Or is this
already a good way to do it?
Do you have suggestions?


Wim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20170830/5ba8287b/attachment.html>


More information about the petsc-dev mailing list