1 #ifndef MAT_CEED_IMPL_H 2 #define MAT_CEED_IMPL_H 3 4 #include <ceed.h> 5 #include <petscdm.h> 6 #include <petscmat.h> 7 8 #if defined(__clang_analyzer__) 9 #define MATCEED_EXTERN extern 10 #elif defined(__cplusplus) 11 #define MATCEED_EXTERN extern "C" 12 #else 13 #define MATCEED_EXTERN extern 14 #endif 15 16 #if defined(__clang_analyzer__) 17 #define MATCEED_INTERN 18 #else 19 #define MATCEED_INTERN MATCEED_EXTERN __attribute__((visibility("hidden"))) 20 #endif 21 22 /** 23 @brief Calls a libCEED function and then checks the resulting error code. 24 If the error code is non-zero, then a PETSc error is set with the libCEED error message. 25 **/ 26 #define PetscCeedCall(ceed_, ...) \ 27 do { \ 28 int ierr_q_ = __VA_ARGS__; \ 29 if (ierr_q_ != CEED_ERROR_SUCCESS) { \ 30 const char *error_message; \ 31 CeedGetErrorMessage(ceed_, &error_message); \ 32 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "%s", error_message); \ 33 } \ 34 } while (0) 35 36 // MatCeed context for applying composite CeedOperator on a DM 37 typedef struct MatCeedContext_private *MatCeedContext; 38 struct MatCeedContext_private { 39 Ceed ceed; 40 char *name, *internal_mat_type; 41 PetscMemType mem_type; 42 PetscInt ref_count, num_mats_assembled_full, num_mats_assembled_pbd; 43 PetscBool is_destroyed, is_ceed_pbd_valid, is_ceed_vpbd_valid; 44 PetscLogEvent log_event_mult, log_event_mult_transpose; 45 DM dm_x, dm_y; 46 Mat *mats_assembled_full, *mats_assembled_pbd, mat_assembled_full_internal, mat_assembled_pbd_internal; 47 Vec X_loc, Y_loc_transpose; 48 CeedVector x_loc, y_loc, coo_values_full, coo_values_pbd; 49 CeedOperator op_mult, op_mult_transpose; 50 PetscLogDouble flops_mult, flops_mult_transpose; 51 }; 52 53 // Context data 54 MATCEED_INTERN PetscErrorCode MatCeedContextCreate(DM dm_x, DM dm_y, Vec X_loc, Vec Y_loc_transpose, CeedOperator op_mult, 55 CeedOperator op_mult_transpose, PetscLogEvent log_event_mult, 56 PetscLogEvent log_event_mult_transpose, MatCeedContext *ctx); 57 MATCEED_INTERN PetscErrorCode MatCeedContextReference(MatCeedContext ctx); 58 MATCEED_INTERN PetscErrorCode MatCeedContextReferenceCopy(MatCeedContext ctx, MatCeedContext *ctx_copy); 59 MATCEED_INTERN PetscErrorCode MatCeedContextDestroy(MatCeedContext ctx); 60 61 // Mat Ceed 62 MATCEED_INTERN PetscErrorCode MatGetDiagonal_Ceed(Mat A, Vec D); 63 MATCEED_INTERN PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y); 64 MATCEED_INTERN PetscErrorCode MatMultTranspose_Ceed(Mat A, Vec Y, Vec X); 65 66 extern PetscClassId MATCEED_CLASSID; 67 extern PetscLogEvent MATCEED_MULT, MATCEED_MULT_TRANSPOSE; 68 69 #endif // MAT_CEED_IMPL_H 70