1 /* smpi_mpi_dt.c -- MPI primitives to handle datatypes */
2 /* FIXME: a very incomplete implementation */
4 /* Copyright (c) 2009, 2010. The SimGrid Team.
5 * All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
15 #include "smpi_mpi_dt_private.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi_dt, smpi,
18 "Logging specific to SMPI (datatype)");
20 #define CREATE_MPI_DATATYPE(name, type) \
21 static s_smpi_mpi_datatype_t mpi_##name = { \
22 sizeof(type), /* size */ \
23 0, /*was 1 has_subtype*/ \
25 sizeof(type), /* ub = lb + size */ \
26 DT_FLAG_BASIC, /* flags */ \
27 NULL /* pointer on extended struct*/ \
29 MPI_Datatype name = &mpi_##name;
32 //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC.
58 // Predefined data types
59 CREATE_MPI_DATATYPE(MPI_CHAR, char);
60 CREATE_MPI_DATATYPE(MPI_SHORT, short);
61 CREATE_MPI_DATATYPE(MPI_INT, int);
62 CREATE_MPI_DATATYPE(MPI_LONG, long);
63 CREATE_MPI_DATATYPE(MPI_LONG_LONG, long long);
64 CREATE_MPI_DATATYPE(MPI_SIGNED_CHAR, signed char);
65 CREATE_MPI_DATATYPE(MPI_UNSIGNED_CHAR, unsigned char);
66 CREATE_MPI_DATATYPE(MPI_UNSIGNED_SHORT, unsigned short);
67 CREATE_MPI_DATATYPE(MPI_UNSIGNED, unsigned int);
68 CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG, unsigned long);
69 CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG_LONG, unsigned long long);
70 CREATE_MPI_DATATYPE(MPI_FLOAT, float);
71 CREATE_MPI_DATATYPE(MPI_DOUBLE, double);
72 CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE, long double);
73 CREATE_MPI_DATATYPE(MPI_WCHAR, wchar_t);
74 CREATE_MPI_DATATYPE(MPI_C_BOOL, _Bool);
75 CREATE_MPI_DATATYPE(MPI_INT8_T, int8_t);
76 CREATE_MPI_DATATYPE(MPI_INT16_T, int16_t);
77 CREATE_MPI_DATATYPE(MPI_INT32_T, int32_t);
78 CREATE_MPI_DATATYPE(MPI_INT64_T, int64_t);
79 CREATE_MPI_DATATYPE(MPI_UINT8_T, uint8_t);
80 CREATE_MPI_DATATYPE(MPI_UINT16_T, uint16_t);
81 CREATE_MPI_DATATYPE(MPI_UINT32_T, uint32_t);
82 CREATE_MPI_DATATYPE(MPI_UINT64_T, uint64_t);
83 CREATE_MPI_DATATYPE(MPI_C_FLOAT_COMPLEX, float _Complex);
84 CREATE_MPI_DATATYPE(MPI_C_DOUBLE_COMPLEX, double _Complex);
85 CREATE_MPI_DATATYPE(MPI_C_LONG_DOUBLE_COMPLEX, long double _Complex);
86 CREATE_MPI_DATATYPE(MPI_AINT, MPI_Aint);
87 CREATE_MPI_DATATYPE(MPI_OFFSET, MPI_Offset);
89 CREATE_MPI_DATATYPE(MPI_FLOAT_INT, float_int);
90 CREATE_MPI_DATATYPE(MPI_LONG_INT, long_int);
91 CREATE_MPI_DATATYPE(MPI_DOUBLE_INT, double_int);
92 CREATE_MPI_DATATYPE(MPI_SHORT_INT, short_int);
93 CREATE_MPI_DATATYPE(MPI_2INT, int_int);
94 CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE_INT, long_double_int);
97 CREATE_MPI_DATATYPE(MPI_PTR, void*);
100 size_t smpi_datatype_size(MPI_Datatype datatype)
102 return datatype->size;
107 MPI_Aint smpi_datatype_lb(MPI_Datatype datatype)
112 MPI_Aint smpi_datatype_ub(MPI_Datatype datatype)
117 int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint * lb,
122 if ((datatype->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
123 retval = MPI_ERR_TYPE;
126 *extent = datatype->ub - datatype->lb;
127 retval = MPI_SUCCESS;
132 int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
133 void *recvbuf, int recvcount, MPI_Datatype recvtype)
137 /* First check if we really have something to do */
138 if (recvcount == 0) {
139 retval = sendcount == 0 ? MPI_SUCCESS : MPI_ERR_TRUNCATE;
141 /* FIXME: treat packed cases */
142 sendcount *= smpi_datatype_size(sendtype);
143 recvcount *= smpi_datatype_size(recvtype);
144 count = sendcount < recvcount ? sendcount : recvcount;
146 if(sendtype->has_subtype == 0 && recvtype->has_subtype == 0) {
147 memcpy(recvbuf, sendbuf, count);
149 else if (sendtype->has_subtype == 0)
151 s_smpi_subtype_t *subtype = recvtype->substruct;
152 subtype->unserialize( sendbuf, recvbuf,1, subtype);
154 else if (recvtype->has_subtype == 0)
156 s_smpi_subtype_t *subtype = sendtype->substruct;
157 subtype->serialize(sendbuf, recvbuf,1, subtype);
159 s_smpi_subtype_t *subtype = sendtype->substruct;
161 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)sendtype;
163 void * buf_tmp = malloc(count * type_c->size_oldtype);
165 subtype->serialize( sendbuf, buf_tmp,1, subtype);
166 subtype = recvtype->substruct;
167 subtype->unserialize(recvbuf, buf_tmp,1, subtype);
171 retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
178 * Copies noncontiguous data into contiguous memory.
179 * @param contiguous_vector - output vector
180 * @param noncontiguous_vector - input vector
181 * @param type - pointer contening :
182 * - stride - stride of between noncontiguous data
183 * - block_length - the width or height of blocked matrix
184 * - count - the number of rows of matrix
186 void serialize_vector( const void *noncontiguous_vector,
187 void *contiguous_vector,
191 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
193 char* contiguous_vector_char = (char*)contiguous_vector;
194 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
196 for (i = 0; i < type_c->block_count * count; i++) {
197 memcpy(contiguous_vector_char,
198 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
200 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
201 noncontiguous_vector_char += type_c->block_stride*type_c->size_oldtype;
205 * Copies contiguous data into noncontiguous memory.
206 * @param noncontiguous_vector - output vector
207 * @param contiguous_vector - input vector
208 * @param type - pointer contening :
209 * - stride - stride of between noncontiguous data
210 * - block_length - the width or height of blocked matrix
211 * - count - the number of rows of matrix
213 void unserialize_vector( const void *contiguous_vector,
214 void *noncontiguous_vector,
218 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
221 char* contiguous_vector_char = (char*)contiguous_vector;
222 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
224 for (i = 0; i < type_c->block_count * count; i++) {
225 memcpy(noncontiguous_vector_char,
226 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
228 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
229 noncontiguous_vector_char += type_c->block_stride*type_c->size_oldtype;
234 * Create a Sub type vector to be able to serialize and unserialize it
235 * the structre s_smpi_mpi_vector_t is derived from s_smpi_subtype which
236 * required the functions unserialize and serialize
239 s_smpi_mpi_vector_t* smpi_datatype_vector_create( int block_stride,
242 MPI_Datatype old_type,
244 s_smpi_mpi_vector_t *new_t= xbt_new(s_smpi_mpi_vector_t,1);
245 new_t->base.serialize = &serialize_vector;
246 new_t->base.unserialize = &unserialize_vector;
247 new_t->block_stride = block_stride;
248 new_t->block_length = block_length;
249 new_t->block_count = block_count;
250 new_t->old_type = old_type;
251 new_t->size_oldtype = size_oldtype;
255 void smpi_datatype_create(MPI_Datatype* new_type, int size, int has_subtype,
256 void *struct_type, int flags){
257 MPI_Datatype new_t= xbt_new(s_smpi_mpi_datatype_t,1);
259 new_t->has_subtype=has_subtype;
263 new_t->substruct=struct_type;
267 void smpi_datatype_free(MPI_Datatype* type){
271 int smpi_datatype_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type)
274 if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
275 retval = MPI_ERR_TYPE;
277 smpi_datatype_create(new_type, count *
278 smpi_datatype_size(old_type),1,NULL, DT_FLAG_CONTIGUOUS);
284 int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type)
287 if (blocklen<=0) return MPI_ERR_ARG;
288 if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
289 retval = MPI_ERR_TYPE;
291 if(stride != blocklen){
292 s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
296 smpi_datatype_size(old_type));
298 smpi_datatype_create(new_type, count * (blocklen) *
299 smpi_datatype_size(old_type),
305 /* in this situation the data are contignous thus it's not
306 * required to serialize and unserialize it*/
307 smpi_datatype_create(new_type, count * (blocklen) *
308 smpi_datatype_size(old_type),
318 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
321 if (blocklen<=0) return MPI_ERR_ARG;
322 if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
323 retval = MPI_ERR_TYPE;
325 /*FIXME: as for the vector the data should be serialized and
326 * unserialized moreover a structure derived from s_smpi_subtype should
328 smpi_datatype_create(new_type, count * ((blocklen *
329 smpi_datatype_size(old_type))+stride),
339 int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
344 for(i=0; i< count; i++){
347 size += blocklens[i];
349 if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
350 retval = MPI_ERR_TYPE;
352 /*FIXME: as for the vector the data should be serialized and
353 * unserialized moreover a structure derived from s_smpi_subtype should
355 smpi_datatype_create(new_type, (size) *
356 smpi_datatype_size(old_type),0, NULL, DT_FLAG_DATA);
362 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
367 for(i=0; i< count; i++){
370 size += blocklens[i];
372 if ((old_type->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED) {
373 retval = MPI_ERR_TYPE;
375 /*FIXME: as for the vector the data should be serialized and
376 * unserialized moreover a structure derived from s_smpi_subtype should
378 smpi_datatype_create(new_type,(size * smpi_datatype_size(old_type)), 0,NULL, DT_FLAG_DATA);
384 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type)
387 size_t size; //Khalid added this
390 for(i=0; i< count; i++){
393 if ((old_types[i]->flags & DT_FLAG_COMMITED) != DT_FLAG_COMMITED)
395 size += blocklens[i]*smpi_datatype_size(old_types[i]);
397 /*FIXME: as for the vector the data should be serialized and
398 * unserialized moreover a structure derived from s_smpi_subtype should
400 smpi_datatype_create(new_type, size,
406 void smpi_datatype_commit(MPI_Datatype *datatype)
408 (*datatype)->flags= ((*datatype)->flags | DT_FLAG_COMMITED);
411 typedef struct s_smpi_mpi_op {
412 MPI_User_function *func;
415 #define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a)
416 #define MIN_OP(a, b) (b) = (a) < (b) ? (a) : (b)
417 #define SUM_OP(a, b) (b) += (a)
418 #define PROD_OP(a, b) (b) *= (a)
419 #define LAND_OP(a, b) (b) = (a) && (b)
420 #define LOR_OP(a, b) (b) = (a) || (b)
421 #define LXOR_OP(a, b) (b) = (!(a) && (b)) || ((a) && !(b))
422 #define BAND_OP(a, b) (b) &= (a)
423 #define BOR_OP(a, b) (b) |= (a)
424 #define BXOR_OP(a, b) (b) ^= (a)
425 #define MAXLOC_OP(a, b) (b) = (a.value) < (b.value) ? (b) : (a)
426 #define MINLOC_OP(a, b) (b) = (a.value) < (b.value) ? (a) : (b)
427 //TODO : MINLOC & MAXLOC
429 #define APPLY_FUNC(a, b, length, type, func) \
432 type* x = (type*)(a); \
433 type* y = (type*)(b); \
434 for(i = 0; i < *(length); i++) { \
439 static void max_func(void *a, void *b, int *length,
440 MPI_Datatype * datatype)
442 if (*datatype == MPI_CHAR) {
443 APPLY_FUNC(a, b, length, char, MAX_OP);
444 } else if (*datatype == MPI_SHORT) {
445 APPLY_FUNC(a, b, length, short, MAX_OP);
446 } else if (*datatype == MPI_INT) {
447 APPLY_FUNC(a, b, length, int, MAX_OP);
448 } else if (*datatype == MPI_LONG) {
449 APPLY_FUNC(a, b, length, long, MAX_OP);
450 } else if (*datatype == MPI_UNSIGNED_SHORT) {
451 APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
452 } else if (*datatype == MPI_UNSIGNED) {
453 APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
454 } else if (*datatype == MPI_UNSIGNED_LONG) {
455 APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
456 } else if (*datatype == MPI_FLOAT) {
457 APPLY_FUNC(a, b, length, float, MAX_OP);
458 } else if (*datatype == MPI_DOUBLE) {
459 APPLY_FUNC(a, b, length, double, MAX_OP);
460 } else if (*datatype == MPI_LONG_DOUBLE) {
461 APPLY_FUNC(a, b, length, long double, MAX_OP);
465 static void min_func(void *a, void *b, int *length,
466 MPI_Datatype * datatype)
468 if (*datatype == MPI_CHAR) {
469 APPLY_FUNC(a, b, length, char, MIN_OP);
470 } else if (*datatype == MPI_SHORT) {
471 APPLY_FUNC(a, b, length, short, MIN_OP);
472 } else if (*datatype == MPI_INT) {
473 APPLY_FUNC(a, b, length, int, MIN_OP);
474 } else if (*datatype == MPI_LONG) {
475 APPLY_FUNC(a, b, length, long, MIN_OP);
476 } else if (*datatype == MPI_UNSIGNED_SHORT) {
477 APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
478 } else if (*datatype == MPI_UNSIGNED) {
479 APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
480 } else if (*datatype == MPI_UNSIGNED_LONG) {
481 APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
482 } else if (*datatype == MPI_FLOAT) {
483 APPLY_FUNC(a, b, length, float, MIN_OP);
484 } else if (*datatype == MPI_DOUBLE) {
485 APPLY_FUNC(a, b, length, double, MIN_OP);
486 } else if (*datatype == MPI_LONG_DOUBLE) {
487 APPLY_FUNC(a, b, length, long double, MIN_OP);
491 static void sum_func(void *a, void *b, int *length,
492 MPI_Datatype * datatype)
494 if (*datatype == MPI_CHAR) {
495 APPLY_FUNC(a, b, length, char, SUM_OP);
496 } else if (*datatype == MPI_SHORT) {
497 APPLY_FUNC(a, b, length, short, SUM_OP);
498 } else if (*datatype == MPI_INT) {
499 APPLY_FUNC(a, b, length, int, SUM_OP);
500 } else if (*datatype == MPI_LONG) {
501 APPLY_FUNC(a, b, length, long, SUM_OP);
502 } else if (*datatype == MPI_UNSIGNED_SHORT) {
503 APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
504 } else if (*datatype == MPI_UNSIGNED) {
505 APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
506 } else if (*datatype == MPI_UNSIGNED_LONG) {
507 APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
508 } else if (*datatype == MPI_FLOAT) {
509 APPLY_FUNC(a, b, length, float, SUM_OP);
510 } else if (*datatype == MPI_DOUBLE) {
511 APPLY_FUNC(a, b, length, double, SUM_OP);
512 } else if (*datatype == MPI_LONG_DOUBLE) {
513 APPLY_FUNC(a, b, length, long double, SUM_OP);
514 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
515 APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
516 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
517 APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
518 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
519 APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
523 static void prod_func(void *a, void *b, int *length,
524 MPI_Datatype * datatype)
526 if (*datatype == MPI_CHAR) {
527 APPLY_FUNC(a, b, length, char, PROD_OP);
528 } else if (*datatype == MPI_SHORT) {
529 APPLY_FUNC(a, b, length, short, PROD_OP);
530 } else if (*datatype == MPI_INT) {
531 APPLY_FUNC(a, b, length, int, PROD_OP);
532 } else if (*datatype == MPI_LONG) {
533 APPLY_FUNC(a, b, length, long, PROD_OP);
534 } else if (*datatype == MPI_UNSIGNED_SHORT) {
535 APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
536 } else if (*datatype == MPI_UNSIGNED) {
537 APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
538 } else if (*datatype == MPI_UNSIGNED_LONG) {
539 APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
540 } else if (*datatype == MPI_FLOAT) {
541 APPLY_FUNC(a, b, length, float, PROD_OP);
542 } else if (*datatype == MPI_DOUBLE) {
543 APPLY_FUNC(a, b, length, double, PROD_OP);
544 } else if (*datatype == MPI_LONG_DOUBLE) {
545 APPLY_FUNC(a, b, length, long double, PROD_OP);
546 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
547 APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
548 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
549 APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
550 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
551 APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
555 static void land_func(void *a, void *b, int *length,
556 MPI_Datatype * datatype)
558 if (*datatype == MPI_CHAR) {
559 APPLY_FUNC(a, b, length, char, LAND_OP);
560 } else if (*datatype == MPI_SHORT) {
561 APPLY_FUNC(a, b, length, short, LAND_OP);
562 } else if (*datatype == MPI_INT) {
563 APPLY_FUNC(a, b, length, int, LAND_OP);
564 } else if (*datatype == MPI_LONG) {
565 APPLY_FUNC(a, b, length, long, LAND_OP);
566 } else if (*datatype == MPI_UNSIGNED_SHORT) {
567 APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
568 } else if (*datatype == MPI_UNSIGNED) {
569 APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
570 } else if (*datatype == MPI_UNSIGNED_LONG) {
571 APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
572 } else if (*datatype == MPI_C_BOOL) {
573 APPLY_FUNC(a, b, length, _Bool, LAND_OP);
577 static void lor_func(void *a, void *b, int *length,
578 MPI_Datatype * datatype)
580 if (*datatype == MPI_CHAR) {
581 APPLY_FUNC(a, b, length, char, LOR_OP);
582 } else if (*datatype == MPI_SHORT) {
583 APPLY_FUNC(a, b, length, short, LOR_OP);
584 } else if (*datatype == MPI_INT) {
585 APPLY_FUNC(a, b, length, int, LOR_OP);
586 } else if (*datatype == MPI_LONG) {
587 APPLY_FUNC(a, b, length, long, LOR_OP);
588 } else if (*datatype == MPI_UNSIGNED_SHORT) {
589 APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
590 } else if (*datatype == MPI_UNSIGNED) {
591 APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
592 } else if (*datatype == MPI_UNSIGNED_LONG) {
593 APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
594 } else if (*datatype == MPI_C_BOOL) {
595 APPLY_FUNC(a, b, length, _Bool, LOR_OP);
599 static void lxor_func(void *a, void *b, int *length,
600 MPI_Datatype * datatype)
602 if (*datatype == MPI_CHAR) {
603 APPLY_FUNC(a, b, length, char, LXOR_OP);
604 } else if (*datatype == MPI_SHORT) {
605 APPLY_FUNC(a, b, length, short, LXOR_OP);
606 } else if (*datatype == MPI_INT) {
607 APPLY_FUNC(a, b, length, int, LXOR_OP);
608 } else if (*datatype == MPI_LONG) {
609 APPLY_FUNC(a, b, length, long, LXOR_OP);
610 } else if (*datatype == MPI_UNSIGNED_SHORT) {
611 APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
612 } else if (*datatype == MPI_UNSIGNED) {
613 APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
614 } else if (*datatype == MPI_UNSIGNED_LONG) {
615 APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
616 } else if (*datatype == MPI_C_BOOL) {
617 APPLY_FUNC(a, b, length, _Bool, LXOR_OP);
621 static void band_func(void *a, void *b, int *length,
622 MPI_Datatype * datatype)
624 if (*datatype == MPI_CHAR) {
625 APPLY_FUNC(a, b, length, char, BAND_OP);
627 if (*datatype == MPI_SHORT) {
628 APPLY_FUNC(a, b, length, short, BAND_OP);
629 } else if (*datatype == MPI_INT) {
630 APPLY_FUNC(a, b, length, int, BAND_OP);
631 } else if (*datatype == MPI_LONG) {
632 APPLY_FUNC(a, b, length, long, BAND_OP);
633 } else if (*datatype == MPI_UNSIGNED_SHORT) {
634 APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
635 } else if (*datatype == MPI_UNSIGNED) {
636 APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
637 } else if (*datatype == MPI_UNSIGNED_LONG) {
638 APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
639 } else if (*datatype == MPI_BYTE) {
640 APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
644 static void bor_func(void *a, void *b, int *length,
645 MPI_Datatype * datatype)
647 if (*datatype == MPI_CHAR) {
648 APPLY_FUNC(a, b, length, char, BOR_OP);
649 } else if (*datatype == MPI_SHORT) {
650 APPLY_FUNC(a, b, length, short, BOR_OP);
651 } else if (*datatype == MPI_INT) {
652 APPLY_FUNC(a, b, length, int, BOR_OP);
653 } else if (*datatype == MPI_LONG) {
654 APPLY_FUNC(a, b, length, long, BOR_OP);
655 } else if (*datatype == MPI_UNSIGNED_SHORT) {
656 APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
657 } else if (*datatype == MPI_UNSIGNED) {
658 APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
659 } else if (*datatype == MPI_UNSIGNED_LONG) {
660 APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
661 } else if (*datatype == MPI_BYTE) {
662 APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
666 static void bxor_func(void *a, void *b, int *length,
667 MPI_Datatype * datatype)
669 if (*datatype == MPI_CHAR) {
670 APPLY_FUNC(a, b, length, char, BXOR_OP);
671 } else if (*datatype == MPI_SHORT) {
672 APPLY_FUNC(a, b, length, short, BXOR_OP);
673 } else if (*datatype == MPI_INT) {
674 APPLY_FUNC(a, b, length, int, BXOR_OP);
675 } else if (*datatype == MPI_LONG) {
676 APPLY_FUNC(a, b, length, long, BXOR_OP);
677 } else if (*datatype == MPI_UNSIGNED_SHORT) {
678 APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
679 } else if (*datatype == MPI_UNSIGNED) {
680 APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
681 } else if (*datatype == MPI_UNSIGNED_LONG) {
682 APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
683 } else if (*datatype == MPI_BYTE) {
684 APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
688 static void minloc_func(void *a, void *b, int *length,
689 MPI_Datatype * datatype)
691 if (*datatype == MPI_FLOAT_INT) {
692 APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
693 } else if (*datatype == MPI_LONG_INT) {
694 APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
695 } else if (*datatype == MPI_DOUBLE_INT) {
696 APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
697 } else if (*datatype == MPI_SHORT_INT) {
698 APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
699 } else if (*datatype == MPI_2INT) {
700 APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
701 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
702 APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
706 static void maxloc_func(void *a, void *b, int *length,
707 MPI_Datatype * datatype)
709 if (*datatype == MPI_FLOAT_INT) {
710 APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
711 } else if (*datatype == MPI_LONG_INT) {
712 APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
713 } else if (*datatype == MPI_DOUBLE_INT) {
714 APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
715 } else if (*datatype == MPI_SHORT_INT) {
716 APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
717 } else if (*datatype == MPI_2INT) {
718 APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
719 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
720 APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
725 #define CREATE_MPI_OP(name, func) \
726 static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */ }; \
727 MPI_Op name = &mpi_##name;
729 CREATE_MPI_OP(MPI_MAX, max_func);
730 CREATE_MPI_OP(MPI_MIN, min_func);
731 CREATE_MPI_OP(MPI_SUM, sum_func);
732 CREATE_MPI_OP(MPI_PROD, prod_func);
733 CREATE_MPI_OP(MPI_LAND, land_func);
734 CREATE_MPI_OP(MPI_LOR, lor_func);
735 CREATE_MPI_OP(MPI_LXOR, lxor_func);
736 CREATE_MPI_OP(MPI_BAND, band_func);
737 CREATE_MPI_OP(MPI_BOR, bor_func);
738 CREATE_MPI_OP(MPI_BXOR, bxor_func);
739 CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
740 CREATE_MPI_OP(MPI_MINLOC, minloc_func);
742 MPI_Op smpi_op_new(MPI_User_function * function, int commute)
746 //FIXME: add commute param
747 op = xbt_new(s_smpi_mpi_op_t, 1);
752 void smpi_op_destroy(MPI_Op op)
757 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
758 MPI_Datatype * datatype)
760 op->func(invec, inoutvec, len, datatype);