Lines Matching refs:ctx
16 static PetscErrorCode GetOptions(MPI_Comm comm, AppCtx *ctx) in GetOptions() argument
21 ctx->comm = comm; in GetOptions()
22 ctx->nsfs = 3; in GetOptions()
23 ctx->n = 1; in GetOptions()
24 ctx->leaveStep = 1; in GetOptions()
25 ctx->sparseLeaves = PETSC_FALSE; in GetOptions()
26 ctx->compare = PETSC_FALSE; in GetOptions()
27 ctx->irregular = PETSC_FALSE; in GetOptions()
28 ctx->rootMode = PETSCSF_CONCATENATE_ROOTMODE_LOCAL; in GetOptions()
29 ctx->viewer = NULL; in GetOptions()
30 PetscCall(PetscOptionsGetInt(NULL, NULL, "-nsfs", &ctx->nsfs, NULL)); in GetOptions()
31 PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &ctx->n, NULL)); in GetOptions()
32 PetscCall(PetscOptionsGetInt(NULL, NULL, "-leave_step", &ctx->leaveStep, NULL)); in GetOptions()
33 PetscCall(PetscOptionsGetBool(NULL, NULL, "-irregular", &ctx->irregular, NULL)); in GetOptions()
34 PetscCall(PetscOptionsGetBool(NULL, NULL, "-compare_to_reference", &ctx->compare, NULL)); in GetOptions()
35 …GetEnum(NULL, NULL, "-root_mode", PetscSFConcatenateRootModes, (PetscEnum *)&ctx->rootMode, NULL)); in GetOptions()
36 PetscCall(PetscOptionsCreateViewer(comm, NULL, NULL, "-sf_view", &ctx->viewer, &format, NULL)); in GetOptions()
37 if (ctx->viewer) PetscCall(PetscViewerPushFormat(ctx->viewer, format)); in GetOptions()
38 ctx->sparseLeaves = (PetscBool)(ctx->leaveStep != 1); in GetOptions()
39 PetscCallMPI(MPI_Comm_size(comm, &ctx->size)); in GetOptions()
40 PetscCallMPI(MPI_Comm_rank(comm, &ctx->rank)); in GetOptions()
126 PetscErrorCode CreateReferenceSF_Regular(AppCtx *ctx, PetscSF *refSF) in CreateReferenceSF_Regular() argument
130 PetscInt nLeaves = ctx->nsfs * ctx->n * ctx->size; in CreateReferenceSF_Regular()
131 PetscInt nroots = ctx->n * ctx->nsfs; in CreateReferenceSF_Regular()
136 if (ctx->sparseLeaves) PetscCall(PetscCalloc1(nLeaves + 1, &ilocal)); in CreateReferenceSF_Regular()
137 PetscCall(PetscSFCreate(ctx->comm, &sf)); in CreateReferenceSF_Regular()
139 if (ctx->sparseLeaves) ilocal[j + 1] = ilocal[j] + ctx->leaveStep; in CreateReferenceSF_Regular()
141 switch (ctx->rootMode) { in CreateReferenceSF_Regular()
149 for (i = 0, j = 0; i < ctx->nsfs; i++) { in CreateReferenceSF_Regular()
150 for (r = 0; r < ctx->size; r++) { in CreateReferenceSF_Regular()
151 for (k = 0; k < ctx->n; k++, j++) { in CreateReferenceSF_Regular()
153 iremote[j].index = k + i * ctx->n; in CreateReferenceSF_Regular()
163 PetscCall(PetscLayoutCreateFromSizes(ctx->comm, nroots, PETSC_DECIDE, 1, &map)); in CreateReferenceSF_Regular()
171 SETERRQ(ctx->comm, PETSC_ERR_SUP, "unsupported rootmode %d", ctx->rootMode); in CreateReferenceSF_Regular()
174 if (ctx->viewer) PetscCall(PetscSFViewCustom(sf, ctx->viewer)); in CreateReferenceSF_Regular()
179 PetscErrorCode CreateSFs_Irregular(AppCtx *ctx, PetscSF *newSFs[], PetscInt *leafOffsets[]) in CreateSFs_Irregular() argument
184 PetscInt nLeaves = ctx->n * ctx->size + (ctx->size - 1) * ctx->size / 2; in CreateSFs_Irregular()
185 PetscInt nroots = ctx->n + ctx->rank + ctx->nsfs - 1 + ctx->size - 1; in CreateSFs_Irregular()
188 if (ctx->sparseLeaves) PetscCall(PetscCalloc1(ctx->nsfs + 1, &lOffsets)); in CreateSFs_Irregular()
189 PetscCall(PetscMalloc1(ctx->nsfs, &sfs)); in CreateSFs_Irregular()
190 for (i = 0; i < ctx->nsfs; i++) { in CreateSFs_Irregular()
198 if (ctx->sparseLeaves) PetscCall(PetscCalloc1(nLeaves + 1, &ilocal)); in CreateSFs_Irregular()
200 for (r = ctx->size - 1, j = 0; r >= 0; r--) { in CreateSFs_Irregular()
201 for (k = 0; k < ctx->n + r; k++, j++) { in CreateSFs_Irregular()
202 if (ctx->sparseLeaves) ilocal[j + 1] = ilocal[j] + ctx->leaveStep; in CreateSFs_Irregular()
204 iremote[j].index = k + i + ctx->rank; in CreateSFs_Irregular()
207 if (ctx->sparseLeaves) lOffsets[i + 1] = lOffsets[i] + ilocal[j]; in CreateSFs_Irregular()
209 PetscCall(PetscSFCreate(ctx->comm, &sf)); in CreateSFs_Irregular()
213 if (ctx->viewer) PetscCall(PetscSFViewCustom(sf, ctx->viewer)); in CreateSFs_Irregular()
221 PetscErrorCode CreateSFs_Regular(AppCtx *ctx, PetscSF *newSFs[], PetscInt *leafOffsets[]) in CreateSFs_Regular() argument
225 PetscInt nLeaves = ctx->n * ctx->size; in CreateSFs_Regular()
227 …PetscSFConcatenateRootMode mode = ctx->compare ? ctx->rootMode : PETSCSF_CONCATENATE_ROOTMODE_LOCA… in CreateSFs_Regular()
230 if (ctx->sparseLeaves) PetscCall(PetscCalloc1(ctx->nsfs + 1, &lOffsets)); in CreateSFs_Regular()
231 PetscCall(PetscCalloc1(ctx->nsfs, &sfs)); in CreateSFs_Regular()
232 for (i = 0; i < ctx->nsfs; i++) { in CreateSFs_Regular()
238 PetscCall(PetscSFCreate(ctx->comm, &sf)); in CreateSFs_Regular()
239 if (ctx->sparseLeaves) { in CreateSFs_Regular()
241 for (j = 0; j < nLeaves; j++) ilocal[j + 1] = ilocal[j] + ctx->leaveStep; in CreateSFs_Regular()
246 PetscInt k, nroots = ctx->n; in CreateSFs_Regular()
251 for (r = 0, j = 0; r < ctx->size; r++) { in CreateSFs_Regular()
252 for (k = 0; k < ctx->n; k++, j++) { in CreateSFs_Regular()
260 PetscInt k, nroots = ctx->n * ctx->nsfs; in CreateSFs_Regular()
265 for (r = 0, j = 0; r < ctx->size; r++) { in CreateSFs_Regular()
266 for (k = 0; k < ctx->n; k++, j++) { in CreateSFs_Regular()
268 iremote[j].index = k + i * ctx->n; in CreateSFs_Regular()
274 PetscInt nroots = ctx->n; in CreateSFs_Regular()
278 PetscCall(PetscLayoutCreateFromSizes(ctx->comm, nroots, PETSC_DECIDE, 1, &map)); in CreateSFs_Regular()
286 SETERRQ(ctx->comm, PETSC_ERR_SUP, "unsupported rootmode %d", ctx->rootMode); in CreateSFs_Regular()
290 if (ctx->viewer) PetscCall(PetscSFViewCustom(sf, ctx->viewer)); in CreateSFs_Regular()
298 PetscErrorCode DestroySFs(AppCtx *ctx, PetscSF *sfs[]) in DestroySFs() argument
303 for (i = 0; i < ctx->nsfs; i++) PetscCall(PetscSFDestroy(&(*sfs)[i])); in DestroySFs()
311 AppCtx *ctx = &ctx_; in main() local
320 PetscCall(GetOptions(comm, ctx)); in main()
322 if (ctx->irregular) { in main()
323 PetscCall(CreateSFs_Irregular(ctx, &sfs, &leafOffsets)); in main()
325 PetscCall(CreateSFs_Regular(ctx, &sfs, &leafOffsets)); in main()
327 PetscCall(PetscSFConcatenate(comm, ctx->nsfs, sfs, ctx->rootMode, leafOffsets, &sf)); in main()
329 if (ctx->viewer) { in main()
330 PetscCall(PetscPrintf(comm, "rootMode = %s:\n", PetscSFConcatenateRootModes[ctx->rootMode])); in main()
331 PetscCall(PetscSFViewCustom(sf, ctx->viewer)); in main()
333 if (ctx->compare) { in main()
336 …PetscAssert(!ctx->irregular, comm, PETSC_ERR_SUP, "Combination -compare_to_reference true -irregu… in main()
337 PetscCall(CreateReferenceSF_Regular(ctx, &sfRef)); in main()
341 PetscCall(DestroySFs(ctx, &sfs)); in main()
344 if (ctx->viewer) { in main()
345 PetscCall(PetscViewerPopFormat(ctx->viewer)); in main()
346 PetscCall(PetscViewerDestroy(&ctx->viewer)); in main()