@@ -105,6 +105,7 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo
105105 // Empty case - won't occur
106106 break ;
107107 }
108+ CeedCallBackend (CeedElemRestrictionDestroy (& rstr ));
108109 CeedCallBackend (CeedElemRestrictionCreateVector (block_rstr [i + start_e ], NULL , & e_vecs_full [i + start_e ]));
109110 }
110111
@@ -122,6 +123,7 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo
122123 CeedCallBackend (CeedQFunctionFieldGetSize (qf_fields [i ], & size ));
123124 CeedCallBackend (CeedBasisGetNumNodes (basis , & P ));
124125 CeedCallBackend (CeedBasisGetNumComponents (basis , & num_comp ));
126+ CeedCallBackend (CeedBasisDestroy (& basis ));
125127 e_size = (CeedSize )P * num_comp * block_size ;
126128 CeedCallBackend (CeedVectorCreate (ceed , e_size , & e_vecs [i ]));
127129 q_size = (CeedSize )Q * size * block_size ;
@@ -132,6 +134,7 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo
132134 q_size = (CeedSize )Q * block_size ;
133135 CeedCallBackend (CeedVectorCreate (ceed , q_size , & q_vecs [i ]));
134136 CeedCallBackend (CeedBasisApply (basis , block_size , CEED_NOTRANSPOSE , CEED_EVAL_WEIGHT , CEED_VECTOR_NONE , q_vecs [i ]));
137+ CeedCallBackend (CeedBasisDestroy (& basis ));
135138 break ;
136139 }
137140 }
@@ -154,7 +157,11 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo
154157 CeedCallBackend (CeedVectorReferenceCopy (e_vecs_full [i + start_e ], & e_vecs_full [j + start_e ]));
155158 skip_rstr [j ] = true;
156159 }
160+ CeedCallBackend (CeedVectorDestroy (& vec_j ));
161+ CeedCallBackend (CeedElemRestrictionDestroy (& rstr_j ));
157162 }
163+ CeedCallBackend (CeedVectorDestroy (& vec_i ));
164+ CeedCallBackend (CeedElemRestrictionDestroy (& rstr_i ));
158165 }
159166 } else {
160167 for (CeedInt i = num_fields - 1 ; i >= 0 ; i -- ) {
@@ -176,7 +183,11 @@ static int CeedOperatorSetupFields_Blocked(CeedQFunction qf, CeedOperator op, bo
176183 apply_add_basis [i ] = true;
177184 e_data_out_indices [j ] = i ;
178185 }
186+ CeedCallBackend (CeedVectorDestroy (& vec_j ));
187+ CeedCallBackend (CeedElemRestrictionDestroy (& rstr_j ));
179188 }
189+ CeedCallBackend (CeedVectorDestroy (& vec_i ));
190+ CeedCallBackend (CeedElemRestrictionDestroy (& rstr_i ));
180191 }
181192 }
182193 return CEED_ERROR_SUCCESS ;
@@ -259,13 +270,15 @@ static inline int CeedOperatorSetupInputs_Blocked(CeedInt num_input_fields, Ceed
259270 CeedVector in_vec , bool skip_active , CeedScalar * e_data_full [2 * CEED_FIELD_MAX ],
260271 CeedOperator_Blocked * impl , CeedRequest * request ) {
261272 for (CeedInt i = 0 ; i < num_input_fields ; i ++ ) {
273+ bool is_active ;
262274 uint64_t state ;
263275 CeedEvalMode eval_mode ;
264276 CeedVector vec ;
265277
266278 // Get input vector
267279 CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
268- if (vec == CEED_VECTOR_ACTIVE ) {
280+ is_active = vec == CEED_VECTOR_ACTIVE ;
281+ if (is_active ) {
269282 if (skip_active ) continue ;
270283 else vec = in_vec ;
271284 }
@@ -282,6 +295,7 @@ static inline int CeedOperatorSetupInputs_Blocked(CeedInt num_input_fields, Ceed
282295 // Get evec
283296 CeedCallBackend (CeedVectorGetArrayRead (impl -> e_vecs_full [i ], CEED_MEM_HOST , (const CeedScalar * * )& e_data_full [i ]));
284297 }
298+ if (!is_active ) CeedCallBackend (CeedVectorDestroy (& vec ));
285299 }
286300 return CEED_ERROR_SUCCESS ;
287301}
@@ -300,15 +314,19 @@ static inline int CeedOperatorInputBasis_Blocked(CeedInt e, CeedInt Q, CeedQFunc
300314
301315 // Skip active input
302316 if (skip_active ) {
317+ bool is_active ;
303318 CeedVector vec ;
304319
305320 CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
306- if (vec == CEED_VECTOR_ACTIVE ) continue ;
321+ is_active = vec == CEED_VECTOR_ACTIVE ;
322+ CeedCallBackend (CeedVectorDestroy (& vec ));
323+ if (is_active ) continue ;
307324 }
308325
309326 // Get elem_size, eval_mode, size
310327 CeedCallBackend (CeedOperatorFieldGetElemRestriction (op_input_fields [i ], & elem_rstr ));
311328 CeedCallBackend (CeedElemRestrictionGetElementSize (elem_rstr , & elem_size ));
329+ CeedCallBackend (CeedElemRestrictionDestroy (& elem_rstr ));
312330 CeedCallBackend (CeedQFunctionFieldGetEvalMode (qf_input_fields [i ], & eval_mode ));
313331 CeedCallBackend (CeedQFunctionFieldGetSize (qf_input_fields [i ], & size ));
314332 // Basis action
@@ -324,6 +342,7 @@ static inline int CeedOperatorInputBasis_Blocked(CeedInt e, CeedInt Q, CeedQFunc
324342 CeedCallBackend (CeedBasisGetNumComponents (basis , & num_comp ));
325343 CeedCallBackend (CeedVectorSetArray (impl -> e_vecs_in [i ], CEED_MEM_HOST , CEED_USE_POINTER , & e_data_full [i ][(CeedSize )e * elem_size * num_comp ]));
326344 CeedCallBackend (CeedBasisApply (basis , block_size , CEED_NOTRANSPOSE , eval_mode , impl -> e_vecs_in [i ], impl -> q_vecs_in [i ]));
345+ CeedCallBackend (CeedBasisDestroy (& basis ));
327346 break ;
328347 case CEED_EVAL_WEIGHT :
329348 break ; // No action
@@ -347,6 +366,7 @@ static inline int CeedOperatorOutputBasis_Blocked(CeedInt e, CeedInt Q, CeedQFun
347366 // Get elem_size, eval_mode, size
348367 CeedCallBackend (CeedOperatorFieldGetElemRestriction (op_output_fields [i ], & elem_rstr ));
349368 CeedCallBackend (CeedElemRestrictionGetElementSize (elem_rstr , & elem_size ));
369+ CeedCallBackend (CeedElemRestrictionDestroy (& elem_rstr ));
350370 CeedCallBackend (CeedQFunctionFieldGetEvalMode (qf_output_fields [i ], & eval_mode ));
351371 // Basis action
352372 switch (eval_mode ) {
@@ -365,6 +385,7 @@ static inline int CeedOperatorOutputBasis_Blocked(CeedInt e, CeedInt Q, CeedQFun
365385 } else {
366386 CeedCallBackend (CeedBasisApply (basis , block_size , CEED_TRANSPOSE , eval_mode , impl -> q_vecs_out [i ], impl -> e_vecs_out [i ]));
367387 }
388+ CeedCallBackend (CeedBasisDestroy (& basis ));
368389 break ;
369390 // LCOV_EXCL_START
370391 case CEED_EVAL_WEIGHT : {
@@ -386,10 +407,13 @@ static inline int CeedOperatorRestoreInputs_Blocked(CeedInt num_input_fields, Ce
386407
387408 // Skip active inputs
388409 if (skip_active ) {
410+ bool is_active ;
389411 CeedVector vec ;
390412
391413 CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
392- if (vec == CEED_VECTOR_ACTIVE ) continue ;
414+ is_active = vec == CEED_VECTOR_ACTIVE ;
415+ CeedCallBackend (CeedVectorDestroy (& vec ));
416+ if (is_active ) continue ;
393417 }
394418 CeedCallBackend (CeedQFunctionFieldGetEvalMode (qf_input_fields [i ], & eval_mode ));
395419 if (eval_mode == CEED_EVAL_WEIGHT ) { // Skip
@@ -470,18 +494,21 @@ static int CeedOperatorApplyAdd_Blocked(CeedOperator op, CeedVector in_vec, Ceed
470494
471495 // Output restriction
472496 for (CeedInt i = 0 ; i < num_output_fields ; i ++ ) {
497+ bool is_active ;
473498 CeedVector vec ;
474499
475500 if (impl -> skip_rstr_out [i ]) continue ;
476501 // Restore evec
477502 CeedCallBackend (CeedVectorRestoreArray (impl -> e_vecs_full [i + impl -> num_inputs ], & e_data_full [i + num_input_fields ]));
478503 // Get output vector
479504 CeedCallBackend (CeedOperatorFieldGetVector (op_output_fields [i ], & vec ));
505+ is_active = vec == CEED_VECTOR_ACTIVE ;
480506 // Active
481- if (vec == CEED_VECTOR_ACTIVE ) vec = out_vec ;
507+ if (is_active ) vec = out_vec ;
482508 // Restrict
483509 CeedCallBackend (
484510 CeedElemRestrictionApply (impl -> block_rstr [i + impl -> num_inputs ], CEED_TRANSPOSE , impl -> e_vecs_full [i + impl -> num_inputs ], vec , request ));
511+ if (!is_active ) CeedCallBackend (CeedVectorDestroy (& vec ));
485512 }
486513
487514 // Restore input arrays
@@ -533,14 +560,14 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Blocked(CeedOperator o
533560 CeedInt field_size ;
534561 CeedVector vec ;
535562
536- // Get input vector
537- CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
538563 // Check if active input
564+ CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
539565 if (vec == CEED_VECTOR_ACTIVE ) {
540566 CeedCallBackend (CeedQFunctionFieldGetSize (qf_input_fields [i ], & field_size ));
541567 CeedCallBackend (CeedVectorSetValue (impl -> q_vecs_in [i ], 0.0 ));
542568 qf_size_in += field_size ;
543569 }
570+ CeedCallBackend (CeedVectorDestroy (& vec ));
544571 }
545572 CeedCheck (qf_size_in > 0 , ceed , CEED_ERROR_BACKEND , "Cannot assemble QFunction without active inputs and outputs" );
546573 impl -> qf_size_in = qf_size_in ;
@@ -552,13 +579,13 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Blocked(CeedOperator o
552579 CeedInt field_size ;
553580 CeedVector vec ;
554581
555- // Get output vector
556- CeedCallBackend (CeedOperatorFieldGetVector (op_output_fields [i ], & vec ));
557582 // Check if active output
583+ CeedCallBackend (CeedOperatorFieldGetVector (op_output_fields [i ], & vec ));
558584 if (vec == CEED_VECTOR_ACTIVE ) {
559585 CeedCallBackend (CeedQFunctionFieldGetSize (qf_output_fields [i ], & field_size ));
560586 qf_size_out += field_size ;
561587 }
588+ CeedCallBackend (CeedVectorDestroy (& vec ));
562589 }
563590 CeedCheck (qf_size_out > 0 , ceed , CEED_ERROR_BACKEND , "Cannot assemble QFunction without active inputs and outputs" );
564591 impl -> qf_size_out = qf_size_out ;
@@ -601,13 +628,15 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Blocked(CeedOperator o
601628
602629 // Assemble QFunction
603630 for (CeedInt i = 0 ; i < num_input_fields ; i ++ ) {
631+ bool is_active ;
604632 CeedInt field_size ;
605633 CeedVector vec ;
606634
607- // Get input vector
608- CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
609635 // Check if active input
610- if (vec != CEED_VECTOR_ACTIVE ) continue ;
636+ CeedCallBackend (CeedOperatorFieldGetVector (op_input_fields [i ], & vec ));
637+ is_active = vec == CEED_VECTOR_ACTIVE ;
638+ CeedCallBackend (CeedVectorDestroy (& vec ));
639+ if (!is_active ) continue ;
611640 CeedCallBackend (CeedQFunctionFieldGetSize (qf_input_fields [i ], & field_size ));
612641 for (CeedInt field = 0 ; field < field_size ; field ++ ) {
613642 // Set current portion of input to 1.0
@@ -633,6 +662,7 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Blocked(CeedOperator o
633662 CeedCallBackend (CeedQFunctionFieldGetSize (qf_output_fields [out ], & field_size ));
634663 l_vec_array += field_size * Q * block_size ; // Advance the pointer by the size of the output
635664 }
665+ CeedCallBackend (CeedVectorDestroy (& vec ));
636666 }
637667 // Apply QFunction
638668 CeedCallBackend (CeedQFunctionApply (qf , Q * block_size , impl -> q_vecs_in , impl -> q_vecs_out ));
@@ -664,12 +694,12 @@ static inline int CeedOperatorLinearAssembleQFunctionCore_Blocked(CeedOperator o
664694 for (CeedInt out = 0 ; out < num_output_fields ; out ++ ) {
665695 CeedVector vec ;
666696
667- // Get output vector
668- CeedCallBackend (CeedOperatorFieldGetVector (op_output_fields [out ], & vec ));
669697 // Check if active output
698+ CeedCallBackend (CeedOperatorFieldGetVector (op_output_fields [out ], & vec ));
670699 if (vec == CEED_VECTOR_ACTIVE ) {
671700 CeedCallBackend (CeedVectorTakeArray (impl -> q_vecs_out [out ], CEED_MEM_HOST , NULL ));
672701 }
702+ CeedCallBackend (CeedVectorDestroy (& vec ));
673703 }
674704 }
675705
0 commit comments