+
+static void prod_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, PROD_OP);
+ } else if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, PROD_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, PROD_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, PROD_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
+ } else if (*datatype == MPI_FLOAT) {
+ APPLY_FUNC(a, b, length, float, PROD_OP);
+ } else if (*datatype == MPI_DOUBLE) {
+ APPLY_FUNC(a, b, length, double, PROD_OP);
+ } else if (*datatype == MPI_LONG_DOUBLE) {
+ APPLY_FUNC(a, b, length, long double, PROD_OP);
+ } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
+ APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
+ } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
+ APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
+ } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
+ APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
+ }
+}
+
+static void land_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, LAND_OP);
+ } else if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, LAND_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, LAND_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, LAND_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
+ } else if (*datatype == MPI_C_BOOL) {
+ APPLY_FUNC(a, b, length, _Bool, LAND_OP);
+ }
+}
+
+static void lor_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, LOR_OP);
+ } else if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, LOR_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, LOR_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, LOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
+ } else if (*datatype == MPI_C_BOOL) {
+ APPLY_FUNC(a, b, length, _Bool, LOR_OP);
+ }
+}
+
+static void lxor_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, LXOR_OP);
+ } else if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, LXOR_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, LXOR_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, LXOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
+ } else if (*datatype == MPI_C_BOOL) {
+ APPLY_FUNC(a, b, length, _Bool, LXOR_OP);
+ }
+}
+
+static void band_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, BAND_OP);
+ }
+ if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, BAND_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, BAND_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, BAND_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
+ } else if (*datatype == MPI_BYTE) {
+ APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
+ }
+}
+
+static void bor_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, BOR_OP);
+ } else if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, BOR_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, BOR_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, BOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
+ } else if (*datatype == MPI_BYTE) {
+ APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
+ }
+}
+
+static void bxor_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_CHAR) {
+ APPLY_FUNC(a, b, length, char, BXOR_OP);
+ } else if (*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, BXOR_OP);
+ } else if (*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, BXOR_OP);
+ } else if (*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, BXOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
+ } else if (*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
+ } else if (*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
+ } else if (*datatype == MPI_BYTE) {
+ APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
+ }
+}
+
+static void minloc_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_FLOAT_INT) {
+ APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
+ } else if (*datatype == MPI_LONG_INT) {
+ APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
+ } else if (*datatype == MPI_DOUBLE_INT) {
+ APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
+ } else if (*datatype == MPI_SHORT_INT) {
+ APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
+ } else if (*datatype == MPI_2INT) {
+ APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
+ } else if (*datatype == MPI_LONG_DOUBLE_INT) {
+ APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
+ } else if (*datatype == MPI_2FLOAT) {
+ APPLY_FUNC(a, b, length, float_float, MINLOC_OP);
+ } else if (*datatype == MPI_2DOUBLE) {
+ APPLY_FUNC(a, b, length, double_double, MINLOC_OP);
+ }
+}
+
+static void maxloc_func(void *a, void *b, int *length,
+ MPI_Datatype * datatype)
+{
+ if (*datatype == MPI_FLOAT_INT) {
+ APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
+ } else if (*datatype == MPI_LONG_INT) {
+ APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
+ } else if (*datatype == MPI_DOUBLE_INT) {
+ APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
+ } else if (*datatype == MPI_SHORT_INT) {
+ APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
+ } else if (*datatype == MPI_2INT) {
+ APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
+ } else if (*datatype == MPI_LONG_DOUBLE_INT) {
+ APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
+ } else if (*datatype == MPI_2FLOAT) {
+ APPLY_FUNC(a, b, length, float_float, MAXLOC_OP);
+ } else if (*datatype == MPI_2DOUBLE) {
+ APPLY_FUNC(a, b, length, double_double, MAXLOC_OP);
+ }
+}
+
+
+#define CREATE_MPI_OP(name, func) \
+ static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */ }; \
+MPI_Op name = &mpi_##name;
+
+CREATE_MPI_OP(MPI_MAX, max_func);
+CREATE_MPI_OP(MPI_MIN, min_func);
+CREATE_MPI_OP(MPI_SUM, sum_func);
+CREATE_MPI_OP(MPI_PROD, prod_func);
+CREATE_MPI_OP(MPI_LAND, land_func);
+CREATE_MPI_OP(MPI_LOR, lor_func);
+CREATE_MPI_OP(MPI_LXOR, lxor_func);
+CREATE_MPI_OP(MPI_BAND, band_func);
+CREATE_MPI_OP(MPI_BOR, bor_func);
+CREATE_MPI_OP(MPI_BXOR, bxor_func);
+CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
+CREATE_MPI_OP(MPI_MINLOC, minloc_func);
+
+MPI_Op smpi_op_new(MPI_User_function * function, int commute)
+{
+ MPI_Op op;
+
+ //FIXME: add commute param
+ op = xbt_new(s_smpi_mpi_op_t, 1);
+ op->func = function;
+ return op;
+}
+
+void smpi_op_destroy(MPI_Op op)
+{
+ xbt_free(op);
+}
+
+void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
+ MPI_Datatype * datatype)