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

Stefano Zampini stefano.zampini at gmail.com
Wed Aug 30 07:55:29 CDT 2017


if you don't use KSPCreateVecs, but just a sequence of VecDuplicates, then
you can swap pointers

Vec tmp = Z_Vec[pipe_l];
for(int i = pipe_l;  i>0; i--){
   Z_Vec[i] = Z_Vec[i-1];
   }

if you still want to use KSPCreateVecs, you need to keep track of what was
the first vector of the sequence at the time of creation, because its
address in memory points to the malloced memory for all the Vec pointers.



2017-08-30 15:45 GMT+03:00 Wim Vanroose <wim at vanroo.se>:

> 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
>
>
>
>


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


More information about the petsc-dev mailing list