[petsc-users] Data Distribution from zero-rank process

Mari Pecha pecha.mari at gmail.com
Tue Aug 12 08:53:33 CDT 2014


Good morning,

I'm Mari and I'm beginner PETSc user and I'd like to ask about tough 
problem, especially for me.
I solve problem of data-set distribution, which are saved only on 
zero-rank process, to DMDA global vector. It means that every process 
stores a appropriate  subset of data-set. I used 
DMDAGlobalToNaturalAllCreate and DMDANaturalAllToGlobalCreate function, 
and then VecScatterBegin and VecScatterEnd functions ... see please code 
below

     ...

     ierr = DMDAGlobalToNaturalAllCreate( da, &tolocalall   ); 
CHKERRQ(ierr);
     ierr = DMDANaturalAllToGlobalCreate( da, &fromlocalall ); 
CHKERRQ(ierr);

     if( rank == 0  )
     {

         ierr = VecCreateSeq( PETSC_COMM_SELF, SIZE, &localall );

         ierr = VecScatterBegin( tolocalall, x, localall, ADD_VALUES, 
SCATTER_FORWARD_LOCAL ); CHKERRQ(ierr);
         ierr = VecScatterEnd(   tolocalall, x, localall, ADD_VALUES, 
SCATTER_FORWARD_LOCAL ); CHKERRQ(ierr);

         ierr = VecGetArray( x, &vlocal ); CHKERRQ(ierr);

         PetscInt s;
         VecGetSize( localall, &s );

         ierr = VecView( localall, PETSC_VIEWER_STDOUT_SELF ); CHKERRQ( 
ierr );

         //create data on zero rank process
         for ( int i = 0; i < s; i++) *vlocal++ = i;

         ierr = VecRestoreArray( localall, &vlocal ); CHKERRQ(ierr);

         ierr = VecScatterBegin(fromlocalall, localall, x, ADD_VALUES, 
SCATTER_FORWARD_LOCAL ); CHKERRQ(ierr);
         ierr = VecScatterEnd(  fromlocalall, localall, x, ADD_VALUES, 
SCATTER_FORWARD_LOCAL ); CHKERRQ(ierr);
     }

     ....

But the piece of code gets and distributes only vector-values belong to 
zero-rank process. So, I haven't any idea how can I solve my problem 
only with PETSc functions. I'd like to get all values from global vector 
to zero-rank process and put back all data-set only from zero-rank to 
global vector. Can you help me, please?

Thanks for your response
Mari


More information about the petsc-users mailing list