Actual source code: ex9.c
1: static char help[] = "Performance tests for DMPlex query operations\n\n";
3: #include <petscdmplex.h>
5: typedef struct {
6: PetscInt dim; /* The topological mesh dimension */
7: PetscBool cellSimplex; /* Flag for simplices */
8: PetscBool spectral; /* Flag for spectral element layout */
9: PetscBool interpolate; /* Flag for mesh interpolation */
10: PetscReal refinementLimit; /* Maximum volume of a refined cell */
11: PetscInt numFields; /* The number of section fields */
12: PetscInt *numComponents; /* The number of field components */
13: PetscInt *numDof; /* The dof signature for the section */
14: PetscBool reuseArray; /* Pass in user allocated array to VecGetClosure() */
15: /* Test data */
16: PetscBool errors; /* Treat failures as errors */
17: PetscInt iterations; /* The number of iterations for a query */
18: PetscReal maxConeTime; /* Max time per run for DMPlexGetCone() */
19: PetscReal maxClosureTime; /* Max time per run for DMPlexGetTransitiveClosure() */
20: PetscReal maxVecClosureTime; /* Max time per run for DMPlexVecGetClosure() */
21: PetscBool printTimes; /* Print total times, do not check limits */
22: } AppCtx;
24: static PetscErrorCode ProcessOptions(AppCtx *options)
25: {
26: PetscInt len;
27: PetscBool flg;
29: PetscFunctionBegin;
30: options->dim = 2;
31: options->cellSimplex = PETSC_TRUE;
32: options->spectral = PETSC_FALSE;
33: options->interpolate = PETSC_FALSE;
34: options->refinementLimit = 0.0;
35: options->numFields = 0;
36: options->numComponents = NULL;
37: options->numDof = NULL;
38: options->reuseArray = PETSC_FALSE;
39: options->errors = PETSC_FALSE;
40: options->iterations = 1;
41: options->maxConeTime = 0.0;
42: options->maxClosureTime = 0.0;
43: options->maxVecClosureTime = 0.0;
44: options->printTimes = PETSC_FALSE;
46: PetscOptionsBegin(PETSC_COMM_SELF, "", "Meshing Problem Options", "DMPLEX");
47: PetscCall(PetscOptionsRangeInt("-dim", "The topological mesh dimension", "ex9.c", options->dim, &options->dim, NULL, 1, 3));
48: PetscCall(PetscOptionsBool("-cellSimplex", "Flag for simplices", "ex9.c", options->cellSimplex, &options->cellSimplex, NULL));
49: PetscCall(PetscOptionsBool("-spectral", "Flag for spectral element layout", "ex9.c", options->spectral, &options->spectral, NULL));
50: PetscCall(PetscOptionsBool("-interpolate", "Flag for mesh interpolation", "ex9.c", options->interpolate, &options->interpolate, NULL));
51: PetscCall(PetscOptionsReal("-refinement_limit", "The maximum volume of a refined cell", "ex9.c", options->refinementLimit, &options->refinementLimit, NULL));
52: PetscCall(PetscOptionsBoundedInt("-num_fields", "The number of section fields", "ex9.c", options->numFields, &options->numFields, NULL, 0));
53: if (options->numFields) {
54: len = options->numFields;
55: PetscCall(PetscMalloc1(len, &options->numComponents));
56: PetscCall(PetscOptionsIntArray("-num_components", "The number of components per field", "ex9.c", options->numComponents, &len, &flg));
57: PetscCheck(!flg || !(len != options->numFields), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Length of components array is %" PetscInt_FMT " should be %" PetscInt_FMT, len, options->numFields);
58: }
59: len = (options->dim + 1) * PetscMax(1, options->numFields);
60: PetscCall(PetscMalloc1(len, &options->numDof));
61: PetscCall(PetscOptionsIntArray("-num_dof", "The dof signature for the section", "ex9.c", options->numDof, &len, &flg));
62: PetscCheck(!flg || len == (options->dim + 1) * PetscMax(1, options->numFields), PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "Length of dof array is %" PetscInt_FMT " should be %" PetscInt_FMT, len, (options->dim + 1) * PetscMax(1, options->numFields));
64: /* We are specifying the scalar dof, so augment it for multiple components */
65: {
66: for (PetscInt f = 0; f < options->numFields; ++f) {
67: for (PetscInt d = 0; d <= options->dim; ++d) options->numDof[f * (options->dim + 1) + d] *= options->numComponents[f];
68: }
69: }
71: PetscCall(PetscOptionsBool("-reuse_array", "Pass in user allocated array to VecGetClosure()", "ex9.c", options->reuseArray, &options->reuseArray, NULL));
72: PetscCall(PetscOptionsBool("-errors", "Treat failures as errors", "ex9.c", options->errors, &options->errors, NULL));
73: PetscCall(PetscOptionsBoundedInt("-iterations", "The number of iterations for a query", "ex9.c", options->iterations, &options->iterations, NULL, 0));
74: PetscCall(PetscOptionsReal("-max_cone_time", "The maximum time per run for DMPlexGetCone()", "ex9.c", options->maxConeTime, &options->maxConeTime, NULL));
75: PetscCall(PetscOptionsReal("-max_closure_time", "The maximum time per run for DMPlexGetTransitiveClosure()", "ex9.c", options->maxClosureTime, &options->maxClosureTime, NULL));
76: PetscCall(PetscOptionsReal("-max_vec_closure_time", "The maximum time per run for DMPlexVecGetClosure()", "ex9.c", options->maxVecClosureTime, &options->maxVecClosureTime, NULL));
77: PetscCall(PetscOptionsBool("-print_times", "Print total times, do not check limits", "ex9.c", options->printTimes, &options->printTimes, NULL));
78: PetscOptionsEnd();
79: PetscFunctionReturn(PETSC_SUCCESS);
80: }
82: static PetscErrorCode CreateSimplex_2D(MPI_Comm comm, DM *newdm)
83: {
84: DM dm;
85: PetscInt numPoints[2] = {4, 2};
86: PetscInt coneSize[6] = {3, 3, 0, 0, 0, 0};
87: PetscInt cones[6] = {2, 3, 4, 5, 4, 3};
88: PetscInt coneOrientations[6] = {0, 0, 0, 0, 0, 0};
89: PetscScalar vertexCoords[8] = {-0.5, 0.5, 0.0, 0.0, 0.0, 1.0, 0.5, 0.5};
90: PetscInt markerPoints[8] = {2, 1, 3, 1, 4, 1, 5, 1};
91: PetscInt dim = 2, depth = 1, p;
93: PetscFunctionBegin;
94: PetscCall(DMCreate(comm, &dm));
95: PetscCall(PetscObjectSetName((PetscObject)dm, "triangular"));
96: PetscCall(DMSetType(dm, DMPLEX));
97: PetscCall(DMSetDimension(dm, dim));
98: PetscCall(DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations, vertexCoords));
99: for (p = 0; p < 4; ++p) PetscCall(DMSetLabelValue(dm, "marker", markerPoints[p * 2], markerPoints[p * 2 + 1]));
100: *newdm = dm;
101: PetscFunctionReturn(PETSC_SUCCESS);
102: }
104: static PetscErrorCode CreateSimplex_3D(MPI_Comm comm, DM *newdm)
105: {
106: DM dm;
107: PetscInt numPoints[2] = {5, 2};
108: PetscInt coneSize[23] = {4, 4, 0, 0, 0, 0, 0};
109: PetscInt cones[8] = {2, 4, 3, 5, 3, 4, 6, 5};
110: PetscInt coneOrientations[8] = {0, 0, 0, 0, 0, 0, 0, 0};
111: PetscScalar vertexCoords[15] = {0.0, 0.0, -0.5, 0.0, -0.5, 0.0, 1.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5};
112: PetscInt markerPoints[10] = {2, 1, 3, 1, 4, 1, 5, 1, 6, 1};
113: PetscInt dim = 3, depth = 1, p;
115: PetscFunctionBegin;
116: PetscCall(DMCreate(comm, &dm));
117: PetscCall(PetscObjectSetName((PetscObject)dm, "tetrahedral"));
118: PetscCall(DMSetType(dm, DMPLEX));
119: PetscCall(DMSetDimension(dm, dim));
120: PetscCall(DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations, vertexCoords));
121: for (p = 0; p < 5; ++p) PetscCall(DMSetLabelValue(dm, "marker", markerPoints[p * 2], markerPoints[p * 2 + 1]));
122: *newdm = dm;
123: PetscFunctionReturn(PETSC_SUCCESS);
124: }
126: static PetscErrorCode CreateQuad_2D(MPI_Comm comm, DM *newdm)
127: {
128: DM dm;
129: PetscInt numPoints[2] = {6, 2};
130: PetscInt coneSize[8] = {4, 4, 0, 0, 0, 0, 0, 0};
131: PetscInt cones[8] = {2, 3, 4, 5, 3, 6, 7, 4};
132: PetscInt coneOrientations[8] = {0, 0, 0, 0, 0, 0, 0, 0};
133: PetscScalar vertexCoords[12] = {-0.5, 0.0, 0.0, 0.0, 0.0, 1.0, -0.5, 1.0, 0.5, 0.0, 0.5, 1.0};
134: PetscInt markerPoints[12] = {2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1};
135: PetscInt dim = 2, depth = 1, p;
137: PetscFunctionBegin;
138: PetscCall(DMCreate(comm, &dm));
139: PetscCall(PetscObjectSetName((PetscObject)dm, "quadrilateral"));
140: PetscCall(DMSetType(dm, DMPLEX));
141: PetscCall(DMSetDimension(dm, dim));
142: PetscCall(DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations, vertexCoords));
143: for (p = 0; p < 6; ++p) PetscCall(DMSetLabelValue(dm, "marker", markerPoints[p * 2], markerPoints[p * 2 + 1]));
144: *newdm = dm;
145: PetscFunctionReturn(PETSC_SUCCESS);
146: }
148: static PetscErrorCode CreateHex_3D(MPI_Comm comm, DM *newdm)
149: {
150: DM dm;
151: PetscInt numPoints[2] = {12, 2};
152: PetscInt coneSize[14] = {8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
153: PetscInt cones[16] = {2, 5, 4, 3, 6, 7, 8, 9, 3, 4, 11, 10, 7, 12, 13, 8};
154: PetscInt coneOrientations[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
155: PetscScalar vertexCoords[36] = {-0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -0.5, 1.0, 0.0, -0.5, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, -0.5, 1.0, 1.0, 0.5, 0.0, 0.0, 0.5, 1.0, 0.0, 0.5, 0.0, 1.0, 0.5, 1.0, 1.0};
156: PetscInt markerPoints[24] = {2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1};
157: PetscInt dim = 3, depth = 1, p;
159: PetscFunctionBegin;
160: PetscCall(DMCreate(comm, &dm));
161: PetscCall(PetscObjectSetName((PetscObject)dm, "hexahedral"));
162: PetscCall(DMSetType(dm, DMPLEX));
163: PetscCall(DMSetDimension(dm, dim));
164: PetscCall(DMPlexCreateFromDAG(dm, depth, numPoints, coneSize, cones, coneOrientations, vertexCoords));
165: for (p = 0; p < 12; ++p) PetscCall(DMSetLabelValue(dm, "marker", markerPoints[p * 2], markerPoints[p * 2 + 1]));
166: *newdm = dm;
167: PetscFunctionReturn(PETSC_SUCCESS);
168: }
170: static PetscErrorCode CreateMesh(MPI_Comm comm, AppCtx *user, DM *newdm)
171: {
172: PetscInt dim = user->dim;
173: PetscBool cellSimplex = user->cellSimplex;
175: PetscFunctionBegin;
176: switch (dim) {
177: case 2:
178: if (cellSimplex) {
179: PetscCall(CreateSimplex_2D(comm, newdm));
180: } else {
181: PetscCall(CreateQuad_2D(comm, newdm));
182: }
183: break;
184: case 3:
185: if (cellSimplex) {
186: PetscCall(CreateSimplex_3D(comm, newdm));
187: } else {
188: PetscCall(CreateHex_3D(comm, newdm));
189: }
190: break;
191: default:
192: SETERRQ(comm, PETSC_ERR_ARG_OUTOFRANGE, "Cannot make meshes for dimension %" PetscInt_FMT, dim);
193: }
194: if (user->refinementLimit > 0.0) {
195: DM rdm;
196: const char *name;
198: PetscCall(DMPlexSetRefinementUniform(*newdm, PETSC_FALSE));
199: PetscCall(DMPlexSetRefinementLimit(*newdm, user->refinementLimit));
200: PetscCall(DMRefine(*newdm, PETSC_COMM_SELF, &rdm));
201: PetscCall(PetscObjectGetName((PetscObject)*newdm, &name));
202: PetscCall(PetscObjectSetName((PetscObject)rdm, name));
203: PetscCall(DMDestroy(newdm));
204: *newdm = rdm;
205: }
206: if (user->interpolate) {
207: DM idm;
209: PetscCall(DMPlexInterpolate(*newdm, &idm));
210: PetscCall(DMDestroy(newdm));
211: *newdm = idm;
212: }
213: PetscCall(DMSetFromOptions(*newdm));
214: PetscFunctionReturn(PETSC_SUCCESS);
215: }
217: static PetscErrorCode TestCone(DM dm, AppCtx *user)
218: {
219: PetscInt numRuns, cStart, cEnd, c, i;
220: PetscReal maxTimePerRun = user->maxConeTime;
221: PetscLogStage stage;
222: PetscLogEvent event;
223: PetscEventPerfInfo eventInfo;
224: MPI_Comm comm;
225: PetscMPIInt rank;
227: PetscFunctionBegin;
228: PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
229: PetscCallMPI(MPI_Comm_rank(comm, &rank));
230: PetscCall(PetscLogStageRegister("DMPlex Cone Test", &stage));
231: PetscCall(PetscLogEventRegister("Cone", PETSC_OBJECT_CLASSID, &event));
232: PetscCall(PetscLogStagePush(stage));
233: PetscCall(DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd));
234: PetscCall(PetscLogEventBegin(event, 0, 0, 0, 0));
235: for (i = 0; i < user->iterations; ++i) {
236: for (c = cStart; c < cEnd; ++c) {
237: const PetscInt *cone;
239: PetscCall(DMPlexGetCone(dm, c, &cone));
240: }
241: }
242: PetscCall(PetscLogEventEnd(event, 0, 0, 0, 0));
243: PetscCall(PetscLogStagePop());
245: PetscCall(PetscLogEventGetPerfInfo(stage, event, &eventInfo));
246: numRuns = (cEnd - cStart) * user->iterations;
247: PetscCheck(eventInfo.count == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of event calls %d should be 1", eventInfo.count);
248: PetscCheck((PetscInt)eventInfo.flops == 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of event flops %" PetscInt_FMT " should be 0", (PetscInt)eventInfo.flops);
249: if (user->printTimes) {
250: PetscCall(PetscSynchronizedPrintf(comm, "[%d] Cones: %" PetscInt_FMT " Total time: %.3es Average time per cone: %.3es\n", rank, numRuns, eventInfo.time, eventInfo.time / numRuns));
251: PetscCall(PetscSynchronizedFlush(comm, PETSC_STDOUT));
252: } else if (eventInfo.time > maxTimePerRun * numRuns) {
253: PetscCall(PetscSynchronizedPrintf(comm, "[%d] Cones: %" PetscInt_FMT " Average time per cone: %gs standard: %gs\n", rank, numRuns, eventInfo.time / numRuns, (double)maxTimePerRun));
254: PetscCall(PetscSynchronizedFlush(comm, PETSC_STDOUT));
255: PetscCheck(!user->errors, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Average time for cone %g > standard %g", eventInfo.time / numRuns, (double)maxTimePerRun);
256: }
257: PetscFunctionReturn(PETSC_SUCCESS);
258: }
260: static PetscErrorCode TestTransitiveClosure(DM dm, AppCtx *user)
261: {
262: PetscInt numRuns, cStart, cEnd, c, i;
263: PetscReal maxTimePerRun = user->maxClosureTime;
264: PetscLogStage stage;
265: PetscLogEvent event;
266: PetscEventPerfInfo eventInfo;
267: MPI_Comm comm;
268: PetscMPIInt rank;
270: PetscFunctionBegin;
271: PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
272: PetscCallMPI(MPI_Comm_rank(comm, &rank));
273: PetscCall(PetscLogStageRegister("DMPlex Transitive Closure Test", &stage));
274: PetscCall(PetscLogEventRegister("TransitiveClosure", PETSC_OBJECT_CLASSID, &event));
275: PetscCall(PetscLogStagePush(stage));
276: PetscCall(DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd));
277: PetscCall(PetscLogEventBegin(event, 0, 0, 0, 0));
278: for (i = 0; i < user->iterations; ++i) {
279: for (c = cStart; c < cEnd; ++c) {
280: PetscInt *closure = NULL;
281: PetscInt closureSize;
283: PetscCall(DMPlexGetTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure));
284: PetscCall(DMPlexRestoreTransitiveClosure(dm, c, PETSC_TRUE, &closureSize, &closure));
285: }
286: }
287: PetscCall(PetscLogEventEnd(event, 0, 0, 0, 0));
288: PetscCall(PetscLogStagePop());
290: PetscCall(PetscLogEventGetPerfInfo(stage, event, &eventInfo));
291: numRuns = (cEnd - cStart) * user->iterations;
292: PetscCheck(eventInfo.count == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of event calls %d should be 1", eventInfo.count);
293: PetscCheck((PetscInt)eventInfo.flops == 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of event flops %" PetscInt_FMT " should be 0", (PetscInt)eventInfo.flops);
294: if (user->printTimes) {
295: PetscCall(PetscSynchronizedPrintf(comm, "[%d] Closures: %" PetscInt_FMT " Total time: %.3es Average time per cone: %.3es\n", rank, numRuns, eventInfo.time, eventInfo.time / numRuns));
296: PetscCall(PetscSynchronizedFlush(comm, PETSC_STDOUT));
297: } else if (eventInfo.time > maxTimePerRun * numRuns) {
298: PetscCall(PetscSynchronizedPrintf(comm, "[%d] Closures: %" PetscInt_FMT " Average time per cone: %gs standard: %gs\n", rank, numRuns, eventInfo.time / numRuns, (double)maxTimePerRun));
299: PetscCall(PetscSynchronizedFlush(comm, PETSC_STDOUT));
300: PetscCheck(!user->errors, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Average time for closure %g > standard %g", eventInfo.time / numRuns, (double)maxTimePerRun);
301: }
302: PetscFunctionReturn(PETSC_SUCCESS);
303: }
305: static PetscErrorCode TestVecClosure(DM dm, PetscBool useIndex, PetscBool useSpectral, AppCtx *user)
306: {
307: PetscSection s;
308: Vec v;
309: PetscInt numRuns, cStart, cEnd, c, i;
310: PetscScalar tmpArray[64];
311: PetscScalar *userArray = user->reuseArray ? tmpArray : NULL;
312: PetscReal maxTimePerRun = user->maxVecClosureTime;
313: PetscLogStage stage;
314: PetscLogEvent event;
315: PetscEventPerfInfo eventInfo;
316: MPI_Comm comm;
317: PetscMPIInt rank;
319: PetscFunctionBegin;
320: PetscCall(PetscObjectGetComm((PetscObject)dm, &comm));
321: PetscCallMPI(MPI_Comm_rank(comm, &rank));
322: if (useIndex) {
323: if (useSpectral) {
324: PetscCall(PetscLogStageRegister("DMPlex Vector Closure with Index Test", &stage));
325: PetscCall(PetscLogEventRegister("VecClosureInd", PETSC_OBJECT_CLASSID, &event));
326: } else {
327: PetscCall(PetscLogStageRegister("DMPlex Vector Spectral Closure with Index Test", &stage));
328: PetscCall(PetscLogEventRegister("VecClosureSpecInd", PETSC_OBJECT_CLASSID, &event));
329: }
330: } else {
331: if (useSpectral) {
332: PetscCall(PetscLogStageRegister("DMPlex Vector Spectral Closure Test", &stage));
333: PetscCall(PetscLogEventRegister("VecClosureSpec", PETSC_OBJECT_CLASSID, &event));
334: } else {
335: PetscCall(PetscLogStageRegister("DMPlex Vector Closure Test", &stage));
336: PetscCall(PetscLogEventRegister("VecClosure", PETSC_OBJECT_CLASSID, &event));
337: }
338: }
339: PetscCall(PetscLogStagePush(stage));
340: PetscCall(DMSetNumFields(dm, user->numFields));
341: PetscCall(DMPlexCreateSection(dm, NULL, user->numComponents, user->numDof, 0, NULL, NULL, NULL, NULL, &s));
342: PetscCall(DMSetLocalSection(dm, s));
343: if (useIndex) PetscCall(DMPlexCreateClosureIndex(dm, s));
344: if (useSpectral) PetscCall(DMPlexSetClosurePermutationTensor(dm, PETSC_DETERMINE, s));
345: PetscCall(PetscSectionDestroy(&s));
346: PetscCall(DMPlexGetHeightStratum(dm, 0, &cStart, &cEnd));
347: PetscCall(DMGetLocalVector(dm, &v));
348: PetscCall(PetscLogEventBegin(event, 0, 0, 0, 0));
349: for (i = 0; i < user->iterations; ++i) {
350: for (c = cStart; c < cEnd; ++c) {
351: PetscScalar *closure = userArray;
352: PetscInt closureSize = 64;
354: PetscCall(DMPlexVecGetClosure(dm, s, v, c, &closureSize, &closure));
355: if (!user->reuseArray) PetscCall(DMPlexVecRestoreClosure(dm, s, v, c, &closureSize, &closure));
356: }
357: }
358: PetscCall(PetscLogEventEnd(event, 0, 0, 0, 0));
359: PetscCall(DMRestoreLocalVector(dm, &v));
360: PetscCall(PetscLogStagePop());
362: PetscCall(PetscLogEventGetPerfInfo(stage, event, &eventInfo));
363: numRuns = (cEnd - cStart) * user->iterations;
364: PetscCheck(eventInfo.count == 1, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of event calls %d should be 1", eventInfo.count);
365: PetscCheck((PetscInt)eventInfo.flops == 0, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of event flops %" PetscInt_FMT " should be 0", (PetscInt)eventInfo.flops);
366: if (user->printTimes || eventInfo.time > maxTimePerRun * numRuns) {
367: const char *title = "VecClosures";
368: const char *titleIndex = "VecClosures with Index";
369: const char *titleSpec = "VecClosures Spectral";
370: const char *titleSpecIndex = "VecClosures Spectral with Index";
372: if (user->printTimes) {
373: PetscCall(PetscSynchronizedPrintf(comm, "[%d] %s: %" PetscInt_FMT " Total time: %.3es Average time per vector closure: %.3es\n", rank, useIndex ? (useSpectral ? titleSpecIndex : titleIndex) : (useSpectral ? titleSpec : title), numRuns,
374: eventInfo.time, eventInfo.time / numRuns));
375: PetscCall(PetscSynchronizedFlush(comm, PETSC_STDOUT));
376: } else {
377: PetscCall(PetscSynchronizedPrintf(comm, "[%d] %s: %" PetscInt_FMT " Average time per vector closure: %gs standard: %gs\n", rank, useIndex ? (useSpectral ? titleSpecIndex : titleIndex) : (useSpectral ? titleSpec : title), numRuns, eventInfo.time / numRuns, (double)maxTimePerRun));
378: PetscCall(PetscSynchronizedFlush(comm, PETSC_STDOUT));
379: PetscCheck(!user->errors, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Average time for vector closure %g > standard %g", eventInfo.time / numRuns, (double)maxTimePerRun);
380: }
381: }
382: PetscFunctionReturn(PETSC_SUCCESS);
383: }
385: static PetscErrorCode CleanupContext(AppCtx *user)
386: {
387: PetscFunctionBegin;
388: PetscCall(PetscFree(user->numComponents));
389: PetscCall(PetscFree(user->numDof));
390: PetscFunctionReturn(PETSC_SUCCESS);
391: }
393: int main(int argc, char **argv)
394: {
395: DM dm;
396: AppCtx user;
398: PetscFunctionBeginUser;
399: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
400: PetscCall(ProcessOptions(&user));
401: PetscCall(PetscLogDefaultBegin());
402: PetscCall(CreateMesh(PETSC_COMM_WORLD, &user, &dm));
403: PetscCall(TestCone(dm, &user));
404: PetscCall(TestTransitiveClosure(dm, &user));
405: PetscCall(TestVecClosure(dm, PETSC_FALSE, PETSC_FALSE, &user));
406: PetscCall(TestVecClosure(dm, PETSC_TRUE, PETSC_FALSE, &user));
407: if (!user.cellSimplex && user.spectral) {
408: PetscCall(TestVecClosure(dm, PETSC_FALSE, PETSC_TRUE, &user));
409: PetscCall(TestVecClosure(dm, PETSC_TRUE, PETSC_TRUE, &user));
410: }
411: PetscCall(DMDestroy(&dm));
412: PetscCall(CleanupContext(&user));
413: PetscCall(PetscFinalize());
414: return 0;
415: }
417: /*TEST
419: build:
420: requires: defined(PETSC_USE_LOG)
422: # 2D Simplex P_1 scalar tests
423: testset:
424: args: -num_dof 1,0,0 -iterations 2 -print_times
425: test:
426: suffix: correctness_0
427: test:
428: suffix: correctness_1
429: args: -interpolate -dm_refine 2
430: test:
431: suffix: correctness_2
432: requires: triangle
433: args: -interpolate -dm_refine 5
434: test:
435: suffix: 0
436: TODO: Only for performance testing
437: args: -num_dof 1,0,0 -iterations 10000 -max_cone_time 1.1e-8 -max_closure_time 1.3e-7 -max_vec_closure_time 3.6e-7
438: test:
439: suffix: 1
440: requires: triangle
441: TODO: Only for performance testing
442: args: -refinement_limit 1.0e-5 -num_dof 1,0,0 -iterations 2 -max_cone_time 2.1e-8 -max_closure_time 1.5e-7 -max_vec_closure_time 3.6e-7
443: test:
444: suffix: 2
445: TODO: Only for performance testing
446: args: -num_fields 1 -num_components 1 -num_dof 1,0,0 -iterations 10000 -max_cone_time 1.1e-8 -max_closure_time 1.3e-7 -max_vec_closure_time 4.5e-7
447: test:
448: suffix: 3
449: requires: triangle
450: TODO: Only for performance testing
451: args: -refinement_limit 1.0e-5 -num_fields 1 -num_components 1 -num_dof 1,0,0 -iterations 2 -max_cone_time 2.1e-8 -max_closure_time 1.5e-7 -max_vec_closure_time 4.7e-7
452: test:
453: suffix: 4
454: TODO: Only for performance testing
455: args: -interpolate -num_dof 1,0,0 -iterations 10000 -max_cone_time 1.1e-8 -max_closure_time 6.5e-7 -max_vec_closure_time 1.0e-6
456: test:
457: suffix: 5
458: requires: triangle
459: TODO: Only for performance testing
460: args: -interpolate -refinement_limit 1.0e-4 -num_dof 1,0,0 -iterations 2 -max_cone_time 2.1e-8 -max_closure_time 6.5e-7 -max_vec_closure_time 1.0e-6
461: test:
462: suffix: 6
463: TODO: Only for performance testing
464: args: -interpolate -num_fields 1 -num_components 1 -num_dof 1,0,0 -iterations 10000 -max_cone_time 1.1e-8 -max_closure_time 6.5e-7 -max_vec_closure_time 1.1e-6
465: test:
466: suffix: 7
467: requires: triangle
468: TODO: Only for performance testing
469: args: -interpolate -refinement_limit 1.0e-4 -num_fields 1 -num_components 1 -num_dof 1,0,0 -iterations 2 -max_cone_time 2.1e-8 -max_closure_time 6.5e-7 -max_vec_closure_time 1.2e-6
471: # 2D Simplex P_1 vector tests
472: # 2D Simplex P_2 scalar tests
473: # 2D Simplex P_2 vector tests
474: # 2D Simplex P_2/P_1 vector/scalar tests
475: # 2D Quad P_1 scalar tests
476: # 2D Quad P_1 vector tests
477: # 2D Quad P_2 scalar tests
478: # 2D Quad P_2 vector tests
479: # 3D Simplex P_1 scalar tests
480: # 3D Simplex P_1 vector tests
481: # 3D Simplex P_2 scalar tests
482: # 3D Simplex P_2 vector tests
483: # 3D Hex P_1 scalar tests
484: # 3D Hex P_1 vector tests
485: # 3D Hex P_2 scalar tests
486: # 3D Hex P_2 vector tests
488: TEST*/