Thanks! It works. Wim
On Wed, Aug 30, 2017 at 3:21 PM, Stefano Zampini <[email protected]> wrote: > sorry, forgot the last line of pointers swapping > Vec tmp = Z_Vec[pipe_l]; > for(int i = pipe_l; i>0; i--){ > Z_Vec[i] = Z_Vec[i-1]; > } > Z_Vec[0] = tmp; > > 2017-08-30 16:19 GMT+03:00 Wim Vanroose <[email protected]>: > >> I've tried that in an earlier version. But it does not work. Then my >> MatMult complains that >> >> [0]PETSC ERROR: Object is in wrong state >> >> [0]PETSC ERROR: x and y must be different vectors >> >> Because Vec[1] is then referring to Vec[0] where I am going to store the >> result of the MatMult. >> Also later on there are some AXPY that are complaining that that x and y >> are the same vector. >> >> Wim >> >> >> On Wed, Aug 30, 2017 at 2:55 PM, Stefano Zampini < >> [email protected]> wrote: >> >>> 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 <[email protected]>: >>> >>>> 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 >>> >> >> > > > -- > Stefano >
