+#define CHECK_ARGS(test, errcode,...)\
+ {\
+ if (test) {\
+ int error_code_ = (errcode);\
+ if (error_code_ != MPI_SUCCESS){\
+ XBT_WARN(__VA_ARGS__);\
+ }\
+ return error_code_;\
+ }\
+ }
+
+#define CHECK_INIT \
+ { \
+ int init_flag = 0; \
+ PMPI_Initialized(&init_flag); \
+ CHECK_ARGS(not init_flag, MPI_ERR_OTHER, "%s: MPI_Init was not called !", __func__) \
+ PMPI_Finalized(&init_flag); \
+ CHECK_ARGS(init_flag, MPI_ERR_OTHER, "%s: MPI_Finalize was already called !", __func__) \
+ }
+
+#define CHECK_VAL(num, val, err, value)\
+ CHECK_ARGS((value) == (val), (err),\
+ "%s: param %d %s cannot be %s", __func__, (num), _XBT_STRINGIFY(value), _XBT_STRINGIFY(val))
+
+#define CHECK_NULL(num,err,buf)\
+ CHECK_ARGS((buf) == nullptr, (err),\
+ "%s: param %d %s cannot be NULL", __func__, (num), _XBT_STRINGIFY(buf))
+
+#define CHECK_MPI_NULL(num, val, err, ptr)\
+ {\
+ CHECK_ARGS((ptr) == (val), (err),\
+ "%s: param %d %s cannot be %s", __func__, (num), _XBT_STRINGIFY(ptr), _XBT_STRINGIFY(val))\
+ CHECK_NULL(num, err, ptr)\