On Tue, 8 Jun 2010 16:04:00 +0800, "Gong Ding" <gdiso at ustc.edu> wrote: > Dear all, > I have a flux vector f and a vector t for local time step. > Both of them are global vectors. > > And I want to update the flow variable vector x in explicit way > x^(n+1) = x^(n) - t*f > > here t*f is each t's component multiply f's component. > > I searched the manual of petsc and find no useful information. > Can anyone tell me how should I do t*f efficiently?
The abstract way is to use VecPointwiseMult followed by VecAXPY, but this makes two passes and needs a temporary. The alternative is VecGetLocalSize, VecGetArray, and then roll the for loop x[i] -= t[i]*f[i]. If you do implicit solves, you will almost certainly find that these updates take a trivial amount of the total time and memory, so you may as well use whichever you find easier to read. Jed
