Actual source code: ex2.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: static char help[] = "Tests application ordering.\n\n";

  4: #include <petscsys.h>
  5: #include <petscao.h>
  6: #include <petscviewer.h>

 10: int main(int argc,char **argv)
 11: {
 13:   PetscMPIInt    rank,size;
 14:   PetscInt       n,*ispetsc,*isapp,start,N,i;
 15:   AO             ao;

 17:   PetscInitialize(&argc,&argv,(char*)0,help);
 18:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
 19:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank); n = rank + 2;
 20:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 22:   /* create the orderings */
 23:   PetscMalloc2(n,&ispetsc,n,&isapp);

 25:   MPI_Scan(&n,&start,1,MPIU_INT,MPI_SUM,PETSC_COMM_WORLD);
 26:   MPI_Allreduce(&n,&N,1,MPIU_INT,MPI_SUM,PETSC_COMM_WORLD);
 27:   start -= n;

 29:   for (i=0; i<n; i++) {
 30:     ispetsc[i] = start + i;
 31:     isapp[i]   = N - start - i - 1;
 32:   }

 34:   /* create the application ordering */
 35:   AOCreateBasic(PETSC_COMM_WORLD,n,isapp,ispetsc,&ao);

 37:   AOView(ao,PETSC_VIEWER_STDOUT_WORLD);

 39:   /* check the mapping */
 40:   AOPetscToApplication(ao,n,ispetsc);
 41:   for (i=0; i<n; i++) {
 42:     if (ispetsc[i] != isapp[i]) {
 43:       PetscPrintf(PETSC_COMM_WORLD,"[%d] Problem with mapping %D to %D\n",rank,i,ispetsc[i]);
 44:     }
 45:   }
 46:   PetscFree2(ispetsc,isapp);

 48:   AODestroy(&ao);
 49:   PetscFinalize();
 50:   return 0;
 51: }