Skip to content

Commit

Permalink
ctx - require CeedQFGetCtx to be Destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Oct 23, 2024
1 parent 6a77f11 commit 17a955c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
2 changes: 2 additions & 0 deletions interface/ceed-fortran.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@ CEED_EXTERN void fCeedQFunctionSetContext(int *qf, int *ctx, int *err) {
if (*err) return;
fctxdata->inner_ctx = ctx_;
*err = CeedQFunctionContextRestoreData(fctx, (void **)&fctxdata);
if (*err) return;
*err = CeedQFunctionContextDestroy(&fctx);
}

#define fCeedQFunctionView FORTRAN_NAME(ceedqfunctionview, CEEDQFUNCTIONVIEW)
Expand Down
44 changes: 17 additions & 27 deletions interface/ceed-operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,22 @@ static int CeedOperatorContextSetGeneric(CeedOperator op, CeedContextFieldLabel
"Composite operator modified after ContextFieldLabel created");

for (CeedInt i = 0; i < num_sub; i++) {
CeedQFunction qf;
CeedQFunctionContext ctx;

CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf));
CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionDestroy(&qf));
CeedCall(CeedOperatorGetContext(sub_operators[i], &ctx));
// Try every sub-operator, ok if some sub-operators do not have field
if (field_label->sub_labels[i] && ctx) {
if (ctx && field_label->sub_labels[i]) {
CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label->sub_labels[i], field_type, values));
}
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
} else {
CeedQFunction qf;
CeedQFunctionContext ctx;

CeedCall(CeedOperatorGetQFunction(op, &qf));
CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionDestroy(&qf));
CeedCall(CeedOperatorGetContext(op, &ctx));
CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
CeedCall(CeedQFunctionContextSetGeneric(ctx, field_label, field_type, values));
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
CeedCall(CeedOperatorSetQFunctionAssemblyDataUpdateNeeded(op, true));
return CEED_ERROR_SUCCESS;
Expand Down Expand Up @@ -441,27 +437,24 @@ static int CeedOperatorContextGetGenericRead(CeedOperator op, CeedContextFieldLa
"Composite operator modified after ContextFieldLabel created");

for (CeedInt i = 0; i < num_sub; i++) {
CeedQFunction qf;
CeedQFunctionContext ctx;

CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf));
CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionDestroy(&qf));
CeedCall(CeedOperatorGetContext(sub_operators[i], &ctx));
// Try every sub-operator, ok if some sub-operators do not have field
if (field_label->sub_labels[i] && ctx) {
if (ctx && field_label->sub_labels[i]) {
CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label->sub_labels[i], field_type, num_values, values));
CeedCall(CeedQFunctionContextDestroy(&ctx));
return CEED_ERROR_SUCCESS;
}
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
} else {
CeedQFunction qf;
CeedQFunctionContext ctx;

CeedCall(CeedOperatorGetQFunction(op, &qf));
CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionDestroy(&qf));
CeedCall(CeedOperatorGetContext(op, &ctx));
CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
CeedCall(CeedQFunctionContextGetGenericRead(ctx, field_label, field_type, num_values, values));
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
return CEED_ERROR_SUCCESS;
}
Expand Down Expand Up @@ -507,27 +500,24 @@ static int CeedOperatorContextRestoreGenericRead(CeedOperator op, CeedContextFie
"Composite operator modified after ContextFieldLabel created");

for (CeedInt i = 0; i < num_sub; i++) {
CeedQFunction qf;
CeedQFunctionContext ctx;

CeedCall(CeedOperatorGetQFunction(sub_operators[i], &qf));
CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionDestroy(&qf));
CeedCall(CeedOperatorGetContext(sub_operators[i], &ctx));
// Try every sub-operator, ok if some sub-operators do not have field
if (field_label->sub_labels[i] && ctx) {
if (ctx && field_label->sub_labels[i]) {
CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label->sub_labels[i], field_type, values));
CeedCall(CeedQFunctionContextDestroy(&ctx));
return CEED_ERROR_SUCCESS;
}
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
} else {
CeedQFunction qf;
CeedQFunctionContext ctx;

CeedCall(CeedOperatorGetQFunction(op, &qf));
CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionDestroy(&qf));
CeedCall(CeedOperatorGetContext(op, &ctx));
CeedCheck(ctx, CeedOperatorReturnCeed(op), CEED_ERROR_UNSUPPORTED, "QFunction does not have context data");
CeedCall(CeedQFunctionContextRestoreGenericRead(ctx, field_label, field_type, values));
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
return CEED_ERROR_SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions interface/ceed-preconditioning.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static int CeedQFunctionCreateFallback(Ceed fallback_ceed, CeedQFunction qf, Cee

CeedCall(CeedQFunctionGetContext(qf, &ctx));
CeedCall(CeedQFunctionSetContext(*qf_fallback, ctx));
CeedCall(CeedQFunctionContextDestroy(&ctx));
}
CeedCall(CeedQFunctionGetFields(qf, &num_input_fields, &input_fields, &num_output_fields, &output_fields));
for (CeedInt i = 0; i < num_input_fields; i++) {
Expand Down
8 changes: 6 additions & 2 deletions interface/ceed-qfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ int CeedQFunctionGetUserFunction(CeedQFunction qf, CeedQFunctionUser *f) {
@ref Backend
**/
int CeedQFunctionGetContext(CeedQFunction qf, CeedQFunctionContext *ctx) {
*ctx = qf->ctx;
*ctx = NULL;
if (qf->ctx) CeedCall(CeedQFunctionContextReferenceCopy(qf->ctx, ctx));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -361,6 +362,7 @@ int CeedQFunctionGetContextData(CeedQFunction qf, CeedMemType mem_type, void *da
} else {
*(void **)data = NULL;
}
CeedCall(CeedQFunctionContextDestroy(&ctx));
return CEED_ERROR_SUCCESS;
}

Expand All @@ -387,7 +389,7 @@ int CeedQFunctionRestoreContextData(CeedQFunction qf, void *data) {
CeedCall(CeedQFunctionContextRestoreDataRead(ctx, data));
}
}
*(void **)data = NULL;
CeedCall(CeedQFunctionContextDestroy(&ctx));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -415,6 +417,7 @@ int CeedQFunctionGetInnerContext(CeedQFunction qf, CeedQFunctionContext *ctx) {
} else {
*ctx = qf_ctx;
}
CeedCall(CeedQFunctionContextDestroy(&qf_ctx));
return CEED_ERROR_SUCCESS;
}

Expand Down Expand Up @@ -730,6 +733,7 @@ int CeedQFunctionCreateIdentity(Ceed ceed, CeedInt size, CeedEvalMode in_mode, C
CeedCall(CeedQFunctionGetContext(*qf, &ctx));
CeedCall(CeedQFunctionContextGetFieldLabel(ctx, "size", &size_label));
CeedCall(CeedQFunctionContextSetInt32(ctx, size_label, &size));
CeedCall(CeedQFunctionContextDestroy(&ctx));
return CEED_ERROR_SUCCESS;
}

Expand Down

0 comments on commit 17a955c

Please sign in to comment.