Actual source code: ex2.c

petsc-3.11.4 2019-09-28
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>

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

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

 20:   /* create the orderings */
 21:   PetscMalloc2(n,&ispetsc,n,&isapp);

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

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

 32:   /* create the application ordering */
 33:   AOCreateBasic(PETSC_COMM_WORLD,n,isapp,ispetsc,&ao);
 34:   AOView(ao,PETSC_VIEWER_STDOUT_WORLD);

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

 45:   AODestroy(&ao);
 46:   PetscFinalize();
 47:   return ierr;
 48: }





 54: /*TEST

 56:    test:

 58:    test:
 59:       suffix: 2
 60:       nsize: 2

 62:    test:
 63:       suffix: 3
 64:       nsize: 3

 66: TEST*/