<div dir="ltr">if you don't use KSPCreateVecs, but just a sequence of VecDuplicates, then you can swap pointers<div><br><div><div>Vec tmp = Z_Vec[pipe_l];</div><div>for(int i = pipe_l;  i>0; i--){</div><div>   Z_Vec[i] = Z_Vec[i-1];</div><div>   }<br></div></div></div><div><br></div><div>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.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-08-30 15:45 GMT+03:00 Wim Vanroose <span dir="ltr"><<a href="mailto:wim@vanroo.se" target="_blank">wim@vanroo.se</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear Petsc Developers, <div><br></div><div>We are writing a pipelined CG with deep pipelines.    For this algorithm I need to </div><div>store   "pipe_l +1"  auxiliary variables  Z_Vec.    I create these vectors as follows:</div><div><br></div><div><div> Vec *Z_VEC;</div></div><div><div> ierr = KSPCreateVecs(ksp,pipe_l+1,&Z_<wbr>VEC,0,NULL);CHKERRQ(ierr);</div></div><div><br></div><div><br></div><div>Then we have a loop of iterations.   However at some point I have to drop the last </div><div>the auxiliary vector and shift the remaining vectors one position, and replace the first vector with the result of a matvec. </div><div><br></div><div>This is in the current prototype implemented as </div><div><br></div><div>      for(int i = pipe_l;  i>0; i--){</div><div>        VecCopy( Z_VEC[i-1], Z_VEC[i] );</div><div>      }</div><div><br></div><div>      ierr = MatMult(A, Z_VEC[1], Z_VEC[0]);CHKERRQ(ierr);</div><div><br></div><div>It looks very inefficient to me to copy the vector, if we only want to shift the data. </div><div><br></div><div>Do you have examples code where this is done more efficiently?  Or is this already a good way to do it?</div><div>Do you have suggestions?  </div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>Wim</div><div> </div><div><br></div><div><br></div></font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Stefano</div>
</div>