[petsc-users] DMDAGetElements returns unexpected values
    Mikhail Artemyev 
    artemiev.mikhail at gmail.com
       
    Wed Jul 15 10:46:46 CDT 2015
    
    
  
Dear all,
Here is a minimal working example that I'm testing:
#include "petscsys.h"
#include "petscdmda.h"
int main(int argc, char **argv)
{
   PetscInitialize(&argc, &argv, 0, 0);
   PetscInt rank;
   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
   DM da;
   DMDACreate1d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, -9, 1, 0, NULL, &da);
   PetscInt n_local_cells, n_cell_nodes;
   const PetscInt *local_indices;
   DMDAGetElements(da, &n_local_cells, &n_cell_nodes, &local_indices);
   PetscSynchronizedPrintf(PETSC_COMM_WORLD,
                           "rank %d n_local_cells %d n_cell_nodes %d\n",
                           rank, n_local_cells, n_cell_nodes);
   PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT);
   DMDARestoreElements(da, &n_local_cells, &n_cell_nodes, &local_indices);
   PetscFinalize();
   return 0;
}
I believe it creates a 1D DM object, and outputs the number of local 
cells assigned to each process.
Here is what I have as an output:
$ mpirun -np 1 ./test
rank 0 n_local_cells 8 n_cell_nodes 2     // OK
$ mpirun -np 2 ./test
rank 0 n_local_cells 4 n_cell_nodes 2     // OK
rank 1 n_local_cells 3 n_cell_nodes 2     // I expected 4 local cells here
$ mpirun -np 4 ./test
rank 0 n_local_cells 2 n_cell_nodes 2     // OK
rank 1 n_local_cells 1 n_cell_nodes 2     // I expected 2 local cells here
rank 2 n_local_cells 1 n_cell_nodes 2     // I expected 2 local cells here
rank 3 n_local_cells 1 n_cell_nodes 2     // I expected 2 local cells here
What am I missing?
Thank you.
Best,
Mikhail
    
    
More information about the petsc-users
mailing list