2

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

smilingbuddha
  • 645
  • 5
  • 10

1 Answers1

2

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.

Jed Brown
  • 25,650
  • 3
  • 72
  • 130