Actual source code: ex1.c
petsc-3.11.4 2019-09-28
2: static char help[] = "Demonstrates constructing an 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: PetscInt i,n = 5;
12: PetscInt getpetsc[] = {0,3,4},getapp[] = {2,1,9,7};
13: PetscInt getpetsc1[] = {0,3,4},getapp1[] = {2,1,9,7};
14: PetscInt getpetsc2[] = {0,3,4},getapp2[] = {2,1,9,7};
15: PetscInt getpetsc3[] = {0,3,4},getapp3[] = {2,1,9,7};
16: PetscInt getpetsc4[] = {0,3,4},getapp4[] = {2,1,9,7};
17: PetscMPIInt rank,size;
18: IS ispetsc,isapp;
19: AO ao;
20: const PetscInt *app;
22: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
23: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
24: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
25: MPI_Comm_size(PETSC_COMM_WORLD,&size);
27: /* create the index sets */
28: ISCreateStride(PETSC_COMM_WORLD,n,rank,size,&isapp);
29: ISCreateStride(PETSC_COMM_WORLD,n,n*rank,1,&ispetsc); /* natural numbering */
31: /* create the application ordering */
32: AOCreateBasicIS(isapp,ispetsc,&ao);
33: AOView(ao,PETSC_VIEWER_STDOUT_WORLD);
35: AOPetscToApplication(ao,4,getapp);
36: AOApplicationToPetsc(ao,3,getpetsc);
38: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 2,1,9,7 PetscToApplication %D %D %D %D\n",rank,getapp[0],getapp[1],getapp[2],getapp[3]);
39: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 0,3,4 ApplicationToPetsc %D %D %D\n",rank,getpetsc[0],getpetsc[1],getpetsc[2]);
40: PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
41: AODestroy(&ao);
43: /* test MemoryScalable ao */
44: /*-------------------------*/
45: PetscPrintf(PETSC_COMM_WORLD,"\nTest AOCreateMemoryScalable: \n");
46: AOCreateMemoryScalableIS(isapp,ispetsc,&ao);
47: AOView(ao,PETSC_VIEWER_STDOUT_WORLD);
49: AOPetscToApplication(ao,4,getapp1);
50: AOApplicationToPetsc(ao,3,getpetsc1);
52: /* Check accuracy */;
53: for (i=0; i<4; i++) {
54: if (getapp1[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp1 %d != getapp %d",getapp1[i],getapp[i]);
55: }
56: for (i=0; i<3; i++) {
57: if (getpetsc1[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc1 %d != getpetsc %d",getpetsc1[i],getpetsc[i]);
58: }
60: AODestroy(&ao);
62: /* test MemoryScalable ao: ispetsc = NULL */
63: /*-----------------------------------------------*/
64: PetscPrintf(PETSC_COMM_WORLD,"\nTest AOCreateMemoryScalable with ispetsc=NULL:\n");
65: AOCreateMemoryScalableIS(isapp,NULL,&ao);
67: AOView(ao,PETSC_VIEWER_STDOUT_WORLD);
69: AOPetscToApplication(ao,4,getapp2);
70: AOApplicationToPetsc(ao,3,getpetsc2);
72: /* Check accuracy */;
73: for (i=0; i<4; i++) {
74: if (getapp2[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp2 %d != getapp %d",getapp2[i],getapp[i]);
75: }
76: for (i=0; i<3; i++) {
77: if (getpetsc2[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc2 %d != getpetsc %d",getpetsc2[i],getpetsc[i]);
78: }
79: AODestroy(&ao);
81: /* test AOCreateMemoryScalable() ao: */
82: ISGetIndices(isapp,&app);
83: AOCreateMemoryScalable(PETSC_COMM_WORLD,n,app,NULL,&ao);
84: ISRestoreIndices(isapp,&app);
86: AOPetscToApplication(ao,4,getapp4);
87: AOApplicationToPetsc(ao,3,getpetsc4);
89: /* Check accuracy */;
90: for (i=0; i<4; i++) {
91: if (getapp4[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp4 %d != getapp %d",getapp4[i],getapp[i]);
92: }
93: for (i=0; i<3; i++) {
94: if (getpetsc4[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc4 %d != getpetsc %d",getpetsc4[i],getpetsc[i]);
95: }
96: AODestroy(&ao);
98: /* test general API */
99: /*------------------*/
100: PetscPrintf(PETSC_COMM_WORLD,"\nTest general API: \n");
101: AOCreate(PETSC_COMM_WORLD,&ao);
102: AOSetIS(ao,isapp,ispetsc);
103: AOSetType(ao,AOMEMORYSCALABLE);
104: AOSetFromOptions(ao);
106: /* ispetsc and isapp are nolonger used. */
107: ISDestroy(&ispetsc);
108: ISDestroy(&isapp);
110: AOPetscToApplication(ao,4,getapp3);
111: AOApplicationToPetsc(ao,3,getpetsc3);
113: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 2,1,9,7 PetscToApplication %D %D %D %D\n",rank,getapp3[0],getapp3[1],getapp3[2],getapp3[3]);
114: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 0,3,4 ApplicationToPetsc %D %D %D\n",rank,getpetsc3[0],getpetsc3[1],getpetsc3[2]);
115: PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
117: /* Check accuracy */;
118: for (i=0; i<4; i++) {
119: if (getapp3[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp3 %d != getapp %d",getapp3[i],getapp[i]);
120: }
121: for (i=0; i<3; i++) {
122: if (getpetsc3[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc3 %d != getpetsc %d",getpetsc3[i],getpetsc[i]);
123: }
125: AODestroy(&ao);
126: PetscFinalize();
127: return ierr;
128: }
134: /*TEST
136: test:
138: test:
139: suffix: 2
140: nsize: 2
142: test:
143: suffix: 3
144: nsize: 3
146: test:
147: suffix: 4
148: nsize: 3
149: args: -ao_type basic
150: output_file: output/ex1_3.out
152: TEST*/