+ *lb = datatype->lb;
+ *extent = datatype->ub - datatype->lb;
+ retval = MPI_SUCCESS;
+ }
+ return MPI_SUCCESS;
+}
+
+int smpi_datatype_copy(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype) {
+ int retval, count;
+
+ /* First check if we really have something to do */
+ if(recvcount == 0) {
+ retval = sendcount == 0 ? MPI_SUCCESS : MPI_ERR_TRUNCATE;
+ } else if(sendtype == recvtype) {
+ /* If same datatypes used, just copy. */
+ count = sendcount < recvcount ? sendcount : recvcount;
+ memcpy(recvbuf, sendbuf, smpi_datatype_size(sendtype) * count);
+ retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
+ } else {
+ /* FIXME: cases
+ * - If receive packed.
+ * - If send packed
+ * to be treated once we have the MPI_Pack things ...
+ **/
+ retval = MPI_SUCCESS;
+ }
+ return retval;
+}
+
+typedef struct s_smpi_mpi_op {
+ MPI_User_function* func;
+} s_smpi_mpi_op_t;
+
+#define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a)
+#define MIN_OP(a, b) (b) = (a) < (b) ? (a) : (b)
+#define SUM_OP(a, b) (b) += (a)
+#define PROD_OP(a, b) (b) *= (a)
+#define LAND_OP(a, b) (b) = (a) && (b)
+#define LOR_OP(a, b) (b) = (a) || (b)
+#define LXOR_OP(a, b) (b) = (!(a) && (b)) || ((a) && !(b))
+#define BAND_OP(a, b) (b) &= (a)
+#define BOR_OP(a, b) (b) |= (a)
+#define BXOR_OP(a, b) (b) ^= (a)
+#define MAXLOC_OP(a, b) (b) = (a.value) < (b.value) ? (b) : (a)
+#define MINLOC_OP(a, b) (b) = (a.value) < (b.value) ? (a) : (b)
+//TODO : MINLOC & MAXLOC
+
+#define APPLY_FUNC(a, b, length, type, func) \
+ { \
+ int i; \
+ type* x = (type*)(a); \
+ type* y = (type*)(b); \
+ for(i = 0; i < *(length); i++) { \
+ func(x[i], y[i]); \
+ } \
+ }
+
+static void max_func(void* a, void* b, int* length, MPI_Datatype* datatype) {
+ if(*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, MAX_OP);
+ } else if(*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, MAX_OP);
+ } else if(*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, MAX_OP);
+ } else if(*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
+ } else if(*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
+ } else if(*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
+ } else if(*datatype == MPI_FLOAT) {
+ APPLY_FUNC(a, b, length, float, MAX_OP);
+ } else if(*datatype == MPI_DOUBLE) {
+ APPLY_FUNC(a, b, length, double, MAX_OP);
+ } else if(*datatype == MPI_LONG_DOUBLE) {
+ APPLY_FUNC(a, b, length, long double, MAX_OP);
+ }
+}
+
+static void min_func(void* a, void* b, int* length, MPI_Datatype* datatype) {
+ if(*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, MIN_OP);
+ } else if(*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, MIN_OP);
+ } else if(*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, MIN_OP);
+ } else if(*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
+ } else if(*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
+ } else if(*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
+ } else if(*datatype == MPI_FLOAT) {
+ APPLY_FUNC(a, b, length, float, MIN_OP);
+ } else if(*datatype == MPI_DOUBLE) {
+ APPLY_FUNC(a, b, length, double, MIN_OP);
+ } else if(*datatype == MPI_LONG_DOUBLE) {
+ APPLY_FUNC(a, b, length, long double, MIN_OP);
+ }
+}
+
+static void sum_func(void* a, void* b, int* length, MPI_Datatype* datatype) {
+ if(*datatype == MPI_SHORT) {
+ APPLY_FUNC(a, b, length, short, SUM_OP);
+ } else if(*datatype == MPI_INT) {
+ APPLY_FUNC(a, b, length, int, SUM_OP);
+ } else if(*datatype == MPI_LONG) {
+ APPLY_FUNC(a, b, length, long, SUM_OP);
+ } else if(*datatype == MPI_UNSIGNED_SHORT) {
+ APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
+ } else if(*datatype == MPI_UNSIGNED) {
+ APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
+ } else if(*datatype == MPI_UNSIGNED_LONG) {
+ APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
+ } else if(*datatype == MPI_FLOAT) {
+ APPLY_FUNC(a, b, length, float, SUM_OP);
+ } else if(*datatype == MPI_DOUBLE) {
+ APPLY_FUNC(a, b, length, double, SUM_OP);
+ } else if(*datatype == MPI_LONG_DOUBLE) {
+ APPLY_FUNC(a, b, length, long double, SUM_OP);
+ } else if(*datatype == MPI_C_FLOAT_COMPLEX) {
+ APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
+ } else if(*datatype == MPI_C_DOUBLE_COMPLEX) {
+ APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
+ } else if(*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
+ APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
+ }
+}
+
+static void prod_func(void* a, void* b, int* length, MPI_Datatype* datatype) {
+ 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_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_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_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_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_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_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);