Actual source code: ex1.c
1: static const char help[] = "Test star forest communication (PetscSF)\n\n";
3: /*T
4: Description: This example creates empty star forests to test the API.
5: T*/
7: #include <petscsf.h>
8: #include <petsc/private/sfimpl.h>
10: static PetscErrorCode CheckGraphNotSet(PetscSF sf)
11: {
12: PetscInt nroots,nleaves;
13: const PetscInt *ilocal;
14: const PetscSFNode *iremote;
17: PetscSFGetGraph(sf,&nroots,&nleaves,&ilocal,&iremote);
24: return 0;
25: }
27: static PetscErrorCode CheckGraphEmpty(PetscSF sf)
28: {
29: PetscInt nroots,nleaves;
30: const PetscInt *ilocal;
31: const PetscSFNode *iremote;
32: PetscInt minleaf,maxleaf;
34: PetscSFGetGraph(sf,&nroots,&nleaves,&ilocal,&iremote);
39: PetscSFGetLeafRange(sf,&minleaf,&maxleaf);
42: return 0;
43: }
45: static PetscErrorCode CheckRanksNotSet(PetscSF sf)
46: {
49: return 0;
50: }
52: static PetscErrorCode CheckRanksEmpty(PetscSF sf)
53: {
55: return 0;
56: }
58: int main(int argc,char **argv)
59: {
60: PetscSF sf,sfDup,sfInv,sfEmbed,sfA,sfB,sfBA;
61: const PetscInt *degree;
62: char sftype[64] = PETSCSFBASIC;
64: PetscInitialize(&argc,&argv,NULL,help);
65: PetscOptionsGetString(NULL,NULL,"-user_sf_type",sftype,sizeof(sftype),NULL);
67: PetscSFCreate(PETSC_COMM_WORLD,&sf);
68: CheckGraphNotSet(sf);
69: PetscSFDestroy(&sf);
71: PetscSFCreate(PETSC_COMM_WORLD,&sf);
72: CheckGraphNotSet(sf);
73: PetscSFReset(sf);
74: CheckGraphNotSet(sf);
75: PetscSFDestroy(&sf);
77: PetscSFCreate(PETSC_COMM_WORLD,&sf);
78: CheckGraphNotSet(sf);
79: PetscSFSetType(sf,sftype);
80: CheckGraphNotSet(sf);
81: PetscSFDestroy(&sf);
83: PetscSFCreate(PETSC_COMM_WORLD,&sf);
84: CheckGraphNotSet(sf);
85: PetscSFSetType(sf,sftype);
86: CheckGraphNotSet(sf);
87: PetscSFReset(sf);
88: CheckGraphNotSet(sf);
89: PetscSFDestroy(&sf);
91: PetscSFCreate(PETSC_COMM_WORLD,&sf);
92: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
93: CheckGraphEmpty(sf);
94: PetscSFReset(sf);
95: CheckGraphNotSet(sf);
96: PetscSFDestroy(&sf);
98: PetscSFCreate(PETSC_COMM_WORLD,&sf);
99: PetscSFSetType(sf,sftype);
100: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
101: CheckGraphEmpty(sf);
102: PetscSFReset(sf);
103: CheckGraphNotSet(sf);
104: PetscSFDestroy(&sf);
106: /* Test setup */
107: PetscSFCreate(PETSC_COMM_WORLD,&sf);
108: CheckRanksNotSet(sf);
109: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
110: CheckRanksNotSet(sf);
111: PetscSFSetUp(sf);
112: CheckRanksEmpty(sf);
113: PetscSFDestroy(&sf);
115: /* Test setup then reset */
116: PetscSFCreate(PETSC_COMM_WORLD,&sf);
117: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
118: PetscSFSetUp(sf);
119: PetscSFReset(sf);
120: CheckRanksNotSet(sf);
121: PetscSFDestroy(&sf);
123: /* Test view (no graph set, no type set) */
124: PetscSFCreate(PETSC_COMM_WORLD,&sf);
125: PetscSFView(sf,NULL);
126: PetscSFDestroy(&sf);
128: /* Test set graph then view (no type set) */
129: PetscSFCreate(PETSC_COMM_WORLD,&sf);
130: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
131: PetscSFView(sf,NULL);
132: PetscSFDestroy(&sf);
134: /* Test set type then view (no graph set) */
135: PetscSFCreate(PETSC_COMM_WORLD,&sf);
136: PetscSFSetType(sf,sftype);
137: PetscSFView(sf,NULL);
138: PetscSFDestroy(&sf);
140: /* Test set type then graph then view */
141: PetscSFCreate(PETSC_COMM_WORLD,&sf);
142: PetscSFSetType(sf,sftype);
143: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
144: PetscSFView(sf,NULL);
145: PetscSFDestroy(&sf);
147: /* Test set graph then type */
148: PetscSFCreate(PETSC_COMM_WORLD,&sf);
149: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
150: PetscSFSetType(sf,sftype);
151: CheckGraphEmpty(sf);
152: PetscSFReset(sf);
153: CheckGraphNotSet(sf);
154: PetscSFDestroy(&sf);
156: /* Test Bcast (we call setfromoptions) */
157: PetscSFCreate(PETSC_COMM_WORLD,&sf);
158: PetscSFSetType(sf,sftype);
159: PetscSFSetFromOptions(sf);
160: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
161: PetscSFBcastBegin(sf,MPI_INT,NULL,NULL,MPI_REPLACE);
162: PetscSFBcastEnd (sf,MPI_INT,NULL,NULL,MPI_REPLACE);
163: PetscSFDestroy(&sf);
165: /* From now on we also call SetFromOptions */
167: /* Test Reduce */
168: PetscSFCreate(PETSC_COMM_WORLD,&sf);
169: PetscSFSetType(sf,sftype);
170: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
171: PetscSFSetFromOptions(sf);
172: PetscSFReduceBegin(sf,MPI_INT,NULL,NULL,MPI_REPLACE);
173: PetscSFReduceEnd (sf,MPI_INT,NULL,NULL,MPI_REPLACE);
174: PetscSFReduceBegin(sf,MPI_INT,NULL,NULL,MPI_SUM);
175: PetscSFReduceEnd (sf,MPI_INT,NULL,NULL,MPI_SUM);
176: PetscSFDestroy(&sf);
178: /* Test FetchAndOp */
179: PetscSFCreate(PETSC_COMM_WORLD,&sf);
180: PetscSFSetType(sf,sftype);
181: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
182: PetscSFSetFromOptions(sf);
183: PetscSFFetchAndOpBegin(sf,MPI_INT,NULL,NULL,NULL,MPI_SUM);
184: PetscSFFetchAndOpEnd (sf,MPI_INT,NULL,NULL,NULL,MPI_SUM);
185: PetscSFDestroy(&sf);
187: /* Test ComputeDegree */
188: PetscSFCreate(PETSC_COMM_WORLD,&sf);
189: PetscSFSetType(sf,sftype);
190: PetscSFSetGraph(sf,0,0,NULL,PETSC_COPY_VALUES,NULL,PETSC_COPY_VALUES);
191: PetscSFSetFromOptions(sf);
192: PetscSFComputeDegreeBegin(sf,°ree);
193: PetscSFComputeDegreeEnd(sf,°ree);
194: PetscSFDestroy(&sf);
196: /* Test PetscSFDuplicate() */
197: PetscSFCreate(PETSC_COMM_WORLD,&sf);
198: PetscSFSetType(sf,sftype);
199: PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
200: PetscSFSetFromOptions(sf);
201: PetscSFDuplicate(sf,PETSCSF_DUPLICATE_GRAPH,&sfDup);
202: CheckGraphEmpty(sfDup);
203: PetscSFDestroy(&sfDup);
204: PetscSFDestroy(&sf);
206: /* Test PetscSFCreateInverseSF() */
207: PetscSFCreate(PETSC_COMM_WORLD,&sf);
208: PetscSFSetType(sf,sftype);
209: PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
210: PetscSFSetFromOptions(sf);
211: PetscSFCreateInverseSF(sf,&sfInv);
212: CheckGraphEmpty(sfInv);
213: PetscSFDestroy(&sfInv);
214: PetscSFDestroy(&sf);
216: /* Test PetscSFCreateEmbeddedRootSF() */
217: PetscSFCreate(PETSC_COMM_WORLD,&sf);
218: PetscSFSetType(sf,sftype);
219: PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
220: PetscSFSetFromOptions(sf);
221: PetscSFCreateEmbeddedRootSF(sf,0,NULL,&sfEmbed);
222: CheckGraphEmpty(sfEmbed);
223: PetscSFDestroy(&sfEmbed);
224: PetscSFDestroy(&sf);
226: /* Test PetscSFCreateEmbeddedLeafSF() */
227: PetscSFCreate(PETSC_COMM_WORLD,&sf);
228: PetscSFSetType(sf,sftype);
229: PetscSFSetGraph(sf,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
230: PetscSFSetFromOptions(sf);
231: PetscSFCreateEmbeddedLeafSF(sf,0,NULL,&sfEmbed);
232: CheckGraphEmpty(sfEmbed);
233: PetscSFDestroy(&sfEmbed);
234: PetscSFDestroy(&sf);
236: /* Test PetscSFCompose() */
237: PetscSFCreate(PETSC_COMM_WORLD,&sfA);
238: PetscSFSetType(sfA,sftype);
239: PetscSFSetGraph(sfA,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
240: PetscSFCreate(PETSC_COMM_WORLD,&sfB);
241: PetscSFSetType(sfB,sftype);
242: PetscSFSetGraph(sfB,0,0,NULL,PETSC_USE_POINTER,NULL,PETSC_USE_POINTER);
243: PetscSFCompose(sfA,sfB,&sfBA);
244: CheckGraphEmpty(sfBA);
245: PetscSFDestroy(&sfBA);
246: PetscSFDestroy(&sfA);
247: PetscSFDestroy(&sfB);
249: PetscFinalize();
250: return 0;
251: }
253: /*TEST
255: test:
256: suffix: basic_1
257: nsize: 1
259: test:
260: suffix: basic_2
261: nsize: 2
263: test:
264: suffix: basic_3
265: nsize: 3
267: test:
268: suffix: window
269: args: -user_sf_type window -sf_type window -sf_window_flavor {{create dynamic allocate}} -sf_window_sync {{fence active lock}}
270: nsize: {{1 2 3}separate output}
271: requires: defined(PETSC_HAVE_MPI_ONE_SIDED) defined(PETSC_HAVE_MPI_FEATURE_DYNAMIC_WINDOW)
273: # The nightly test suite with MPICH uses ch3:sock, which is broken when winsize == 0 in some of the processes
274: test:
275: suffix: window_shared
276: args: -user_sf_type window -sf_type window -sf_window_flavor shared -sf_window_sync {{fence active lock}}
277: nsize: {{1 2 3}separate output}
278: 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)
280: TEST*/