Actual source code: ex1.c

  1: static const char help[] = "Test star forest communication (PetscSF)\n\n";

  3: #include <petscsf.h>
  4: #include <petsc/private/sfimpl.h>

  6: static PetscErrorCode CheckGraphNotSet(PetscSF sf)
  7: {
  8:   PetscInt          nroots,nleaves;
  9:   const PetscInt    *ilocal;
 10:   const PetscSFNode *iremote;

 13:   PetscSFGetGraph(sf,&nroots,&nleaves,&ilocal,&iremote);
 20:   return 0;
 21: }

 23: static PetscErrorCode CheckGraphEmpty(PetscSF sf)
 24: {
 25:   PetscInt          nroots,nleaves;
 26:   const PetscInt    *ilocal;
 27:   const PetscSFNode *iremote;
 28:   PetscInt          minleaf,maxleaf;

 30:   PetscSFGetGraph(sf,&nroots,&nleaves,&ilocal,&iremote);
 35:   PetscSFGetLeafRange(sf,&minleaf,&maxleaf);
 38:   return 0;
 39: }

 41: static PetscErrorCode CheckRanksNotSet(PetscSF sf)
 42: {
 45:   return 0;
 46: }

 48: static PetscErrorCode CheckRanksEmpty(PetscSF sf)
 49: {
 51:   return 0;
 52: }

 54: int main(int argc,char **argv)
 55: {
 56:   PetscSF        sf,sfDup,sfInv,sfEmbed,sfA,sfB,sfBA;
 57:   const PetscInt *degree;
 58:   char           sftype[64] = PETSCSFBASIC;

 60:   PetscInitialize(&argc,&argv,NULL,help);
 61:   PetscOptionsGetString(NULL,NULL,"-user_sf_type",sftype,sizeof(sftype),NULL);

 63:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
 64:   CheckGraphNotSet(sf);
 65:   PetscSFDestroy(&sf);

 67:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
 68:   CheckGraphNotSet(sf);
 69:   PetscSFReset(sf);
 70:   CheckGraphNotSet(sf);
 71:   PetscSFDestroy(&sf);

 73:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
 74:   CheckGraphNotSet(sf);
 75:   PetscSFSetType(sf,sftype);
 76:   CheckGraphNotSet(sf);
 77:   PetscSFDestroy(&sf);

 79:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
 80:   CheckGraphNotSet(sf);
 81:   PetscSFSetType(sf,sftype);
 82:   CheckGraphNotSet(sf);
 83:   PetscSFReset(sf);
 84:   CheckGraphNotSet(sf);
 85:   PetscSFDestroy(&sf);

 87:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
 88:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
 89:   CheckGraphEmpty(sf);
 90:   PetscSFReset(sf);
 91:   CheckGraphNotSet(sf);
 92:   PetscSFDestroy(&sf);

 94:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
 95:   PetscSFSetType(sf,sftype);
 96:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
 97:   CheckGraphEmpty(sf);
 98:   PetscSFReset(sf);
 99:   CheckGraphNotSet(sf);
100:   PetscSFDestroy(&sf);

102:   /* Test setup */
103:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
104:   CheckRanksNotSet(sf);
105:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
106:   CheckRanksNotSet(sf);
107:   PetscSFSetUp(sf);
108:   CheckRanksEmpty(sf);
109:   PetscSFDestroy(&sf);

111:   /* Test setup then reset */
112:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
113:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
114:   PetscSFSetUp(sf);
115:   PetscSFReset(sf);
116:   CheckRanksNotSet(sf);
117:   PetscSFDestroy(&sf);

119:   /* Test view (no graph set, no type set) */
120:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
121:   PetscSFView(sf,NULL);
122:   PetscSFDestroy(&sf);

124:   /* Test set graph then view (no type set) */
125:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
126:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
127:   PetscSFView(sf,NULL);
128:   PetscSFDestroy(&sf);

130:   /* Test set type then view (no graph set) */
131:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
132:   PetscSFSetType(sf,sftype);
133:   PetscSFView(sf,NULL);
134:   PetscSFDestroy(&sf);

136:   /* Test set type then graph then view */
137:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
138:   PetscSFSetType(sf,sftype);
139:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
140:   PetscSFView(sf,NULL);
141:   PetscSFDestroy(&sf);

143:   /* Test set graph then type */
144:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
145:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
146:   PetscSFSetType(sf,sftype);
147:   CheckGraphEmpty(sf);
148:   PetscSFReset(sf);
149:   CheckGraphNotSet(sf);
150:   PetscSFDestroy(&sf);

152:   /* Test Bcast (we call setfromoptions) */
153:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
154:   PetscSFSetType(sf,sftype);
155:   PetscSFSetFromOptions(sf);
156:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
157:   PetscSFBcastBegin(sf,MPI_INT,NULL,NULL,MPI_REPLACE);
158:   PetscSFBcastEnd  (sf,MPI_INT,NULL,NULL,MPI_REPLACE);
159:   PetscSFDestroy(&sf);

161:   /* From now on we also call SetFromOptions */

163:   /* Test Reduce */
164:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
165:   PetscSFSetType(sf,sftype);
166:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
167:   PetscSFSetFromOptions(sf);
168:   PetscSFReduceBegin(sf,MPI_INT,NULL,NULL,MPI_REPLACE);
169:   PetscSFReduceEnd  (sf,MPI_INT,NULL,NULL,MPI_REPLACE);
170:   PetscSFReduceBegin(sf,MPI_INT,NULL,NULL,MPI_SUM);
171:   PetscSFReduceEnd  (sf,MPI_INT,NULL,NULL,MPI_SUM);
172:   PetscSFDestroy(&sf);

174:   /* Test FetchAndOp */
175:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
176:   PetscSFSetType(sf,sftype);
177:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
178:   PetscSFSetFromOptions(sf);
179:   PetscSFFetchAndOpBegin(sf,MPI_INT,NULL,NULL,NULL,MPI_SUM);
180:   PetscSFFetchAndOpEnd  (sf,MPI_INT,NULL,NULL,NULL,MPI_SUM);
181:   PetscSFDestroy(&sf);

183:   /* Test ComputeDegree */
184:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
185:   PetscSFSetType(sf,sftype);
186:   PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
187:   PetscSFSetFromOptions(sf);
188:   PetscSFComputeDegreeBegin(sf,&degree);
189:   PetscSFComputeDegreeEnd(sf,&degree);
190:   PetscSFDestroy(&sf);

192:   /* Test PetscSFDuplicate() */
193:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
194:   PetscSFSetType(sf,sftype);
195:   PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
196:   PetscSFSetFromOptions(sf);
197:   PetscSFDuplicate(sf,PETSCSF_DUPLICATE_GRAPH,&sfDup);
198:   CheckGraphEmpty(sfDup);
199:   PetscSFDestroy(&sfDup);
200:   PetscSFDestroy(&sf);

202:   /* Test PetscSFCreateInverseSF() */
203:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
204:   PetscSFSetType(sf,sftype);
205:   PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
206:   PetscSFSetFromOptions(sf);
207:   PetscSFCreateInverseSF(sf,&sfInv);
208:   CheckGraphEmpty(sfInv);
209:   PetscSFDestroy(&sfInv);
210:   PetscSFDestroy(&sf);

212:   /* Test PetscSFCreateEmbeddedRootSF() */
213:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
214:   PetscSFSetType(sf,sftype);
215:   PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
216:   PetscSFSetFromOptions(sf);
217:   PetscSFCreateEmbeddedRootSF(sf,0,NULL,&sfEmbed);
218:   CheckGraphEmpty(sfEmbed);
219:   PetscSFDestroy(&sfEmbed);
220:   PetscSFDestroy(&sf);

222:   /* Test PetscSFCreateEmbeddedLeafSF() */
223:   PetscSFCreate(PETSC_COMM_WORLD,&sf);
224:   PetscSFSetType(sf,sftype);
225:   PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
226:   PetscSFSetFromOptions(sf);
227:   PetscSFCreateEmbeddedLeafSF(sf,0,NULL,&sfEmbed);
228:   CheckGraphEmpty(sfEmbed);
229:   PetscSFDestroy(&sfEmbed);
230:   PetscSFDestroy(&sf);

232:   /* Test PetscSFCompose() */
233:   PetscSFCreate(PETSC_COMM_WORLD,&sfA);
234:   PetscSFSetType(sfA,sftype);
235:   PetscSFSetGraph(sfA,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
236:   PetscSFCreate(PETSC_COMM_WORLD,&sfB);
237:   PetscSFSetType(sfB,sftype);
238:   PetscSFSetGraph(sfB,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
239:   PetscSFCompose(sfA,sfB,&sfBA);
240:   CheckGraphEmpty(sfBA);
241:   PetscSFDestroy(&sfBA);
242:   PetscSFDestroy(&sfA);
243:   PetscSFDestroy(&sfB);

245:   PetscFinalize();
246:   return 0;
247: }

249: /*TEST

251:    test:
252:       suffix: basic_1
253:       nsize: 1

255:    test:
256:       suffix: basic_2
257:       nsize: 2

259:    test:
260:       suffix: basic_3
261:       nsize: 3

263:    test:
264:       suffix: window
265:       args: -user_sf_type window -sf_type window -sf_window_flavor {{create dynamic allocate}} -sf_window_sync {{fence active lock}}
266:       nsize: {{1 2 3}separate output}
267:       requires: defined(PETSC_HAVE_MPI_ONE_SIDED) defined(PETSC_HAVE_MPI_FEATURE_DYNAMIC_WINDOW)

269:    # The nightly test suite with MPICH uses ch3:sock, which is broken when winsize == 0 in some of the processes
270:    test:
271:       suffix: window_shared
272:       args: -user_sf_type window -sf_type window -sf_window_flavor shared -sf_window_sync {{fence active lock}}
273:       nsize: {{1 2 3}separate output}
274:       requires: defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY) !defined(PETSC_HAVE_MPICH_NUMVERSION) defined(PETSC_HAVE_MPI_ONE_SIDED) defined(PETSC_HAVE_MPI_FEATURE_DYNAMIC_WINDOW)

276: TEST*/