Actual source code: ex1.c
petsc-3.7.3 2016-08-01
2: static char help[] = "Demonstrates constructing an 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: PetscInt i,n = 5;
14: PetscInt getpetsc[] = {0,3,4},getapp[] = {2,1,9,7};
15: PetscInt getpetsc1[] = {0,3,4},getapp1[] = {2,1,9,7};
16: PetscInt getpetsc2[] = {0,3,4},getapp2[] = {2,1,9,7};
17: PetscInt getpetsc3[] = {0,3,4},getapp3[] = {2,1,9,7};
18: PetscInt getpetsc4[] = {0,3,4},getapp4[] = {2,1,9,7};
19: PetscMPIInt rank,size;
20: IS ispetsc,isapp;
21: AO ao;
22: const PetscInt *app;
24: PetscInitialize(&argc,&argv,(char*)0,help);
25: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
26: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
27: MPI_Comm_size(PETSC_COMM_WORLD,&size);
29: /* create the index sets */
30: ISCreateStride(PETSC_COMM_WORLD,n,rank,size,&isapp);
31: ISCreateStride(PETSC_COMM_WORLD,n,n*rank,1,&ispetsc); /* natural numbering */
33: /* create the application ordering */
34: AOCreateBasicIS(isapp,ispetsc,&ao);
35: AOView(ao,PETSC_VIEWER_STDOUT_WORLD);
37: AOPetscToApplication(ao,4,getapp);
38: AOApplicationToPetsc(ao,3,getpetsc);
40: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 2,1,9,7 PetscToApplication %D %D %D %D\n",
41: rank,getapp[0],getapp[1],getapp[2],getapp[3]);
42: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 0,3,4 ApplicationToPetsc %D %D %D\n",
43: rank,getpetsc[0],getpetsc[1],getpetsc[2]);
44: PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
45: AODestroy(&ao);
47: /* test MemoryScalable ao */
48: /*-------------------------*/
49: if (!rank) {
50: PetscPrintf(PETSC_COMM_SELF,"\nTest AOCreateMemoryScalable: \n");
51: }
52: AOCreateMemoryScalableIS(isapp,ispetsc,&ao);
53: AOView(ao,PETSC_VIEWER_STDOUT_WORLD);
55: AOPetscToApplication(ao,4,getapp1);
56: AOApplicationToPetsc(ao,3,getpetsc1);
58: /* Check accuracy */;
59: for (i=0; i<4; i++) {
60: if (getapp1[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp1 %d != getapp %d",getapp1[i],getapp[i]);
61: }
62: for (i=0; i<3; i++) {
63: if (getpetsc1[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc1 %d != getpetsc %d",getpetsc1[i],getpetsc[i]);
64: }
66: AODestroy(&ao);
68: /* test MemoryScalable ao: ispetsc = NULL */
69: /*-----------------------------------------------*/
70: if (!rank) {
71: PetscPrintf(PETSC_COMM_SELF,"\nTest AOCreateMemoryScalable with ispetsc=NULL:\n");
72: }
73: AOCreateMemoryScalableIS(isapp,NULL,&ao);
75: AOView(ao,PETSC_VIEWER_STDOUT_WORLD);
77: AOPetscToApplication(ao,4,getapp2);
78: AOApplicationToPetsc(ao,3,getpetsc2);
80: /* Check accuracy */;
81: for (i=0; i<4; i++) {
82: if (getapp2[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp2 %d != getapp %d",getapp2[i],getapp[i]);
83: }
84: for (i=0; i<3; i++) {
85: if (getpetsc2[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc2 %d != getpetsc %d",getpetsc2[i],getpetsc[i]);
86: }
87: AODestroy(&ao);
89: /* test AOCreateMemoryScalable() ao: */
90: ISGetIndices(isapp,&app);
91: AOCreateMemoryScalable(PETSC_COMM_WORLD,n,app,NULL,&ao);
92: ISRestoreIndices(isapp,&app);
94: AOPetscToApplication(ao,4,getapp4);
95: AOApplicationToPetsc(ao,3,getpetsc4);
97: /* Check accuracy */;
98: for (i=0; i<4; i++) {
99: if (getapp4[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp4 %d != getapp %d",getapp4[i],getapp[i]);
100: }
101: for (i=0; i<3; i++) {
102: if (getpetsc4[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc4 %d != getpetsc %d",getpetsc4[i],getpetsc[i]);
103: }
104: AODestroy(&ao);
106: /* test general API */
107: /*------------------*/
108: if (!rank) {
109: PetscPrintf(PETSC_COMM_SELF,"\nTest general API: \n");
110: }
111: AOCreate(PETSC_COMM_WORLD,&ao);
112: AOSetIS(ao,isapp,ispetsc);
113: AOSetType(ao,AOMEMORYSCALABLE);
114: AOSetFromOptions(ao);
116: /* ispetsc and isapp are nolonger used. */
117: ISDestroy(&ispetsc);
118: ISDestroy(&isapp);
120: AOPetscToApplication(ao,4,getapp3);
121: AOApplicationToPetsc(ao,3,getpetsc3);
123: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 2,1,9,7 PetscToApplication %D %D %D %D\n",
124: rank,getapp3[0],getapp3[1],getapp3[2],getapp3[3]);
125: PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] 0,3,4 ApplicationToPetsc %D %D %D\n",
126: rank,getpetsc3[0],getpetsc3[1],getpetsc3[2]);
127: PetscSynchronizedFlush(PETSC_COMM_WORLD,PETSC_STDOUT);
129: /* Check accuracy */;
130: for (i=0; i<4; i++) {
131: if (getapp3[i] != getapp[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getapp3 %d != getapp %d",getapp3[i],getapp[i]);
132: }
133: for (i=0; i<3; i++) {
134: if (getpetsc3[i] != getpetsc[i]) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"getpetsc3 %d != getpetsc %d",getpetsc3[i],getpetsc[i]);
135: }
137: AODestroy(&ao);
138: PetscFinalize();
139: return 0;
140: }