[petsc-users] VecRestoreSubVector can't change value of original vector
mailinglist
mailinglistxf at yahoo.fr
Wed Oct 2 07:59:20 CDT 2013
Hello,
I have a vector(v). I use VecRestoreSubVector to get a sub vector(subv).
I change the value of the sub vector and want to give the new value back
to v using VecRestoreSubVector, but it only works for seqential
case(mpirun -np 1 ...). This is my code. Thank you very much.
#include "petsc.h"
#include "mpi.h"
int main(int argc, char** argv){
PetscInitialize(&argc,&argv,0,0);
int commSize;
int commRank;
MPI_Comm_rank(MPI_COMM_WORLD,&commRank);
MPI_Comm_size(MPI_COMM_WORLD,&commSize);
Vec v;
VecCreateMPI(PETSC_COMM_WORLD,5,5*commSize,&v);
VecSet(v,0.0);
VecAssemblyBegin(v);
VecAssemblyEnd(v);
// is
IS is;
int index[1], Nindex = 1;
index[0] = 0;
ISCreateGeneral(PETSC_COMM_WORLD,Nindex,index,PETSC_COPY_VALUES,&is);
Vec vsub;
VecGetSubVector(v,is,&vsub);
VecSet(vsub,1);
VecAssemblyBegin(vsub);
VecAssemblyEnd(vsub);
// VecView(vsub,PETSC_VIEWER_STDOUT_WORLD);
VecRestoreSubVector(v,is,&vsub);
// VecAssemblyBegin(v);
// VecAssemblyEnd(v);
VecView(v,PETSC_VIEWER_STDOUT_WORLD);
PetscFinalize();
return 0;
}
Regards,
fxing
More information about the petsc-users
mailing list