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);
319 void smpi_datatype_use(MPI_Datatype type){
320 if(type)type->in_use++;
324 void smpi_datatype_unuse(MPI_Datatype type){
325 if(type && type->in_use-- == 0 && (type->flags & DT_FLAG_DESTROYED))
326 smpi_datatype_free(&type);
329 int smpi_datatype_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type)
332 if(old_type->has_subtype){
333 //handle this case as a hvector with stride equals to the extent of the datatype
334 return smpi_datatype_hvector(count, 1, smpi_datatype_get_extent(old_type), old_type, new_type);
336 smpi_datatype_create(new_type,
337 count * smpi_datatype_size(old_type),
338 0,count * smpi_datatype_size(old_type),
339 0,NULL, DT_FLAG_CONTIGUOUS);
344 int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type)
347 if (blocklen<=0) return MPI_ERR_ARG;
351 lb=smpi_datatype_lb(old_type);
352 ub=((count-1)*stride+blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
354 if(old_type->has_subtype || stride != blocklen){
357 s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
361 smpi_datatype_size(old_type));
362 smpi_datatype_create(new_type,
363 count * (blocklen) * smpi_datatype_size(old_type), lb,
370 /* in this situation the data are contignous thus it's not
371 * required to serialize and unserialize it*/
372 smpi_datatype_create(new_type, count * blocklen *
373 smpi_datatype_size(old_type), 0, ((count -1) * stride + blocklen)*
374 smpi_datatype_size(old_type),
377 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
383 void free_vector(MPI_Datatype* d){
387 Hvector Implementation - Vector with stride in bytes
392 * Copies noncontiguous data into contiguous memory.
393 * @param contiguous_hvector - output hvector
394 * @param noncontiguous_hvector - input hvector
395 * @param type - pointer contening :
396 * - stride - stride of between noncontiguous data, in bytes
397 * - block_length - the width or height of blocked matrix
398 * - count - the number of rows of matrix
400 void serialize_hvector( const void *noncontiguous_hvector,
401 void *contiguous_hvector,
405 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
407 char* contiguous_vector_char = (char*)contiguous_hvector;
408 char* noncontiguous_vector_char = (char*)noncontiguous_hvector;
410 for (i = 0; i < type_c->block_count * count; i++) {
411 if (type_c->old_type->has_subtype == 0)
412 memcpy(contiguous_vector_char,
413 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
415 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
416 contiguous_vector_char,
417 type_c->block_length,
418 type_c->old_type->substruct);
420 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
421 noncontiguous_vector_char += type_c->block_stride;
425 * Copies contiguous data into noncontiguous memory.
426 * @param noncontiguous_vector - output hvector
427 * @param contiguous_vector - input hvector
428 * @param type - pointer contening :
429 * - stride - stride of between noncontiguous data, in bytes
430 * - block_length - the width or height of blocked matrix
431 * - count - the number of rows of matrix
433 void unserialize_hvector( const void *contiguous_vector,
434 void *noncontiguous_vector,
438 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
441 char* contiguous_vector_char = (char*)contiguous_vector;
442 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
444 for (i = 0; i < type_c->block_count * count; i++) {
445 if (type_c->old_type->has_subtype == 0)
446 memcpy(noncontiguous_vector_char,
447 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
449 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
450 noncontiguous_vector_char,
451 type_c->block_length,
452 type_c->old_type->substruct);
453 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
454 noncontiguous_vector_char += type_c->block_stride;
459 * Create a Sub type vector to be able to serialize and unserialize it
460 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
461 * required the functions unserialize and serialize
464 s_smpi_mpi_hvector_t* smpi_datatype_hvector_create( MPI_Aint block_stride,
467 MPI_Datatype old_type,
469 s_smpi_mpi_hvector_t *new_t= xbt_new(s_smpi_mpi_hvector_t,1);
470 new_t->base.serialize = &serialize_hvector;
471 new_t->base.unserialize = &unserialize_hvector;
472 new_t->base.subtype_free = &free_hvector;
473 new_t->block_stride = block_stride;
474 new_t->block_length = block_length;
475 new_t->block_count = block_count;
476 new_t->old_type = old_type;
477 new_t->size_oldtype = size_oldtype;
481 //do nothing for vector types
482 void free_hvector(MPI_Datatype* d){
485 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
488 if (blocklen<=0) return MPI_ERR_ARG;
492 lb=smpi_datatype_lb(old_type);
493 ub=((count-1)*stride)+(blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
495 if(old_type->has_subtype || stride != blocklen*smpi_datatype_get_extent(old_type)){
496 s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride,
500 smpi_datatype_size(old_type));
502 smpi_datatype_create(new_type, count * blocklen * smpi_datatype_size(old_type),
509 smpi_datatype_create(new_type, count * blocklen *
510 smpi_datatype_size(old_type),0,count * blocklen *
511 smpi_datatype_size(old_type),
514 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
522 Indexed Implementation
526 * Copies noncontiguous data into contiguous memory.
527 * @param contiguous_indexed - output indexed
528 * @param noncontiguous_indexed - input indexed
529 * @param type - pointer contening :
530 * - block_lengths - the width or height of blocked matrix
531 * - block_indices - indices of each data, in element
532 * - count - the number of rows of matrix
534 void serialize_indexed( const void *noncontiguous_indexed,
535 void *contiguous_indexed,
539 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
541 char* contiguous_indexed_char = (char*)contiguous_indexed;
542 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed;
543 for(j=0; j<count;j++){
544 for (i = 0; i < type_c->block_count; i++) {
545 if (type_c->old_type->has_subtype == 0)
546 memcpy(contiguous_indexed_char,
547 noncontiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
549 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_indexed_char,
550 contiguous_indexed_char,
551 type_c->block_lengths[i],
552 type_c->old_type->substruct);
555 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
556 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);
557 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
559 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
563 * Copies contiguous data into noncontiguous memory.
564 * @param noncontiguous_indexed - output indexed
565 * @param contiguous_indexed - input indexed
566 * @param type - pointer contening :
567 * - block_lengths - the width or height of blocked matrix
568 * - block_indices - indices of each data, in element
569 * - count - the number of rows of matrix
571 void unserialize_indexed( const void *contiguous_indexed,
572 void *noncontiguous_indexed,
576 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
579 char* contiguous_indexed_char = (char*)contiguous_indexed;
580 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed;
581 for(j=0; j<count;j++){
582 for (i = 0; i < type_c->block_count; i++) {
583 if (type_c->old_type->has_subtype == 0)
584 memcpy(noncontiguous_indexed_char,
585 contiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
587 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_indexed_char,
588 noncontiguous_indexed_char,
589 type_c->block_lengths[i],
590 type_c->old_type->substruct);
592 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
593 if (i<type_c->block_count-1)
594 noncontiguous_indexed_char = (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
595 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
597 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
601 void free_indexed(MPI_Datatype* type){
602 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_lengths);
603 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_indices);
607 * Create a Sub type indexed to be able to serialize and unserialize it
608 * the structure s_smpi_mpi_indexed_t is derived from s_smpi_subtype which
609 * required the functions unserialize and serialize
611 s_smpi_mpi_indexed_t* smpi_datatype_indexed_create( int* block_lengths,
614 MPI_Datatype old_type,
616 s_smpi_mpi_indexed_t *new_t= xbt_new(s_smpi_mpi_indexed_t,1);
617 new_t->base.serialize = &serialize_indexed;
618 new_t->base.unserialize = &unserialize_indexed;
619 new_t->base.subtype_free = &free_indexed;
620 //TODO : add a custom function for each time to clean these
621 new_t->block_lengths= xbt_new(int, block_count);
622 new_t->block_indices= xbt_new(int, block_count);
624 for(i=0;i<block_count;i++){
625 new_t->block_lengths[i]=block_lengths[i];
626 new_t->block_indices[i]=block_indices[i];
628 new_t->block_count = block_count;
629 new_t->old_type = old_type;
630 new_t->size_oldtype = size_oldtype;
635 int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
644 lb=indices[0]*smpi_datatype_get_extent(old_type);
645 ub=indices[0]*smpi_datatype_get_extent(old_type) + blocklens[0]*smpi_datatype_ub(old_type);
648 for(i=0; i< count; i++){
651 size += blocklens[i];
653 if(indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type)<lb)
654 lb = indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type);
655 if(indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type)>ub)
656 ub = indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type);
658 if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )contiguous=0;
660 if (old_type->has_subtype == 1)
664 s_smpi_mpi_indexed_t* subtype = smpi_datatype_indexed_create( blocklens,
668 smpi_datatype_size(old_type));
669 smpi_datatype_create(new_type, size *
670 smpi_datatype_size(old_type),lb,ub,1, subtype, DT_FLAG_DATA);
672 smpi_datatype_create(new_type, size *
673 smpi_datatype_size(old_type),0,size *
674 smpi_datatype_size(old_type),0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
682 Hindexed Implementation - Indexed with indices in bytes
686 * Copies noncontiguous data into contiguous memory.
687 * @param contiguous_hindexed - output hindexed
688 * @param noncontiguous_hindexed - input hindexed
689 * @param type - pointer contening :
690 * - block_lengths - the width or height of blocked matrix
691 * - block_indices - indices of each data, in bytes
692 * - count - the number of rows of matrix
694 void serialize_hindexed( const void *noncontiguous_hindexed,
695 void *contiguous_hindexed,
699 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
701 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
702 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
703 for(j=0; j<count;j++){
704 for (i = 0; i < type_c->block_count; i++) {
705 if (type_c->old_type->has_subtype == 0)
706 memcpy(contiguous_hindexed_char,
707 noncontiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
709 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_hindexed_char,
710 contiguous_hindexed_char,
711 type_c->block_lengths[i],
712 type_c->old_type->substruct);
714 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
715 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
716 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
718 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
722 * Copies contiguous data into noncontiguous memory.
723 * @param noncontiguous_hindexed - output hindexed
724 * @param contiguous_hindexed - input hindexed
725 * @param type - pointer contening :
726 * - block_lengths - the width or height of blocked matrix
727 * - block_indices - indices of each data, in bytes
728 * - count - the number of rows of matrix
730 void unserialize_hindexed( const void *contiguous_hindexed,
731 void *noncontiguous_hindexed,
735 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
738 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
739 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
740 for(j=0; j<count;j++){
741 for (i = 0; i < type_c->block_count; i++) {
742 if (type_c->old_type->has_subtype == 0)
743 memcpy(noncontiguous_hindexed_char,
744 contiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
746 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_hindexed_char,
747 noncontiguous_hindexed_char,
748 type_c->block_lengths[i],
749 type_c->old_type->substruct);
751 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
752 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
753 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
755 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
759 void free_hindexed(MPI_Datatype* type){
760 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_lengths);
761 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_indices);
765 * Create a Sub type hindexed to be able to serialize and unserialize it
766 * the structure s_smpi_mpi_hindexed_t is derived from s_smpi_subtype which
767 * required the functions unserialize and serialize
769 s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths,
770 MPI_Aint* block_indices,
772 MPI_Datatype old_type,
774 s_smpi_mpi_hindexed_t *new_t= xbt_new(s_smpi_mpi_hindexed_t,1);
775 new_t->base.serialize = &serialize_hindexed;
776 new_t->base.unserialize = &unserialize_hindexed;
777 new_t->base.subtype_free = &free_hindexed;
778 //TODO : add a custom function for each time to clean these
779 new_t->block_lengths= xbt_new(int, block_count);
780 new_t->block_indices= xbt_new(MPI_Aint, block_count);
782 for(i=0;i<block_count;i++){
783 new_t->block_lengths[i]=block_lengths[i];
784 new_t->block_indices[i]=block_indices[i];
786 new_t->block_count = block_count;
787 new_t->old_type = old_type;
788 new_t->size_oldtype = size_oldtype;
793 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
802 lb=indices[0] + smpi_datatype_lb(old_type);
803 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_type);
805 for(i=0; i< count; i++){
808 size += blocklens[i];
810 if(indices[i]+smpi_datatype_lb(old_type)<lb) lb = indices[i]+smpi_datatype_lb(old_type);
811 if(indices[i]+blocklens[i]*smpi_datatype_ub(old_type)>ub) ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_type);
813 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_type) != indices[i+1]) )contiguous=0;
815 if (old_type->has_subtype == 1 || lb!=0)
819 s_smpi_mpi_hindexed_t* subtype = smpi_datatype_hindexed_create( blocklens,
823 smpi_datatype_size(old_type));
824 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
827 ,1, subtype, DT_FLAG_DATA);
829 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
830 0,size * smpi_datatype_size(old_type),
831 0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
839 struct Implementation - Indexed with indices in bytes
843 * Copies noncontiguous data into contiguous memory.
844 * @param contiguous_struct - output struct
845 * @param noncontiguous_struct - input struct
846 * @param type - pointer contening :
847 * - stride - stride of between noncontiguous data
848 * - block_length - the width or height of blocked matrix
849 * - count - the number of rows of matrix
851 void serialize_struct( const void *noncontiguous_struct,
852 void *contiguous_struct,
856 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
858 char* contiguous_struct_char = (char*)contiguous_struct;
859 char* noncontiguous_struct_char = (char*)noncontiguous_struct;
860 for(j=0; j<count;j++){
861 for (i = 0; i < type_c->block_count; i++) {
862 if (type_c->old_types[i]->has_subtype == 0)
863 memcpy(contiguous_struct_char,
864 noncontiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
866 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->serialize( noncontiguous_struct_char,
867 contiguous_struct_char,
868 type_c->block_lengths[i],
869 type_c->old_types[i]->substruct);
872 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
873 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
874 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 ?
876 noncontiguous_struct=(void*)noncontiguous_struct_char;
880 * Copies contiguous data into noncontiguous memory.
881 * @param noncontiguous_struct - output struct
882 * @param contiguous_struct - input struct
883 * @param type - pointer contening :
884 * - stride - stride of between noncontiguous data
885 * - block_length - the width or height of blocked matrix
886 * - count - the number of rows of matrix
888 void unserialize_struct( const void *contiguous_struct,
889 void *noncontiguous_struct,
893 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
896 char* contiguous_struct_char = (char*)contiguous_struct;
897 char* noncontiguous_struct_char = (char*)noncontiguous_struct;
898 for(j=0; j<count;j++){
899 for (i = 0; i < type_c->block_count; i++) {
900 if (type_c->old_types[i]->has_subtype == 0)
901 memcpy(noncontiguous_struct_char,
902 contiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
904 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->unserialize( contiguous_struct_char,
905 noncontiguous_struct_char,
906 type_c->block_lengths[i],
907 type_c->old_types[i]->substruct);
909 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
910 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
911 else noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);
913 noncontiguous_struct=(void*)noncontiguous_struct_char;
918 void free_struct(MPI_Datatype* type){
919 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_lengths);
920 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_indices);
921 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types);
925 * Create a Sub type struct to be able to serialize and unserialize it
926 * the structure s_smpi_mpi_struct_t is derived from s_smpi_subtype which
927 * required the functions unserialize and serialize
929 s_smpi_mpi_struct_t* smpi_datatype_struct_create( int* block_lengths,
930 MPI_Aint* block_indices,
932 MPI_Datatype* old_types){
933 s_smpi_mpi_struct_t *new_t= xbt_new(s_smpi_mpi_struct_t,1);
934 new_t->base.serialize = &serialize_struct;
935 new_t->base.unserialize = &unserialize_struct;
936 new_t->base.subtype_free = &free_struct;
937 //TODO : add a custom function for each time to clean these
938 new_t->block_lengths= xbt_new(int, block_count);
939 new_t->block_indices= xbt_new(MPI_Aint, block_count);
940 new_t->old_types= xbt_new(MPI_Datatype, block_count);
942 for(i=0;i<block_count;i++){
943 new_t->block_lengths[i]=block_lengths[i];
944 new_t->block_indices[i]=block_indices[i];
945 new_t->old_types[i]=old_types[i];
947 //new_t->block_lengths = block_lengths;
948 //new_t->block_indices = block_indices;
949 new_t->block_count = block_count;
950 //new_t->old_types = old_types;
955 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type)
964 lb=indices[0] + smpi_datatype_lb(old_types[0]);
965 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_types[0]);
969 for(i=0; i< count; i++){
972 if (old_types[i]->has_subtype == 1)
975 size += blocklens[i]*smpi_datatype_size(old_types[i]);
976 if (old_types[i]==MPI_LB){
980 if (old_types[i]==MPI_UB){
985 if(!forced_lb && indices[i]+smpi_datatype_lb(old_types[i])<lb) lb = indices[i];
986 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]);
988 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_types[i]) != indices[i+1]) )contiguous=0;
992 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens,
997 smpi_datatype_create(new_type, size, lb, ub,1, subtype, DT_FLAG_DATA);
999 smpi_datatype_create(new_type, size, lb, ub,0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
1004 void smpi_datatype_commit(MPI_Datatype *datatype)
1006 (*datatype)->flags= ((*datatype)->flags | DT_FLAG_COMMITED);
1009 typedef struct s_smpi_mpi_op {
1010 MPI_User_function *func;
1013 #define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a)
1014 #define MIN_OP(a, b) (b) = (a) < (b) ? (a) : (b)
1015 #define SUM_OP(a, b) (b) += (a)
1016 #define PROD_OP(a, b) (b) *= (a)
1017 #define LAND_OP(a, b) (b) = (a) && (b)
1018 #define LOR_OP(a, b) (b) = (a) || (b)
1019 #define LXOR_OP(a, b) (b) = (!(a) && (b)) || ((a) && !(b))
1020 #define BAND_OP(a, b) (b) &= (a)
1021 #define BOR_OP(a, b) (b) |= (a)
1022 #define BXOR_OP(a, b) (b) ^= (a)
1023 #define MAXLOC_OP(a, b) (b) = (a.value) < (b.value) ? (b) : (a)
1024 #define MINLOC_OP(a, b) (b) = (a.value) < (b.value) ? (a) : (b)
1025 //TODO : MINLOC & MAXLOC
1027 #define APPLY_FUNC(a, b, length, type, func) \
1030 type* x = (type*)(a); \
1031 type* y = (type*)(b); \
1032 for(i = 0; i < *(length); i++) { \
1037 static void max_func(void *a, void *b, int *length,
1038 MPI_Datatype * datatype)
1040 if (*datatype == MPI_CHAR) {
1041 APPLY_FUNC(a, b, length, char, MAX_OP);
1042 } else if (*datatype == MPI_SHORT) {
1043 APPLY_FUNC(a, b, length, short, MAX_OP);
1044 } else if (*datatype == MPI_INT) {
1045 APPLY_FUNC(a, b, length, int, MAX_OP);
1046 } else if (*datatype == MPI_LONG) {
1047 APPLY_FUNC(a, b, length, long, MAX_OP);
1048 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1049 APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
1050 } else if (*datatype == MPI_UNSIGNED) {
1051 APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
1052 } else if (*datatype == MPI_UNSIGNED_LONG) {
1053 APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
1054 } else if (*datatype == MPI_FLOAT) {
1055 APPLY_FUNC(a, b, length, float, MAX_OP);
1056 } else if (*datatype == MPI_DOUBLE) {
1057 APPLY_FUNC(a, b, length, double, MAX_OP);
1058 } else if (*datatype == MPI_LONG_DOUBLE) {
1059 APPLY_FUNC(a, b, length, long double, MAX_OP);
1063 static void min_func(void *a, void *b, int *length,
1064 MPI_Datatype * datatype)
1066 if (*datatype == MPI_CHAR) {
1067 APPLY_FUNC(a, b, length, char, MIN_OP);
1068 } else if (*datatype == MPI_SHORT) {
1069 APPLY_FUNC(a, b, length, short, MIN_OP);
1070 } else if (*datatype == MPI_INT) {
1071 APPLY_FUNC(a, b, length, int, MIN_OP);
1072 } else if (*datatype == MPI_LONG) {
1073 APPLY_FUNC(a, b, length, long, MIN_OP);
1074 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1075 APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
1076 } else if (*datatype == MPI_UNSIGNED) {
1077 APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
1078 } else if (*datatype == MPI_UNSIGNED_LONG) {
1079 APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
1080 } else if (*datatype == MPI_FLOAT) {
1081 APPLY_FUNC(a, b, length, float, MIN_OP);
1082 } else if (*datatype == MPI_DOUBLE) {
1083 APPLY_FUNC(a, b, length, double, MIN_OP);
1084 } else if (*datatype == MPI_LONG_DOUBLE) {
1085 APPLY_FUNC(a, b, length, long double, MIN_OP);
1089 static void sum_func(void *a, void *b, int *length,
1090 MPI_Datatype * datatype)
1092 if (*datatype == MPI_CHAR) {
1093 APPLY_FUNC(a, b, length, char, SUM_OP);
1094 } else if (*datatype == MPI_SHORT) {
1095 APPLY_FUNC(a, b, length, short, SUM_OP);
1096 } else if (*datatype == MPI_INT) {
1097 APPLY_FUNC(a, b, length, int, SUM_OP);
1098 } else if (*datatype == MPI_LONG) {
1099 APPLY_FUNC(a, b, length, long, SUM_OP);
1100 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1101 APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
1102 } else if (*datatype == MPI_UNSIGNED) {
1103 APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
1104 } else if (*datatype == MPI_UNSIGNED_LONG) {
1105 APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
1106 } else if (*datatype == MPI_FLOAT) {
1107 APPLY_FUNC(a, b, length, float, SUM_OP);
1108 } else if (*datatype == MPI_DOUBLE) {
1109 APPLY_FUNC(a, b, length, double, SUM_OP);
1110 } else if (*datatype == MPI_LONG_DOUBLE) {
1111 APPLY_FUNC(a, b, length, long double, SUM_OP);
1112 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1113 APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
1114 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1115 APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
1116 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1117 APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
1121 static void prod_func(void *a, void *b, int *length,
1122 MPI_Datatype * datatype)
1124 if (*datatype == MPI_CHAR) {
1125 APPLY_FUNC(a, b, length, char, PROD_OP);
1126 } else if (*datatype == MPI_SHORT) {
1127 APPLY_FUNC(a, b, length, short, PROD_OP);
1128 } else if (*datatype == MPI_INT) {
1129 APPLY_FUNC(a, b, length, int, PROD_OP);
1130 } else if (*datatype == MPI_LONG) {
1131 APPLY_FUNC(a, b, length, long, PROD_OP);
1132 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1133 APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
1134 } else if (*datatype == MPI_UNSIGNED) {
1135 APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
1136 } else if (*datatype == MPI_UNSIGNED_LONG) {
1137 APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
1138 } else if (*datatype == MPI_FLOAT) {
1139 APPLY_FUNC(a, b, length, float, PROD_OP);
1140 } else if (*datatype == MPI_DOUBLE) {
1141 APPLY_FUNC(a, b, length, double, PROD_OP);
1142 } else if (*datatype == MPI_LONG_DOUBLE) {
1143 APPLY_FUNC(a, b, length, long double, PROD_OP);
1144 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1145 APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
1146 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1147 APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
1148 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1149 APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
1153 static void land_func(void *a, void *b, int *length,
1154 MPI_Datatype * datatype)
1156 if (*datatype == MPI_CHAR) {
1157 APPLY_FUNC(a, b, length, char, LAND_OP);
1158 } else if (*datatype == MPI_SHORT) {
1159 APPLY_FUNC(a, b, length, short, LAND_OP);
1160 } else if (*datatype == MPI_INT) {
1161 APPLY_FUNC(a, b, length, int, LAND_OP);
1162 } else if (*datatype == MPI_LONG) {
1163 APPLY_FUNC(a, b, length, long, LAND_OP);
1164 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1165 APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
1166 } else if (*datatype == MPI_UNSIGNED) {
1167 APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
1168 } else if (*datatype == MPI_UNSIGNED_LONG) {
1169 APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
1170 } else if (*datatype == MPI_C_BOOL) {
1171 APPLY_FUNC(a, b, length, _Bool, LAND_OP);
1175 static void lor_func(void *a, void *b, int *length,
1176 MPI_Datatype * datatype)
1178 if (*datatype == MPI_CHAR) {
1179 APPLY_FUNC(a, b, length, char, LOR_OP);
1180 } else if (*datatype == MPI_SHORT) {
1181 APPLY_FUNC(a, b, length, short, LOR_OP);
1182 } else if (*datatype == MPI_INT) {
1183 APPLY_FUNC(a, b, length, int, LOR_OP);
1184 } else if (*datatype == MPI_LONG) {
1185 APPLY_FUNC(a, b, length, long, LOR_OP);
1186 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1187 APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
1188 } else if (*datatype == MPI_UNSIGNED) {
1189 APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
1190 } else if (*datatype == MPI_UNSIGNED_LONG) {
1191 APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
1192 } else if (*datatype == MPI_C_BOOL) {
1193 APPLY_FUNC(a, b, length, _Bool, LOR_OP);
1197 static void lxor_func(void *a, void *b, int *length,
1198 MPI_Datatype * datatype)
1200 if (*datatype == MPI_CHAR) {
1201 APPLY_FUNC(a, b, length, char, LXOR_OP);
1202 } else if (*datatype == MPI_SHORT) {
1203 APPLY_FUNC(a, b, length, short, LXOR_OP);
1204 } else if (*datatype == MPI_INT) {
1205 APPLY_FUNC(a, b, length, int, LXOR_OP);
1206 } else if (*datatype == MPI_LONG) {
1207 APPLY_FUNC(a, b, length, long, LXOR_OP);
1208 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1209 APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
1210 } else if (*datatype == MPI_UNSIGNED) {
1211 APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
1212 } else if (*datatype == MPI_UNSIGNED_LONG) {
1213 APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
1214 } else if (*datatype == MPI_C_BOOL) {
1215 APPLY_FUNC(a, b, length, _Bool, LXOR_OP);
1219 static void band_func(void *a, void *b, int *length,
1220 MPI_Datatype * datatype)
1222 if (*datatype == MPI_CHAR) {
1223 APPLY_FUNC(a, b, length, char, BAND_OP);
1225 if (*datatype == MPI_SHORT) {
1226 APPLY_FUNC(a, b, length, short, BAND_OP);
1227 } else if (*datatype == MPI_INT) {
1228 APPLY_FUNC(a, b, length, int, BAND_OP);
1229 } else if (*datatype == MPI_LONG) {
1230 APPLY_FUNC(a, b, length, long, BAND_OP);
1231 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1232 APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
1233 } else if (*datatype == MPI_UNSIGNED) {
1234 APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
1235 } else if (*datatype == MPI_UNSIGNED_LONG) {
1236 APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
1237 } else if (*datatype == MPI_BYTE) {
1238 APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
1242 static void bor_func(void *a, void *b, int *length,
1243 MPI_Datatype * datatype)
1245 if (*datatype == MPI_CHAR) {
1246 APPLY_FUNC(a, b, length, char, BOR_OP);
1247 } else if (*datatype == MPI_SHORT) {
1248 APPLY_FUNC(a, b, length, short, BOR_OP);
1249 } else if (*datatype == MPI_INT) {
1250 APPLY_FUNC(a, b, length, int, BOR_OP);
1251 } else if (*datatype == MPI_LONG) {
1252 APPLY_FUNC(a, b, length, long, BOR_OP);
1253 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1254 APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
1255 } else if (*datatype == MPI_UNSIGNED) {
1256 APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
1257 } else if (*datatype == MPI_UNSIGNED_LONG) {
1258 APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
1259 } else if (*datatype == MPI_BYTE) {
1260 APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
1264 static void bxor_func(void *a, void *b, int *length,
1265 MPI_Datatype * datatype)
1267 if (*datatype == MPI_CHAR) {
1268 APPLY_FUNC(a, b, length, char, BXOR_OP);
1269 } else if (*datatype == MPI_SHORT) {
1270 APPLY_FUNC(a, b, length, short, BXOR_OP);
1271 } else if (*datatype == MPI_INT) {
1272 APPLY_FUNC(a, b, length, int, BXOR_OP);
1273 } else if (*datatype == MPI_LONG) {
1274 APPLY_FUNC(a, b, length, long, BXOR_OP);
1275 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1276 APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
1277 } else if (*datatype == MPI_UNSIGNED) {
1278 APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
1279 } else if (*datatype == MPI_UNSIGNED_LONG) {
1280 APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
1281 } else if (*datatype == MPI_BYTE) {
1282 APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
1286 static void minloc_func(void *a, void *b, int *length,
1287 MPI_Datatype * datatype)
1289 if (*datatype == MPI_FLOAT_INT) {
1290 APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
1291 } else if (*datatype == MPI_LONG_INT) {
1292 APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
1293 } else if (*datatype == MPI_DOUBLE_INT) {
1294 APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
1295 } else if (*datatype == MPI_SHORT_INT) {
1296 APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
1297 } else if (*datatype == MPI_2INT) {
1298 APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
1299 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1300 APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
1301 } else if (*datatype == MPI_2FLOAT) {
1302 APPLY_FUNC(a, b, length, float_float, MINLOC_OP);
1303 } else if (*datatype == MPI_2DOUBLE) {
1304 APPLY_FUNC(a, b, length, double_double, MINLOC_OP);
1308 static void maxloc_func(void *a, void *b, int *length,
1309 MPI_Datatype * datatype)
1311 if (*datatype == MPI_FLOAT_INT) {
1312 APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
1313 } else if (*datatype == MPI_LONG_INT) {
1314 APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
1315 } else if (*datatype == MPI_DOUBLE_INT) {
1316 APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
1317 } else if (*datatype == MPI_SHORT_INT) {
1318 APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
1319 } else if (*datatype == MPI_2INT) {
1320 APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
1321 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1322 APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
1323 } else if (*datatype == MPI_2FLOAT) {
1324 APPLY_FUNC(a, b, length, float_float, MAXLOC_OP);
1325 } else if (*datatype == MPI_2DOUBLE) {
1326 APPLY_FUNC(a, b, length, double_double, MAXLOC_OP);
1331 #define CREATE_MPI_OP(name, func) \
1332 static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */ }; \
1333 MPI_Op name = &mpi_##name;
1335 CREATE_MPI_OP(MPI_MAX, max_func);
1336 CREATE_MPI_OP(MPI_MIN, min_func);
1337 CREATE_MPI_OP(MPI_SUM, sum_func);
1338 CREATE_MPI_OP(MPI_PROD, prod_func);
1339 CREATE_MPI_OP(MPI_LAND, land_func);
1340 CREATE_MPI_OP(MPI_LOR, lor_func);
1341 CREATE_MPI_OP(MPI_LXOR, lxor_func);
1342 CREATE_MPI_OP(MPI_BAND, band_func);
1343 CREATE_MPI_OP(MPI_BOR, bor_func);
1344 CREATE_MPI_OP(MPI_BXOR, bxor_func);
1345 CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
1346 CREATE_MPI_OP(MPI_MINLOC, minloc_func);
1348 MPI_Op smpi_op_new(MPI_User_function * function, int commute)
1352 //FIXME: add commute param
1353 op = xbt_new(s_smpi_mpi_op_t, 1);
1354 op->func = function;
1358 void smpi_op_destroy(MPI_Op op)
1363 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
1364 MPI_Datatype * datatype)
1366 op->func(invec, inoutvec, len, datatype);