----- Original Message ----- > Hello everyone, > > I am trying to create a sparse matrix A, which depends on a parallel > vector v. For example, my function looks like this: Mat > myfun(MPI_Comm comm, Vec v, other parameters). When I set the value > A(i,j) = v[k], v[k] may not be obtained by VecGetValues since that > operation can only get values on the same processor. I am thinking > > 1) create v as an array and pass this array into myfun. > 2) create another vector v2, which is a full copy of parallel v > through VecScatter.
Do you need all the vector elements on each processor to set the matrix values or just a subset of them? ' If you need all the vector elements then you can use VecScattertoAll http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Vec/VecScatterCreateToAll.html If you only need a subset then you could create v as a ghosted vector. See the example http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/src/vec/vec/examples/tutorials/ex9.c.html > 3) when I first create the initial vec v, using > VecCreate(PETSC_COMM_SELF,v) or VecCreateSeq. Does this guarantee that > all the processors creating matrix A have all the components of vector > v? > > I think 1) and 2) are going to work, but not sure about option 3). I > have no idea which would have better performance. Can you give me some > suggestions on how to handle this problem? Thanks. > > Another quick question, what is the difference between > PetscViewerSetFormat and PetscViewerPushFormat? > > Best, > Xiangdong
