<div dir="ltr">Hello,<div><br></div><div>Somewhere in my code, I need to take spatial average of a global vector created by 3D DA context and store it into another global vector. </div><div>It is like X3D(streamwise,normalwise,spanwise) --> Y3D(0,normalwise,0). It is very easy to do serially in Fortran, for example,</div><div><br></div><div>         tot = (ni-2)*(nk-2)</div><div><br></div><div><div>         do k= 2,nkm1</div><div>         do j= 2,njm1</div><div>         do i= 2,nim1</div><div><br></div><div>            su(2,j,2)=su(2,j,2)+cs(i,j,k)/float(tot)<br></div><div><br></div><div>         end do</div><div>         end do</div><div>         end do</div></div><div><br></div><div>What could be the most efficient way of doing this in PETSC? </div><div><br></div><div>or Is it possible to do as follows using ADD_VALUES?</div><div><br></div><div>mxmz = mx*mz</div><div><br></div><div><div>do k=zs,zs+zm-1</div><div>        do j=ys,ys+ym-1</div><div>                do i=xs,xs+xm-1</div><div><br></div><div>                 row  = i   - gxs + (j - gys)*gxm  + (k - gzs)*gxm*gym + 1</div></div><div>                 rowj = xs - gxs + (j - gys)*gxm  + (zs - gzs)*gxm*gym + 1<br></div><div>                 </div><div>                scaX3DAVE(idX3DAVE+<b>rowj</b>) =  scaX3DAVE(idX3DAVE+<b>rowj</b>) +  scaX3D(idX3D+<b>row</b>)/float(mx*mz)</div><div><br></div><div><div>                end do</div><div>        end do</div><div>end do</div></div><div><br></div><div>call VecRestoreArray()</div><div>call DALocaltoGlobal(da,localX3DAVE,<b>ADD_VALUES</b>,X3DAVE,ierr)</div><div><br></div><div><br></div><div>Thanks.</div><div><br></div><div>IY</div></div>