<div dir="ltr">Thanks!  It works. <div><br></div><div>Wim</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 30, 2017 at 3:21 PM, Stefano Zampini <span dir="ltr"><<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">sorry, forgot the last line of pointers swapping<span class=""><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>   }</div></div></span><div>Z_Vec[0] = tmp;</div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">2017-08-30 16:19 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">I've tried that in an earlier version.  But it does not work. Then my MatMult complains that <div><br></div><div><div>[0]PETSC ERROR: Object is in wrong state                                      </div><div>[0]PETSC ERROR: x and y must be different vectors </div></div><div><br></div><div>Because Vec[1] is then referring to  Vec[0] where I am going to store the result of the MatMult.</div><div>Also later on there are some AXPY that are complaining that that x and y are the same vector.  </div><span class="m_-1505260588368761511HOEnZb"><font color="#888888"><div><br></div><div>Wim</div><div><br></div></font></span></div><div class="m_-1505260588368761511HOEnZb"><div class="m_-1505260588368761511h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 30, 2017 at 2:55 PM, Stefano Zampini <span dir="ltr"><<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><span><div>for(int i = pipe_l;  i>0; i--){</div></span><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"><div><div class="m_-1505260588368761511m_-1326668370328469609h5"><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="m_-1505260588368761511m_-1326668370328469609m_554000989836285606HOEnZb"><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></div></div><span class="m_-1505260588368761511m_-1326668370328469609HOEnZb"><font color="#888888">-- <br><div class="m_-1505260588368761511m_-1326668370328469609m_554000989836285606gmail_signature" data-smartmail="gmail_signature">Stefano</div>
</font></span></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_-1505260588368761511gmail_signature" data-smartmail="gmail_signature">Stefano</div>
</font></span></div>
</blockquote></div><br></div>