2
$\begingroup$

In one of my PETSc programs, I need a processor to access values from another processor.

So in the PETSc FAQ's this issue has been briefly addressed here. To create a local vector, I tried this

Vec local;
ierr = VecCreateSeq(PETSC_COMM_WORLD,10,&local);CHKERRQ(ierr);

where 10 is the size of the local vector I wish to create. But running with 2 processors gives me an error

[0]PETSC ERROR: --------------------- Error Message ------------------------------------
[0]PETSC ERROR: Invalid argument!
[0]PETSC ERROR: Cannot create VECSEQ on more than one process!
[0]PETSC ERROR: ------------------------------------------------------------------------

So to be more precise, I would like to write a toy code where I want to add all elements from a big vector v which is spread across n processors.

I would like to do this by gathering all elements from v onto a vector local to Process 0 and add them all up.

Also more generally how would Process 0 get elements from any specific processor say processor i

$\endgroup$

1 Answer 1

2
$\begingroup$

PETSC_COMM_WORLD is a global communicator. Use PETSC_COMM_SELF to create a sequential object.

Use VecScatterCreateToZero for gathering to rank 0. (Obviously this is not memory scalable, so try not to do this in a real application.)

Use VecScatter for arbitrary (often sparse) collective vector distributions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.