Scattering DA Vectors

Victor Sofonea sofonea at acad-tim.tm.edu.ro
Wed Jan 24 00:11:39 CST 2007


Hi,

I'm using two-dimensional DAs in my code to create global and local
vectors

DA da;
Vec nloc, lnloc, zero_nloc;
PetscInt imax = 102, jmax=3;

DACreate2d(PETSC_COMM_WORLD, DA_YPERIODIC, DA_STENCIL_BOX,
           imax,jmax,PETSC_DECIDE,PETSC_DECIDE,
           1,1,PETSC_NULL,PETSC_NULL,&da);

ierr = DACreateLocalVector(da,&lnloc);              CHKERRQ(ierr);

ierr = DACreateGlobalVector(da,&nloc);              CHKERRQ(ierr);


and at some moment I need copy all values of the global vector nloc
on the zeroth processor. For this purpose, I tried to create a scatter
context and use VecScatterBegin...End:

ierr = VecScatterCreateToZero(nloc,&zero_ctx,&zero_nloc);CHKERRQ(ierr);

ierr = VecScatterBegin(nloc,zero_nloc,INSERT_VALUES,SCATTER_FORWARD,zero_ctx);
CHKERRQ(ierr);
ierr = VecScatterEnd(nloc,zero_nloc,INSERT_VALUES,SCATTER_FORWARD,zero_ctx);
CHKERRQ(ierr);

This scatter procedure does not work for global vectors created using
DACreateGlobalVector(...) since (on processor 0, when using 2
processors, but I plan to use more processors in the future):

PetscReal **aznloc

ierr = DAVecGetArray(da,zero_nloc,&aznloc);        CHKERRQ(ierr);

gives the error

+++++++++++++ BEGIN ERROR MESSAGE

[0]PETSC ERROR: --------------------- Error Message
------------------------------------
[0]PETSC ERROR: Arguments are incompatible!
[0]PETSC ERROR: Vector local size 306 is not compatible with DA local
sizes 153 260
!
[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: Petsc Release Version 2.3.2, Patch 7, Fri Dec  1 11:22:44
CST 2006 HG revision: 4fc87ad4c9d9855d212e1fa6135ed04b299cdc92
[0]PETSC ERROR: See docs/changes/index.html for recent updates.
[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
[0]PETSC ERROR: See docs/index.html for manual pages.
[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: ./dachannel on a freebsd named
smoluchowski.acad-tim.tm.edu.ro by sofonea Wed Jan 24 08:08:34 2007
[0]PETSC ERROR: Libraries linked from
/usr/local/petsc-2.3.2-p7-mpi//lib/freebsd
[0]PETSC ERROR: Configure run at Tue Jan  2 18:08:24 2007
[0]PETSC ERROR: Configure options --with-deb[1]PETSC ERROR:
--------------------- Error Message ------------------------------------
[1]PETSC ERROR: Arguments are incompatible!
[1]PETSC ERROR: Vector local size 0 is not compatible with DA local sizes
153 260
!
[1]PETSC ERROR:
------------------------------------------------------------------------
[1]PETSC ERROR: Petsc Release Version 2.3.2, Patch 7, Fri Dec  1 11:22:44
CST 2006 HG revision: 4fc87ad4c9d9855d212e1fa6135ed04b299cdc92
[1]PETSC ERROR: See docs/changes/index.html for recent updates.
[1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
[1]PETSC ERROR: See docs/index.html for manual pages.
[1]PETSC ERROR:
------------------------------------------------------------------------
[1]PETSC ERROR: ./dachannel on a freebsd named
smoluchowski.acad-tim.tm.edu.ro by sofonea Wed Jan 24 08:08:34 2007
[1]PETSC ERROR: Libraries linked from
/usr/local/petsc-2.3.2-p7-mpi//lib/freebsd
[1]PETSC ERROR: Configure run at Tue Jan  2 18:08:24 2007
[1]PETSC ERROR: Configure options --with-debugging=0ugging=0
--download-f-blas-lapack=ifneeded --download-mpich=ifneeded
--with-shared=0
[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: DAVecGetArray() line 50 in src/dm/da/src/dagetarray.c
[0]PETSC ERROR: User provided function() line 343 in dainout.c
[0]PETSC ERROR: User provided function() line 1130 in damain.c
 --download-f-blas-lapack=ifneeded --download-mpich=ifneeded
--with-shared=0
[1]PETSC ERROR:
------------------------------------------------------------------------
[1]PETSC ERROR: DAVecGetArray() line 50 in src/dm/da/src/dagetarray.c
[1]PETSC ERROR: User provided function() line 343 in dainout.c
[1]PETSC ERROR: User provided function() line 1130 in damain.c

++++++++++++ END ERROR MESSAGE

I tried also

PetscReal *aznloc

ierr = VecGetArray(zero_nloc,&aznloc);        CHKERRQ(ierr);

Although this works, I need the natural ordering for further processing
the elements of aznloc, as follows:

PetscReal nn[imax];

for(i=0; i<imax; i++)
{
  nn[i] = 0.00
  for(i=0; j<imax; i++)
    {
      nn[i] += aznloc[j][i];
    }
}


In other words, I need aznloc to be a two-dimensional array to preserve
the same idex ranges 0...imax and 0...jmax used for the global vector
nloc).

Do you have a solution ?

Thank you,

Victor Sofonea




More information about the petsc-users mailing list