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;
31 #define CREATE_MPI_DATATYPE_NULL(name) \
32 static s_smpi_mpi_datatype_t mpi_##name = { \
34 0, /*was 1 has_subtype*/ \
36 0, /* ub = lb + size */ \
37 DT_FLAG_BASIC, /* flags */ \
38 NULL /* pointer on extended struct*/ \
40 MPI_Datatype name = &mpi_##name;
42 //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC.
76 // Predefined data types
77 CREATE_MPI_DATATYPE(MPI_CHAR, char);
78 CREATE_MPI_DATATYPE(MPI_SHORT, short);
79 CREATE_MPI_DATATYPE(MPI_INT, int);
80 CREATE_MPI_DATATYPE(MPI_LONG, long);
81 CREATE_MPI_DATATYPE(MPI_LONG_LONG, long long);
82 CREATE_MPI_DATATYPE(MPI_SIGNED_CHAR, signed char);
83 CREATE_MPI_DATATYPE(MPI_UNSIGNED_CHAR, unsigned char);
84 CREATE_MPI_DATATYPE(MPI_UNSIGNED_SHORT, unsigned short);
85 CREATE_MPI_DATATYPE(MPI_UNSIGNED, unsigned int);
86 CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG, unsigned long);
87 CREATE_MPI_DATATYPE(MPI_UNSIGNED_LONG_LONG, unsigned long long);
88 CREATE_MPI_DATATYPE(MPI_FLOAT, float);
89 CREATE_MPI_DATATYPE(MPI_DOUBLE, double);
90 CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE, long double);
91 CREATE_MPI_DATATYPE(MPI_WCHAR, wchar_t);
92 CREATE_MPI_DATATYPE(MPI_C_BOOL, _Bool);
93 CREATE_MPI_DATATYPE(MPI_INT8_T, int8_t);
94 CREATE_MPI_DATATYPE(MPI_INT16_T, int16_t);
95 CREATE_MPI_DATATYPE(MPI_INT32_T, int32_t);
96 CREATE_MPI_DATATYPE(MPI_INT64_T, int64_t);
97 CREATE_MPI_DATATYPE(MPI_UINT8_T, uint8_t);
98 CREATE_MPI_DATATYPE(MPI_UINT16_T, uint16_t);
99 CREATE_MPI_DATATYPE(MPI_UINT32_T, uint32_t);
100 CREATE_MPI_DATATYPE(MPI_UINT64_T, uint64_t);
101 CREATE_MPI_DATATYPE(MPI_C_FLOAT_COMPLEX, float _Complex);
102 CREATE_MPI_DATATYPE(MPI_C_DOUBLE_COMPLEX, double _Complex);
103 CREATE_MPI_DATATYPE(MPI_C_LONG_DOUBLE_COMPLEX, long double _Complex);
104 CREATE_MPI_DATATYPE(MPI_AINT, MPI_Aint);
105 CREATE_MPI_DATATYPE(MPI_OFFSET, MPI_Offset);
107 CREATE_MPI_DATATYPE(MPI_FLOAT_INT, float_int);
108 CREATE_MPI_DATATYPE(MPI_LONG_INT, long_int);
109 CREATE_MPI_DATATYPE(MPI_DOUBLE_INT, double_int);
110 CREATE_MPI_DATATYPE(MPI_SHORT_INT, short_int);
111 CREATE_MPI_DATATYPE(MPI_2INT, int_int);
112 CREATE_MPI_DATATYPE(MPI_2FLOAT, float_float);
113 CREATE_MPI_DATATYPE(MPI_2DOUBLE, double_double);
115 CREATE_MPI_DATATYPE(MPI_LONG_DOUBLE_INT, long_double_int);
117 CREATE_MPI_DATATYPE_NULL(MPI_UB);
118 CREATE_MPI_DATATYPE_NULL(MPI_LB);
119 CREATE_MPI_DATATYPE_NULL(MPI_PACKED);
121 CREATE_MPI_DATATYPE(MPI_PTR, void*);
124 size_t smpi_datatype_size(MPI_Datatype datatype)
126 return datatype->size;
131 MPI_Aint smpi_datatype_lb(MPI_Datatype datatype)
136 MPI_Aint smpi_datatype_ub(MPI_Datatype datatype)
141 int smpi_datatype_extent(MPI_Datatype datatype, MPI_Aint * lb,
145 *extent = datatype->ub - datatype->lb;
149 MPI_Aint smpi_datatype_get_extent(MPI_Datatype datatype){
150 return datatype->ub - datatype->lb;
153 int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
154 void *recvbuf, int recvcount, MPI_Datatype recvtype)
158 /* First check if we really have something to do */
159 if (recvcount == 0) {
160 retval = sendcount == 0 ? MPI_SUCCESS : MPI_ERR_TRUNCATE;
162 /* FIXME: treat packed cases */
163 sendcount *= smpi_datatype_size(sendtype);
164 recvcount *= smpi_datatype_size(recvtype);
165 count = sendcount < recvcount ? sendcount : recvcount;
167 if(sendtype->has_subtype == 0 && recvtype->has_subtype == 0) {
168 memcpy(recvbuf, sendbuf, count);
170 else if (sendtype->has_subtype == 0)
172 s_smpi_subtype_t *subtype = recvtype->substruct;
173 subtype->unserialize( sendbuf, recvbuf,1, subtype);
175 else if (recvtype->has_subtype == 0)
177 s_smpi_subtype_t *subtype = sendtype->substruct;
178 subtype->serialize(sendbuf, recvbuf,1, subtype);
180 s_smpi_subtype_t *subtype = sendtype->substruct;
182 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)sendtype;
184 void * buf_tmp = xbt_malloc(count * type_c->size_oldtype);
186 subtype->serialize( sendbuf, buf_tmp,1, subtype);
187 subtype = recvtype->substruct;
188 subtype->unserialize(recvbuf, buf_tmp,1, subtype);
192 retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
199 * Copies noncontiguous data into contiguous memory.
200 * @param contiguous_vector - output vector
201 * @param noncontiguous_vector - input vector
202 * @param type - pointer contening :
203 * - stride - stride of between noncontiguous data
204 * - block_length - the width or height of blocked matrix
205 * - count - the number of rows of matrix
207 void serialize_vector( const void *noncontiguous_vector,
208 void *contiguous_vector,
212 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
214 char* contiguous_vector_char = (char*)contiguous_vector;
215 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
217 for (i = 0; i < type_c->block_count * count; i++) {
218 if (type_c->old_type->has_subtype == 0)
219 memcpy(contiguous_vector_char,
220 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
222 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
223 contiguous_vector_char,
224 type_c->block_length,
225 type_c->old_type->substruct);
227 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
228 noncontiguous_vector_char += type_c->block_stride*smpi_datatype_get_extent(type_c->old_type);
233 * Copies contiguous data into noncontiguous memory.
234 * @param noncontiguous_vector - output vector
235 * @param contiguous_vector - input vector
236 * @param type - pointer contening :
237 * - stride - stride of between noncontiguous data
238 * - block_length - the width or height of blocked matrix
239 * - count - the number of rows of matrix
241 void unserialize_vector( const void *contiguous_vector,
242 void *noncontiguous_vector,
246 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
249 char* contiguous_vector_char = (char*)contiguous_vector;
250 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
252 for (i = 0; i < type_c->block_count * count; i++) {
253 if (type_c->old_type->has_subtype == 0)
254 memcpy(noncontiguous_vector_char,
255 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
257 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
258 noncontiguous_vector_char,
259 type_c->block_length,
260 type_c->old_type->substruct);
261 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
262 noncontiguous_vector_char += type_c->block_stride*smpi_datatype_get_extent(type_c->old_type);
267 * Create a Sub type vector to be able to serialize and unserialize it
268 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
269 * required the functions unserialize and serialize
272 s_smpi_mpi_vector_t* smpi_datatype_vector_create( int block_stride,
275 MPI_Datatype old_type,
277 s_smpi_mpi_vector_t *new_t= xbt_new(s_smpi_mpi_vector_t,1);
278 new_t->base.serialize = &serialize_vector;
279 new_t->base.unserialize = &unserialize_vector;
280 new_t->base.subtype_free = &free_vector;
281 new_t->block_stride = block_stride;
282 new_t->block_length = block_length;
283 new_t->block_count = block_count;
284 new_t->old_type = old_type;
285 new_t->size_oldtype = size_oldtype;
289 void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int has_subtype,
290 void *struct_type, int flags){
291 MPI_Datatype new_t= xbt_new(s_smpi_mpi_datatype_t,1);
293 new_t->has_subtype = has_subtype;
296 new_t->flags = flags;
297 new_t->substruct = struct_type;
302 void smpi_datatype_free(MPI_Datatype* type){
304 if((*type)->flags & DT_FLAG_PREDEFINED)return;
306 //if still used, mark for deletion
307 if((*type)->in_use!=0){
308 (*type)->flags |=DT_FLAG_DESTROYED;
312 if ((*type)->has_subtype == 1){
313 ((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);
314 xbt_free((*type)->substruct);
320 void smpi_datatype_use(MPI_Datatype type){
321 if(type)type->in_use++;
325 void smpi_datatype_unuse(MPI_Datatype type){
326 if(type && type->in_use-- == 0 && (type->flags & DT_FLAG_DESTROYED))
327 smpi_datatype_free(&type);
330 int smpi_datatype_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type)
333 if(old_type->has_subtype){
334 //handle this case as a hvector with stride equals to the extent of the datatype
335 return smpi_datatype_hvector(count, 1, smpi_datatype_get_extent(old_type), old_type, new_type);
337 smpi_datatype_create(new_type,
338 count * smpi_datatype_size(old_type),
339 0,count * smpi_datatype_size(old_type),
340 0,NULL, DT_FLAG_CONTIGUOUS);
345 int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type)
348 if (blocklen<=0) return MPI_ERR_ARG;
352 lb=smpi_datatype_lb(old_type);
353 ub=((count-1)*stride+blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
355 if(old_type->has_subtype || stride != blocklen){
358 s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
362 smpi_datatype_size(old_type));
363 smpi_datatype_create(new_type,
364 count * (blocklen) * smpi_datatype_size(old_type), lb,
371 /* in this situation the data are contignous thus it's not
372 * required to serialize and unserialize it*/
373 smpi_datatype_create(new_type, count * blocklen *
374 smpi_datatype_size(old_type), 0, ((count -1) * stride + blocklen)*
375 smpi_datatype_size(old_type),
378 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
384 void free_vector(MPI_Datatype* d){
388 Hvector Implementation - Vector with stride in bytes
393 * Copies noncontiguous data into contiguous memory.
394 * @param contiguous_hvector - output hvector
395 * @param noncontiguous_hvector - input hvector
396 * @param type - pointer contening :
397 * - stride - stride of between noncontiguous data, in bytes
398 * - block_length - the width or height of blocked matrix
399 * - count - the number of rows of matrix
401 void serialize_hvector( const void *noncontiguous_hvector,
402 void *contiguous_hvector,
406 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
408 char* contiguous_vector_char = (char*)contiguous_hvector;
409 char* noncontiguous_vector_char = (char*)noncontiguous_hvector;
411 for (i = 0; i < type_c->block_count * count; i++) {
412 if (type_c->old_type->has_subtype == 0)
413 memcpy(contiguous_vector_char,
414 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
416 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
417 contiguous_vector_char,
418 type_c->block_length,
419 type_c->old_type->substruct);
421 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
422 noncontiguous_vector_char += type_c->block_stride;
426 * Copies contiguous data into noncontiguous memory.
427 * @param noncontiguous_vector - output hvector
428 * @param contiguous_vector - input hvector
429 * @param type - pointer contening :
430 * - stride - stride of between noncontiguous data, in bytes
431 * - block_length - the width or height of blocked matrix
432 * - count - the number of rows of matrix
434 void unserialize_hvector( const void *contiguous_vector,
435 void *noncontiguous_vector,
439 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
442 char* contiguous_vector_char = (char*)contiguous_vector;
443 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
445 for (i = 0; i < type_c->block_count * count; i++) {
446 if (type_c->old_type->has_subtype == 0)
447 memcpy(noncontiguous_vector_char,
448 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
450 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
451 noncontiguous_vector_char,
452 type_c->block_length,
453 type_c->old_type->substruct);
454 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
455 noncontiguous_vector_char += type_c->block_stride;
460 * Create a Sub type vector to be able to serialize and unserialize it
461 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
462 * required the functions unserialize and serialize
465 s_smpi_mpi_hvector_t* smpi_datatype_hvector_create( MPI_Aint block_stride,
468 MPI_Datatype old_type,
470 s_smpi_mpi_hvector_t *new_t= xbt_new(s_smpi_mpi_hvector_t,1);
471 new_t->base.serialize = &serialize_hvector;
472 new_t->base.unserialize = &unserialize_hvector;
473 new_t->base.subtype_free = &free_hvector;
474 new_t->block_stride = block_stride;
475 new_t->block_length = block_length;
476 new_t->block_count = block_count;
477 new_t->old_type = old_type;
478 new_t->size_oldtype = size_oldtype;
482 //do nothing for vector types
483 void free_hvector(MPI_Datatype* d){
486 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
489 if (blocklen<=0) return MPI_ERR_ARG;
493 lb=smpi_datatype_lb(old_type);
494 ub=((count-1)*stride)+(blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
496 if(old_type->has_subtype || stride != blocklen*smpi_datatype_get_extent(old_type)){
497 s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride,
501 smpi_datatype_size(old_type));
503 smpi_datatype_create(new_type, count * blocklen * smpi_datatype_size(old_type),
510 smpi_datatype_create(new_type, count * blocklen *
511 smpi_datatype_size(old_type),0,count * blocklen *
512 smpi_datatype_size(old_type),
515 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
523 Indexed Implementation
527 * Copies noncontiguous data into contiguous memory.
528 * @param contiguous_indexed - output indexed
529 * @param noncontiguous_indexed - input indexed
530 * @param type - pointer contening :
531 * - block_lengths - the width or height of blocked matrix
532 * - block_indices - indices of each data, in element
533 * - count - the number of rows of matrix
535 void serialize_indexed( const void *noncontiguous_indexed,
536 void *contiguous_indexed,
540 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
542 char* contiguous_indexed_char = (char*)contiguous_indexed;
543 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed;
544 for(j=0; j<count;j++){
545 for (i = 0; i < type_c->block_count; i++) {
546 if (type_c->old_type->has_subtype == 0)
547 memcpy(contiguous_indexed_char,
548 noncontiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
550 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_indexed_char,
551 contiguous_indexed_char,
552 type_c->block_lengths[i],
553 type_c->old_type->substruct);
556 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
557 if (i<type_c->block_count-1)noncontiguous_indexed_char = (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
558 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
560 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
564 * Copies contiguous data into noncontiguous memory.
565 * @param noncontiguous_indexed - output indexed
566 * @param contiguous_indexed - input indexed
567 * @param type - pointer contening :
568 * - block_lengths - the width or height of blocked matrix
569 * - block_indices - indices of each data, in element
570 * - count - the number of rows of matrix
572 void unserialize_indexed( const void *contiguous_indexed,
573 void *noncontiguous_indexed,
577 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
580 char* contiguous_indexed_char = (char*)contiguous_indexed;
581 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed;
582 for(j=0; j<count;j++){
583 for (i = 0; i < type_c->block_count; i++) {
584 if (type_c->old_type->has_subtype == 0)
585 memcpy(noncontiguous_indexed_char,
586 contiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
588 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_indexed_char,
589 noncontiguous_indexed_char,
590 type_c->block_lengths[i],
591 type_c->old_type->substruct);
593 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
594 if (i<type_c->block_count-1)
595 noncontiguous_indexed_char = (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
596 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
598 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
602 void free_indexed(MPI_Datatype* type){
603 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_lengths);
604 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_indices);
608 * Create a Sub type indexed to be able to serialize and unserialize it
609 * the structure s_smpi_mpi_indexed_t is derived from s_smpi_subtype which
610 * required the functions unserialize and serialize
612 s_smpi_mpi_indexed_t* smpi_datatype_indexed_create( int* block_lengths,
615 MPI_Datatype old_type,
617 s_smpi_mpi_indexed_t *new_t= xbt_new(s_smpi_mpi_indexed_t,1);
618 new_t->base.serialize = &serialize_indexed;
619 new_t->base.unserialize = &unserialize_indexed;
620 new_t->base.subtype_free = &free_indexed;
621 //TODO : add a custom function for each time to clean these
622 new_t->block_lengths= xbt_new(int, block_count);
623 new_t->block_indices= xbt_new(int, block_count);
625 for(i=0;i<block_count;i++){
626 new_t->block_lengths[i]=block_lengths[i];
627 new_t->block_indices[i]=block_indices[i];
629 new_t->block_count = block_count;
630 new_t->old_type = old_type;
631 new_t->size_oldtype = size_oldtype;
636 int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
645 lb=indices[0]*smpi_datatype_get_extent(old_type);
646 ub=indices[0]*smpi_datatype_get_extent(old_type) + blocklens[0]*smpi_datatype_ub(old_type);
649 for(i=0; i< count; i++){
652 size += blocklens[i];
654 if(indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type)<lb)
655 lb = indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type);
656 if(indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type)>ub)
657 ub = indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type);
659 if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )contiguous=0;
661 if (old_type->has_subtype == 1)
665 s_smpi_mpi_indexed_t* subtype = smpi_datatype_indexed_create( blocklens,
669 smpi_datatype_size(old_type));
670 smpi_datatype_create(new_type, size *
671 smpi_datatype_size(old_type),lb,ub,1, subtype, DT_FLAG_DATA);
673 smpi_datatype_create(new_type, size *
674 smpi_datatype_size(old_type),0,size *
675 smpi_datatype_size(old_type),0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
683 Hindexed Implementation - Indexed with indices in bytes
687 * Copies noncontiguous data into contiguous memory.
688 * @param contiguous_hindexed - output hindexed
689 * @param noncontiguous_hindexed - input hindexed
690 * @param type - pointer contening :
691 * - block_lengths - the width or height of blocked matrix
692 * - block_indices - indices of each data, in bytes
693 * - count - the number of rows of matrix
695 void serialize_hindexed( const void *noncontiguous_hindexed,
696 void *contiguous_hindexed,
700 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
702 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
703 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
704 for(j=0; j<count;j++){
705 for (i = 0; i < type_c->block_count; i++) {
706 if (type_c->old_type->has_subtype == 0)
707 memcpy(contiguous_hindexed_char,
708 noncontiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
710 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_hindexed_char,
711 contiguous_hindexed_char,
712 type_c->block_lengths[i],
713 type_c->old_type->substruct);
715 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
716 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
717 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
719 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
723 * Copies contiguous data into noncontiguous memory.
724 * @param noncontiguous_hindexed - output hindexed
725 * @param contiguous_hindexed - input hindexed
726 * @param type - pointer contening :
727 * - block_lengths - the width or height of blocked matrix
728 * - block_indices - indices of each data, in bytes
729 * - count - the number of rows of matrix
731 void unserialize_hindexed( const void *contiguous_hindexed,
732 void *noncontiguous_hindexed,
736 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
739 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
740 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
741 for(j=0; j<count;j++){
742 for (i = 0; i < type_c->block_count; i++) {
743 if (type_c->old_type->has_subtype == 0)
744 memcpy(noncontiguous_hindexed_char,
745 contiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
747 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_hindexed_char,
748 noncontiguous_hindexed_char,
749 type_c->block_lengths[i],
750 type_c->old_type->substruct);
752 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
753 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
754 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
756 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
760 void free_hindexed(MPI_Datatype* type){
761 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_lengths);
762 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_indices);
766 * Create a Sub type hindexed to be able to serialize and unserialize it
767 * the structure s_smpi_mpi_hindexed_t is derived from s_smpi_subtype which
768 * required the functions unserialize and serialize
770 s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths,
771 MPI_Aint* block_indices,
773 MPI_Datatype old_type,
775 s_smpi_mpi_hindexed_t *new_t= xbt_new(s_smpi_mpi_hindexed_t,1);
776 new_t->base.serialize = &serialize_hindexed;
777 new_t->base.unserialize = &unserialize_hindexed;
778 new_t->base.subtype_free = &free_hindexed;
779 //TODO : add a custom function for each time to clean these
780 new_t->block_lengths= xbt_new(int, block_count);
781 new_t->block_indices= xbt_new(MPI_Aint, block_count);
783 for(i=0;i<block_count;i++){
784 new_t->block_lengths[i]=block_lengths[i];
785 new_t->block_indices[i]=block_indices[i];
787 new_t->block_count = block_count;
788 new_t->old_type = old_type;
789 new_t->size_oldtype = size_oldtype;
794 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
803 lb=indices[0] + smpi_datatype_lb(old_type);
804 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_type);
806 for(i=0; i< count; i++){
809 size += blocklens[i];
811 if(indices[i]+smpi_datatype_lb(old_type)<lb) lb = indices[i]+smpi_datatype_lb(old_type);
812 if(indices[i]+blocklens[i]*smpi_datatype_ub(old_type)>ub) ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_type);
814 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_type) != indices[i+1]) )contiguous=0;
816 if (old_type->has_subtype == 1 || lb!=0)
820 s_smpi_mpi_hindexed_t* subtype = smpi_datatype_hindexed_create( blocklens,
824 smpi_datatype_size(old_type));
825 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
828 ,1, subtype, DT_FLAG_DATA);
830 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
831 0,size * smpi_datatype_size(old_type),
832 0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
840 struct Implementation - Indexed with indices in bytes
844 * Copies noncontiguous data into contiguous memory.
845 * @param contiguous_struct - output struct
846 * @param noncontiguous_struct - input struct
847 * @param type - pointer contening :
848 * - stride - stride of between noncontiguous data
849 * - block_length - the width or height of blocked matrix
850 * - count - the number of rows of matrix
852 void serialize_struct( const void *noncontiguous_struct,
853 void *contiguous_struct,
857 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
859 char* contiguous_struct_char = (char*)contiguous_struct;
860 char* noncontiguous_struct_char = (char*)noncontiguous_struct;
861 for(j=0; j<count;j++){
862 for (i = 0; i < type_c->block_count; i++) {
863 if (type_c->old_types[i]->has_subtype == 0)
864 memcpy(contiguous_struct_char,
865 noncontiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
867 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->serialize( noncontiguous_struct_char,
868 contiguous_struct_char,
869 type_c->block_lengths[i],
870 type_c->old_types[i]->substruct);
873 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
874 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
875 else noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);//let's hope this is MPI_UB ?
877 noncontiguous_struct=(void*)noncontiguous_struct_char;
881 * Copies contiguous data into noncontiguous memory.
882 * @param noncontiguous_struct - output struct
883 * @param contiguous_struct - input struct
884 * @param type - pointer contening :
885 * - stride - stride of between noncontiguous data
886 * - block_length - the width or height of blocked matrix
887 * - count - the number of rows of matrix
889 void unserialize_struct( const void *contiguous_struct,
890 void *noncontiguous_struct,
894 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
897 char* contiguous_struct_char = (char*)contiguous_struct;
898 char* noncontiguous_struct_char = (char*)noncontiguous_struct;
899 for(j=0; j<count;j++){
900 for (i = 0; i < type_c->block_count; i++) {
901 if (type_c->old_types[i]->has_subtype == 0)
902 memcpy(noncontiguous_struct_char,
903 contiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
905 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->unserialize( contiguous_struct_char,
906 noncontiguous_struct_char,
907 type_c->block_lengths[i],
908 type_c->old_types[i]->substruct);
910 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
911 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
912 else noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);
914 noncontiguous_struct=(void*)noncontiguous_struct_char;
919 void free_struct(MPI_Datatype* type){
920 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_lengths);
921 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_indices);
922 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types);
926 * Create a Sub type struct to be able to serialize and unserialize it
927 * the structure s_smpi_mpi_struct_t is derived from s_smpi_subtype which
928 * required the functions unserialize and serialize
930 s_smpi_mpi_struct_t* smpi_datatype_struct_create( int* block_lengths,
931 MPI_Aint* block_indices,
933 MPI_Datatype* old_types){
934 s_smpi_mpi_struct_t *new_t= xbt_new(s_smpi_mpi_struct_t,1);
935 new_t->base.serialize = &serialize_struct;
936 new_t->base.unserialize = &unserialize_struct;
937 new_t->base.subtype_free = &free_struct;
938 //TODO : add a custom function for each time to clean these
939 new_t->block_lengths= xbt_new(int, block_count);
940 new_t->block_indices= xbt_new(MPI_Aint, block_count);
941 new_t->old_types= xbt_new(MPI_Datatype, block_count);
943 for(i=0;i<block_count;i++){
944 new_t->block_lengths[i]=block_lengths[i];
945 new_t->block_indices[i]=block_indices[i];
946 new_t->old_types[i]=old_types[i];
948 //new_t->block_lengths = block_lengths;
949 //new_t->block_indices = block_indices;
950 new_t->block_count = block_count;
951 //new_t->old_types = old_types;
956 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type)
965 lb=indices[0] + smpi_datatype_lb(old_types[0]);
966 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_types[0]);
970 for(i=0; i< count; i++){
973 if (old_types[i]->has_subtype == 1)
976 size += blocklens[i]*smpi_datatype_size(old_types[i]);
977 if (old_types[i]==MPI_LB){
981 if (old_types[i]==MPI_UB){
986 if(!forced_lb && indices[i]+smpi_datatype_lb(old_types[i])<lb) lb = indices[i];
987 if(!forced_ub && indices[i]+blocklens[i]*smpi_datatype_ub(old_types[i])>ub) ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_types[i]);
989 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_types[i]) != indices[i+1]) )contiguous=0;
993 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens,
998 smpi_datatype_create(new_type, size, lb, ub,1, subtype, DT_FLAG_DATA);
1000 smpi_datatype_create(new_type, size, lb, ub,0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
1005 void smpi_datatype_commit(MPI_Datatype *datatype)
1007 (*datatype)->flags= ((*datatype)->flags | DT_FLAG_COMMITED);
1010 typedef struct s_smpi_mpi_op {
1011 MPI_User_function *func;
1014 #define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a)
1015 #define MIN_OP(a, b) (b) = (a) < (b) ? (a) : (b)
1016 #define SUM_OP(a, b) (b) += (a)
1017 #define PROD_OP(a, b) (b) *= (a)
1018 #define LAND_OP(a, b) (b) = (a) && (b)
1019 #define LOR_OP(a, b) (b) = (a) || (b)
1020 #define LXOR_OP(a, b) (b) = (!(a) && (b)) || ((a) && !(b))
1021 #define BAND_OP(a, b) (b) &= (a)
1022 #define BOR_OP(a, b) (b) |= (a)
1023 #define BXOR_OP(a, b) (b) ^= (a)
1024 #define MAXLOC_OP(a, b) (b) = (a.value) < (b.value) ? (b) : (a)
1025 #define MINLOC_OP(a, b) (b) = (a.value) < (b.value) ? (a) : (b)
1026 //TODO : MINLOC & MAXLOC
1028 #define APPLY_FUNC(a, b, length, type, func) \
1031 type* x = (type*)(a); \
1032 type* y = (type*)(b); \
1033 for(i = 0; i < *(length); i++) { \
1038 static void max_func(void *a, void *b, int *length,
1039 MPI_Datatype * datatype)
1041 if (*datatype == MPI_CHAR) {
1042 APPLY_FUNC(a, b, length, char, MAX_OP);
1043 } else if (*datatype == MPI_SHORT) {
1044 APPLY_FUNC(a, b, length, short, MAX_OP);
1045 } else if (*datatype == MPI_INT) {
1046 APPLY_FUNC(a, b, length, int, MAX_OP);
1047 } else if (*datatype == MPI_LONG) {
1048 APPLY_FUNC(a, b, length, long, MAX_OP);
1049 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1050 APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
1051 } else if (*datatype == MPI_UNSIGNED) {
1052 APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
1053 } else if (*datatype == MPI_UNSIGNED_LONG) {
1054 APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
1055 } else if (*datatype == MPI_FLOAT) {
1056 APPLY_FUNC(a, b, length, float, MAX_OP);
1057 } else if (*datatype == MPI_DOUBLE) {
1058 APPLY_FUNC(a, b, length, double, MAX_OP);
1059 } else if (*datatype == MPI_LONG_DOUBLE) {
1060 APPLY_FUNC(a, b, length, long double, MAX_OP);
1064 static void min_func(void *a, void *b, int *length,
1065 MPI_Datatype * datatype)
1067 if (*datatype == MPI_CHAR) {
1068 APPLY_FUNC(a, b, length, char, MIN_OP);
1069 } else if (*datatype == MPI_SHORT) {
1070 APPLY_FUNC(a, b, length, short, MIN_OP);
1071 } else if (*datatype == MPI_INT) {
1072 APPLY_FUNC(a, b, length, int, MIN_OP);
1073 } else if (*datatype == MPI_LONG) {
1074 APPLY_FUNC(a, b, length, long, MIN_OP);
1075 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1076 APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
1077 } else if (*datatype == MPI_UNSIGNED) {
1078 APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
1079 } else if (*datatype == MPI_UNSIGNED_LONG) {
1080 APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
1081 } else if (*datatype == MPI_FLOAT) {
1082 APPLY_FUNC(a, b, length, float, MIN_OP);
1083 } else if (*datatype == MPI_DOUBLE) {
1084 APPLY_FUNC(a, b, length, double, MIN_OP);
1085 } else if (*datatype == MPI_LONG_DOUBLE) {
1086 APPLY_FUNC(a, b, length, long double, MIN_OP);
1090 static void sum_func(void *a, void *b, int *length,
1091 MPI_Datatype * datatype)
1093 if (*datatype == MPI_CHAR) {
1094 APPLY_FUNC(a, b, length, char, SUM_OP);
1095 } else if (*datatype == MPI_SHORT) {
1096 APPLY_FUNC(a, b, length, short, SUM_OP);
1097 } else if (*datatype == MPI_INT) {
1098 APPLY_FUNC(a, b, length, int, SUM_OP);
1099 } else if (*datatype == MPI_LONG) {
1100 APPLY_FUNC(a, b, length, long, SUM_OP);
1101 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1102 APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
1103 } else if (*datatype == MPI_UNSIGNED) {
1104 APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
1105 } else if (*datatype == MPI_UNSIGNED_LONG) {
1106 APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
1107 } else if (*datatype == MPI_FLOAT) {
1108 APPLY_FUNC(a, b, length, float, SUM_OP);
1109 } else if (*datatype == MPI_DOUBLE) {
1110 APPLY_FUNC(a, b, length, double, SUM_OP);
1111 } else if (*datatype == MPI_LONG_DOUBLE) {
1112 APPLY_FUNC(a, b, length, long double, SUM_OP);
1113 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1114 APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
1115 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1116 APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
1117 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1118 APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
1122 static void prod_func(void *a, void *b, int *length,
1123 MPI_Datatype * datatype)
1125 if (*datatype == MPI_CHAR) {
1126 APPLY_FUNC(a, b, length, char, PROD_OP);
1127 } else if (*datatype == MPI_SHORT) {
1128 APPLY_FUNC(a, b, length, short, PROD_OP);
1129 } else if (*datatype == MPI_INT) {
1130 APPLY_FUNC(a, b, length, int, PROD_OP);
1131 } else if (*datatype == MPI_LONG) {
1132 APPLY_FUNC(a, b, length, long, PROD_OP);
1133 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1134 APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
1135 } else if (*datatype == MPI_UNSIGNED) {
1136 APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
1137 } else if (*datatype == MPI_UNSIGNED_LONG) {
1138 APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
1139 } else if (*datatype == MPI_FLOAT) {
1140 APPLY_FUNC(a, b, length, float, PROD_OP);
1141 } else if (*datatype == MPI_DOUBLE) {
1142 APPLY_FUNC(a, b, length, double, PROD_OP);
1143 } else if (*datatype == MPI_LONG_DOUBLE) {
1144 APPLY_FUNC(a, b, length, long double, PROD_OP);
1145 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1146 APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
1147 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1148 APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
1149 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1150 APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
1154 static void land_func(void *a, void *b, int *length,
1155 MPI_Datatype * datatype)
1157 if (*datatype == MPI_CHAR) {
1158 APPLY_FUNC(a, b, length, char, LAND_OP);
1159 } else if (*datatype == MPI_SHORT) {
1160 APPLY_FUNC(a, b, length, short, LAND_OP);
1161 } else if (*datatype == MPI_INT) {
1162 APPLY_FUNC(a, b, length, int, LAND_OP);
1163 } else if (*datatype == MPI_LONG) {
1164 APPLY_FUNC(a, b, length, long, LAND_OP);
1165 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1166 APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
1167 } else if (*datatype == MPI_UNSIGNED) {
1168 APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
1169 } else if (*datatype == MPI_UNSIGNED_LONG) {
1170 APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
1171 } else if (*datatype == MPI_C_BOOL) {
1172 APPLY_FUNC(a, b, length, _Bool, LAND_OP);
1176 static void lor_func(void *a, void *b, int *length,
1177 MPI_Datatype * datatype)
1179 if (*datatype == MPI_CHAR) {
1180 APPLY_FUNC(a, b, length, char, LOR_OP);
1181 } else if (*datatype == MPI_SHORT) {
1182 APPLY_FUNC(a, b, length, short, LOR_OP);
1183 } else if (*datatype == MPI_INT) {
1184 APPLY_FUNC(a, b, length, int, LOR_OP);
1185 } else if (*datatype == MPI_LONG) {
1186 APPLY_FUNC(a, b, length, long, LOR_OP);
1187 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1188 APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
1189 } else if (*datatype == MPI_UNSIGNED) {
1190 APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
1191 } else if (*datatype == MPI_UNSIGNED_LONG) {
1192 APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
1193 } else if (*datatype == MPI_C_BOOL) {
1194 APPLY_FUNC(a, b, length, _Bool, LOR_OP);
1198 static void lxor_func(void *a, void *b, int *length,
1199 MPI_Datatype * datatype)
1201 if (*datatype == MPI_CHAR) {
1202 APPLY_FUNC(a, b, length, char, LXOR_OP);
1203 } else if (*datatype == MPI_SHORT) {
1204 APPLY_FUNC(a, b, length, short, LXOR_OP);
1205 } else if (*datatype == MPI_INT) {
1206 APPLY_FUNC(a, b, length, int, LXOR_OP);
1207 } else if (*datatype == MPI_LONG) {
1208 APPLY_FUNC(a, b, length, long, LXOR_OP);
1209 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1210 APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
1211 } else if (*datatype == MPI_UNSIGNED) {
1212 APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
1213 } else if (*datatype == MPI_UNSIGNED_LONG) {
1214 APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
1215 } else if (*datatype == MPI_C_BOOL) {
1216 APPLY_FUNC(a, b, length, _Bool, LXOR_OP);
1220 static void band_func(void *a, void *b, int *length,
1221 MPI_Datatype * datatype)
1223 if (*datatype == MPI_CHAR) {
1224 APPLY_FUNC(a, b, length, char, BAND_OP);
1226 if (*datatype == MPI_SHORT) {
1227 APPLY_FUNC(a, b, length, short, BAND_OP);
1228 } else if (*datatype == MPI_INT) {
1229 APPLY_FUNC(a, b, length, int, BAND_OP);
1230 } else if (*datatype == MPI_LONG) {
1231 APPLY_FUNC(a, b, length, long, BAND_OP);
1232 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1233 APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
1234 } else if (*datatype == MPI_UNSIGNED) {
1235 APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
1236 } else if (*datatype == MPI_UNSIGNED_LONG) {
1237 APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
1238 } else if (*datatype == MPI_BYTE) {
1239 APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
1243 static void bor_func(void *a, void *b, int *length,
1244 MPI_Datatype * datatype)
1246 if (*datatype == MPI_CHAR) {
1247 APPLY_FUNC(a, b, length, char, BOR_OP);
1248 } else if (*datatype == MPI_SHORT) {
1249 APPLY_FUNC(a, b, length, short, BOR_OP);
1250 } else if (*datatype == MPI_INT) {
1251 APPLY_FUNC(a, b, length, int, BOR_OP);
1252 } else if (*datatype == MPI_LONG) {
1253 APPLY_FUNC(a, b, length, long, BOR_OP);
1254 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1255 APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
1256 } else if (*datatype == MPI_UNSIGNED) {
1257 APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
1258 } else if (*datatype == MPI_UNSIGNED_LONG) {
1259 APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
1260 } else if (*datatype == MPI_BYTE) {
1261 APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
1265 static void bxor_func(void *a, void *b, int *length,
1266 MPI_Datatype * datatype)
1268 if (*datatype == MPI_CHAR) {
1269 APPLY_FUNC(a, b, length, char, BXOR_OP);
1270 } else if (*datatype == MPI_SHORT) {
1271 APPLY_FUNC(a, b, length, short, BXOR_OP);
1272 } else if (*datatype == MPI_INT) {
1273 APPLY_FUNC(a, b, length, int, BXOR_OP);
1274 } else if (*datatype == MPI_LONG) {
1275 APPLY_FUNC(a, b, length, long, BXOR_OP);
1276 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1277 APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
1278 } else if (*datatype == MPI_UNSIGNED) {
1279 APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
1280 } else if (*datatype == MPI_UNSIGNED_LONG) {
1281 APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
1282 } else if (*datatype == MPI_BYTE) {
1283 APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
1287 static void minloc_func(void *a, void *b, int *length,
1288 MPI_Datatype * datatype)
1290 if (*datatype == MPI_FLOAT_INT) {
1291 APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
1292 } else if (*datatype == MPI_LONG_INT) {
1293 APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
1294 } else if (*datatype == MPI_DOUBLE_INT) {
1295 APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
1296 } else if (*datatype == MPI_SHORT_INT) {
1297 APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
1298 } else if (*datatype == MPI_2INT) {
1299 APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
1300 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1301 APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
1302 } else if (*datatype == MPI_2FLOAT) {
1303 APPLY_FUNC(a, b, length, float_float, MINLOC_OP);
1304 } else if (*datatype == MPI_2DOUBLE) {
1305 APPLY_FUNC(a, b, length, double_double, MINLOC_OP);
1309 static void maxloc_func(void *a, void *b, int *length,
1310 MPI_Datatype * datatype)
1312 if (*datatype == MPI_FLOAT_INT) {
1313 APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
1314 } else if (*datatype == MPI_LONG_INT) {
1315 APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
1316 } else if (*datatype == MPI_DOUBLE_INT) {
1317 APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
1318 } else if (*datatype == MPI_SHORT_INT) {
1319 APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
1320 } else if (*datatype == MPI_2INT) {
1321 APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
1322 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1323 APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
1324 } else if (*datatype == MPI_2FLOAT) {
1325 APPLY_FUNC(a, b, length, float_float, MAXLOC_OP);
1326 } else if (*datatype == MPI_2DOUBLE) {
1327 APPLY_FUNC(a, b, length, double_double, MAXLOC_OP);
1332 #define CREATE_MPI_OP(name, func) \
1333 static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */ }; \
1334 MPI_Op name = &mpi_##name;
1336 CREATE_MPI_OP(MPI_MAX, max_func);
1337 CREATE_MPI_OP(MPI_MIN, min_func);
1338 CREATE_MPI_OP(MPI_SUM, sum_func);
1339 CREATE_MPI_OP(MPI_PROD, prod_func);
1340 CREATE_MPI_OP(MPI_LAND, land_func);
1341 CREATE_MPI_OP(MPI_LOR, lor_func);
1342 CREATE_MPI_OP(MPI_LXOR, lxor_func);
1343 CREATE_MPI_OP(MPI_BAND, band_func);
1344 CREATE_MPI_OP(MPI_BOR, bor_func);
1345 CREATE_MPI_OP(MPI_BXOR, bxor_func);
1346 CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
1347 CREATE_MPI_OP(MPI_MINLOC, minloc_func);
1349 MPI_Op smpi_op_new(MPI_User_function * function, int commute)
1353 //FIXME: add commute param
1354 op = xbt_new(s_smpi_mpi_op_t, 1);
1355 op->func = function;
1359 void smpi_op_destroy(MPI_Op op)
1364 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
1365 MPI_Datatype * datatype)
1367 op->func(invec, inoutvec, len, datatype);