mailinglist <[email protected]> writes:

> 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 ...). 

The interface is supposed to give you read access, but not currently
write access.  The interface doesn't say whether the values are copied.
Your subvector is not contiguous so it can't be done "in-place".  You
should probably use VecScatter for this purpose.

> 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

Attachment: pgpWQitFurjEo.pgp
Description: PGP signature

Reply via email to