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 && recvbuf != sendbuf) {
160 /* FIXME: treat packed cases */
161 sendcount *= smpi_datatype_size(sendtype);
162 recvcount *= smpi_datatype_size(recvtype);
163 count = sendcount < recvcount ? sendcount : recvcount;
165 if(sendtype->has_subtype == 0 && recvtype->has_subtype == 0) {
166 memcpy(recvbuf, sendbuf, count);
168 else if (sendtype->has_subtype == 0)
170 s_smpi_subtype_t *subtype = recvtype->substruct;
171 subtype->unserialize( sendbuf, recvbuf,1, subtype);
173 else if (recvtype->has_subtype == 0)
175 s_smpi_subtype_t *subtype = sendtype->substruct;
176 subtype->serialize(sendbuf, recvbuf,1, subtype);
178 s_smpi_subtype_t *subtype = sendtype->substruct;
181 void * buf_tmp = xbt_malloc(count);
183 subtype->serialize( sendbuf, buf_tmp,1, subtype);
184 subtype = recvtype->substruct;
185 subtype->unserialize( buf_tmp, recvbuf,1, subtype);
191 return sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
195 * Copies noncontiguous data into contiguous memory.
196 * @param contiguous_vector - output vector
197 * @param noncontiguous_vector - input vector
198 * @param type - pointer contening :
199 * - stride - stride of between noncontiguous data
200 * - block_length - the width or height of blocked matrix
201 * - count - the number of rows of matrix
203 void serialize_vector( const void *noncontiguous_vector,
204 void *contiguous_vector,
208 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
210 char* contiguous_vector_char = (char*)contiguous_vector;
211 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
213 for (i = 0; i < type_c->block_count * count; i++) {
214 if (type_c->old_type->has_subtype == 0)
215 memcpy(contiguous_vector_char,
216 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
218 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
219 contiguous_vector_char,
220 type_c->block_length,
221 type_c->old_type->substruct);
223 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
224 noncontiguous_vector_char += type_c->block_stride*smpi_datatype_get_extent(type_c->old_type);
229 * Copies contiguous data into noncontiguous memory.
230 * @param noncontiguous_vector - output vector
231 * @param contiguous_vector - input vector
232 * @param type - pointer contening :
233 * - stride - stride of between noncontiguous data
234 * - block_length - the width or height of blocked matrix
235 * - count - the number of rows of matrix
237 void unserialize_vector( const void *contiguous_vector,
238 void *noncontiguous_vector,
242 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
245 char* contiguous_vector_char = (char*)contiguous_vector;
246 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
248 for (i = 0; i < type_c->block_count * count; i++) {
249 if (type_c->old_type->has_subtype == 0)
250 memcpy(noncontiguous_vector_char,
251 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
253 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
254 noncontiguous_vector_char,
255 type_c->block_length,
256 type_c->old_type->substruct);
257 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
258 noncontiguous_vector_char += type_c->block_stride*smpi_datatype_get_extent(type_c->old_type);
263 * Create a Sub type vector to be able to serialize and unserialize it
264 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
265 * required the functions unserialize and serialize
268 s_smpi_mpi_vector_t* smpi_datatype_vector_create( int block_stride,
271 MPI_Datatype old_type,
273 s_smpi_mpi_vector_t *new_t= xbt_new(s_smpi_mpi_vector_t,1);
274 new_t->base.serialize = &serialize_vector;
275 new_t->base.unserialize = &unserialize_vector;
276 new_t->base.subtype_free = &free_vector;
277 new_t->block_stride = block_stride;
278 new_t->block_length = block_length;
279 new_t->block_count = block_count;
280 new_t->old_type = old_type;
281 new_t->size_oldtype = size_oldtype;
285 void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int has_subtype,
286 void *struct_type, int flags){
287 MPI_Datatype new_t= xbt_new(s_smpi_mpi_datatype_t,1);
289 new_t->has_subtype = has_subtype;
292 new_t->flags = flags;
293 new_t->substruct = struct_type;
298 void smpi_datatype_free(MPI_Datatype* type){
300 if((*type)->flags & DT_FLAG_PREDEFINED)return;
302 //if still used, mark for deletion
303 if((*type)->in_use!=0){
304 (*type)->flags |=DT_FLAG_DESTROYED;
308 if ((*type)->has_subtype == 1){
309 ((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);
310 xbt_free((*type)->substruct);
316 void smpi_datatype_use(MPI_Datatype type){
317 if(type)type->in_use++;
321 void smpi_datatype_unuse(MPI_Datatype type){
322 if(type && type->in_use-- == 0 && (type->flags & DT_FLAG_DESTROYED))
323 smpi_datatype_free(&type);
326 int smpi_datatype_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type)
329 if(old_type->has_subtype){
330 //handle this case as a hvector with stride equals to the extent of the datatype
331 return smpi_datatype_hvector(count, 1, smpi_datatype_get_extent(old_type), old_type, new_type);
333 smpi_datatype_create(new_type,
334 count * smpi_datatype_size(old_type),
335 0,count * smpi_datatype_size(old_type),
336 0,NULL, DT_FLAG_CONTIGUOUS);
341 int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type)
344 if (blocklen<=0) return MPI_ERR_ARG;
348 lb=smpi_datatype_lb(old_type);
349 ub=((count-1)*stride+blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
351 if(old_type->has_subtype || stride != blocklen){
354 s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
358 smpi_datatype_size(old_type));
359 smpi_datatype_create(new_type,
360 count * (blocklen) * smpi_datatype_size(old_type), lb,
367 /* in this situation the data are contignous thus it's not
368 * required to serialize and unserialize it*/
369 smpi_datatype_create(new_type, count * blocklen *
370 smpi_datatype_size(old_type), 0, ((count -1) * stride + blocklen)*
371 smpi_datatype_size(old_type),
374 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
380 void free_vector(MPI_Datatype* d){
384 Hvector Implementation - Vector with stride in bytes
389 * Copies noncontiguous data into contiguous memory.
390 * @param contiguous_hvector - output hvector
391 * @param noncontiguous_hvector - input hvector
392 * @param type - pointer contening :
393 * - stride - stride of between noncontiguous data, in bytes
394 * - block_length - the width or height of blocked matrix
395 * - count - the number of rows of matrix
397 void serialize_hvector( const void *noncontiguous_hvector,
398 void *contiguous_hvector,
402 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
404 char* contiguous_vector_char = (char*)contiguous_hvector;
405 char* noncontiguous_vector_char = (char*)noncontiguous_hvector;
407 for (i = 0; i < type_c->block_count * count; i++) {
408 if (type_c->old_type->has_subtype == 0)
409 memcpy(contiguous_vector_char,
410 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
412 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
413 contiguous_vector_char,
414 type_c->block_length,
415 type_c->old_type->substruct);
417 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
418 noncontiguous_vector_char += type_c->block_stride;
422 * Copies contiguous data into noncontiguous memory.
423 * @param noncontiguous_vector - output hvector
424 * @param contiguous_vector - input hvector
425 * @param type - pointer contening :
426 * - stride - stride of between noncontiguous data, in bytes
427 * - block_length - the width or height of blocked matrix
428 * - count - the number of rows of matrix
430 void unserialize_hvector( const void *contiguous_vector,
431 void *noncontiguous_vector,
435 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
438 char* contiguous_vector_char = (char*)contiguous_vector;
439 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
441 for (i = 0; i < type_c->block_count * count; i++) {
442 if (type_c->old_type->has_subtype == 0)
443 memcpy(noncontiguous_vector_char,
444 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
446 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
447 noncontiguous_vector_char,
448 type_c->block_length,
449 type_c->old_type->substruct);
450 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
451 noncontiguous_vector_char += type_c->block_stride;
456 * Create a Sub type vector to be able to serialize and unserialize it
457 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
458 * required the functions unserialize and serialize
461 s_smpi_mpi_hvector_t* smpi_datatype_hvector_create( MPI_Aint block_stride,
464 MPI_Datatype old_type,
466 s_smpi_mpi_hvector_t *new_t= xbt_new(s_smpi_mpi_hvector_t,1);
467 new_t->base.serialize = &serialize_hvector;
468 new_t->base.unserialize = &unserialize_hvector;
469 new_t->base.subtype_free = &free_hvector;
470 new_t->block_stride = block_stride;
471 new_t->block_length = block_length;
472 new_t->block_count = block_count;
473 new_t->old_type = old_type;
474 new_t->size_oldtype = size_oldtype;
478 //do nothing for vector types
479 void free_hvector(MPI_Datatype* d){
482 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
485 if (blocklen<=0) return MPI_ERR_ARG;
489 lb=smpi_datatype_lb(old_type);
490 ub=((count-1)*stride)+(blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
492 if(old_type->has_subtype || stride != blocklen*smpi_datatype_get_extent(old_type)){
493 s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride,
497 smpi_datatype_size(old_type));
499 smpi_datatype_create(new_type, count * blocklen * smpi_datatype_size(old_type),
506 smpi_datatype_create(new_type, count * blocklen *
507 smpi_datatype_size(old_type),0,count * blocklen *
508 smpi_datatype_size(old_type),
511 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
519 Indexed Implementation
523 * Copies noncontiguous data into contiguous memory.
524 * @param contiguous_indexed - output indexed
525 * @param noncontiguous_indexed - input indexed
526 * @param type - pointer contening :
527 * - block_lengths - the width or height of blocked matrix
528 * - block_indices - indices of each data, in element
529 * - count - the number of rows of matrix
531 void serialize_indexed( const void *noncontiguous_indexed,
532 void *contiguous_indexed,
536 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
538 char* contiguous_indexed_char = (char*)contiguous_indexed;
539 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed;
540 for(j=0; j<count;j++){
541 for (i = 0; i < type_c->block_count; i++) {
542 if (type_c->old_type->has_subtype == 0)
543 memcpy(contiguous_indexed_char,
544 noncontiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
546 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_indexed_char,
547 contiguous_indexed_char,
548 type_c->block_lengths[i],
549 type_c->old_type->substruct);
552 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
553 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);
554 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
556 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
560 * Copies contiguous data into noncontiguous memory.
561 * @param noncontiguous_indexed - output indexed
562 * @param contiguous_indexed - input indexed
563 * @param type - pointer contening :
564 * - block_lengths - the width or height of blocked matrix
565 * - block_indices - indices of each data, in element
566 * - count - the number of rows of matrix
568 void unserialize_indexed( const void *contiguous_indexed,
569 void *noncontiguous_indexed,
573 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
576 char* contiguous_indexed_char = (char*)contiguous_indexed;
577 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed;
578 for(j=0; j<count;j++){
579 for (i = 0; i < type_c->block_count; i++) {
580 if (type_c->old_type->has_subtype == 0)
581 memcpy(noncontiguous_indexed_char,
582 contiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
584 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_indexed_char,
585 noncontiguous_indexed_char,
586 type_c->block_lengths[i],
587 type_c->old_type->substruct);
589 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
590 if (i<type_c->block_count-1)
591 noncontiguous_indexed_char = (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
592 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
594 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
598 void free_indexed(MPI_Datatype* type){
599 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_lengths);
600 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_indices);
604 * Create a Sub type indexed to be able to serialize and unserialize it
605 * the structure s_smpi_mpi_indexed_t is derived from s_smpi_subtype which
606 * required the functions unserialize and serialize
608 s_smpi_mpi_indexed_t* smpi_datatype_indexed_create( int* block_lengths,
611 MPI_Datatype old_type,
613 s_smpi_mpi_indexed_t *new_t= xbt_new(s_smpi_mpi_indexed_t,1);
614 new_t->base.serialize = &serialize_indexed;
615 new_t->base.unserialize = &unserialize_indexed;
616 new_t->base.subtype_free = &free_indexed;
617 //TODO : add a custom function for each time to clean these
618 new_t->block_lengths= xbt_new(int, block_count);
619 new_t->block_indices= xbt_new(int, block_count);
621 for(i=0;i<block_count;i++){
622 new_t->block_lengths[i]=block_lengths[i];
623 new_t->block_indices[i]=block_indices[i];
625 new_t->block_count = block_count;
626 new_t->old_type = old_type;
627 new_t->size_oldtype = size_oldtype;
632 int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
641 lb=indices[0]*smpi_datatype_get_extent(old_type);
642 ub=indices[0]*smpi_datatype_get_extent(old_type) + blocklens[0]*smpi_datatype_ub(old_type);
645 for(i=0; i< count; i++){
648 size += blocklens[i];
650 if(indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type)<lb)
651 lb = indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type);
652 if(indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type)>ub)
653 ub = indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type);
655 if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )contiguous=0;
657 if (old_type->has_subtype == 1)
661 s_smpi_mpi_indexed_t* subtype = smpi_datatype_indexed_create( blocklens,
665 smpi_datatype_size(old_type));
666 smpi_datatype_create(new_type, size *
667 smpi_datatype_size(old_type),lb,ub,1, subtype, DT_FLAG_DATA);
669 smpi_datatype_create(new_type, size *
670 smpi_datatype_size(old_type),0,size *
671 smpi_datatype_size(old_type),0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
679 Hindexed Implementation - Indexed with indices in bytes
683 * Copies noncontiguous data into contiguous memory.
684 * @param contiguous_hindexed - output hindexed
685 * @param noncontiguous_hindexed - input hindexed
686 * @param type - pointer contening :
687 * - block_lengths - the width or height of blocked matrix
688 * - block_indices - indices of each data, in bytes
689 * - count - the number of rows of matrix
691 void serialize_hindexed( const void *noncontiguous_hindexed,
692 void *contiguous_hindexed,
696 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
698 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
699 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
700 for(j=0; j<count;j++){
701 for (i = 0; i < type_c->block_count; i++) {
702 if (type_c->old_type->has_subtype == 0)
703 memcpy(contiguous_hindexed_char,
704 noncontiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
706 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_hindexed_char,
707 contiguous_hindexed_char,
708 type_c->block_lengths[i],
709 type_c->old_type->substruct);
711 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
712 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
713 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
715 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
719 * Copies contiguous data into noncontiguous memory.
720 * @param noncontiguous_hindexed - output hindexed
721 * @param contiguous_hindexed - input hindexed
722 * @param type - pointer contening :
723 * - block_lengths - the width or height of blocked matrix
724 * - block_indices - indices of each data, in bytes
725 * - count - the number of rows of matrix
727 void unserialize_hindexed( const void *contiguous_hindexed,
728 void *noncontiguous_hindexed,
732 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
735 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
736 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed;
737 for(j=0; j<count;j++){
738 for (i = 0; i < type_c->block_count; i++) {
739 if (type_c->old_type->has_subtype == 0)
740 memcpy(noncontiguous_hindexed_char,
741 contiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
743 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_hindexed_char,
744 noncontiguous_hindexed_char,
745 type_c->block_lengths[i],
746 type_c->old_type->substruct);
748 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
749 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
750 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
752 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
756 void free_hindexed(MPI_Datatype* type){
757 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_lengths);
758 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_indices);
762 * Create a Sub type hindexed to be able to serialize and unserialize it
763 * the structure s_smpi_mpi_hindexed_t is derived from s_smpi_subtype which
764 * required the functions unserialize and serialize
766 s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths,
767 MPI_Aint* block_indices,
769 MPI_Datatype old_type,
771 s_smpi_mpi_hindexed_t *new_t= xbt_new(s_smpi_mpi_hindexed_t,1);
772 new_t->base.serialize = &serialize_hindexed;
773 new_t->base.unserialize = &unserialize_hindexed;
774 new_t->base.subtype_free = &free_hindexed;
775 //TODO : add a custom function for each time to clean these
776 new_t->block_lengths= xbt_new(int, block_count);
777 new_t->block_indices= xbt_new(MPI_Aint, block_count);
779 for(i=0;i<block_count;i++){
780 new_t->block_lengths[i]=block_lengths[i];
781 new_t->block_indices[i]=block_indices[i];
783 new_t->block_count = block_count;
784 new_t->old_type = old_type;
785 new_t->size_oldtype = size_oldtype;
790 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
799 lb=indices[0] + smpi_datatype_lb(old_type);
800 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_type);
802 for(i=0; i< count; i++){
805 size += blocklens[i];
807 if(indices[i]+smpi_datatype_lb(old_type)<lb) lb = indices[i]+smpi_datatype_lb(old_type);
808 if(indices[i]+blocklens[i]*smpi_datatype_ub(old_type)>ub) ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_type);
810 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_type) != indices[i+1]) )contiguous=0;
812 if (old_type->has_subtype == 1 || lb!=0)
816 s_smpi_mpi_hindexed_t* subtype = smpi_datatype_hindexed_create( blocklens,
820 smpi_datatype_size(old_type));
821 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
824 ,1, subtype, DT_FLAG_DATA);
826 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
827 0,size * smpi_datatype_size(old_type),
828 0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
836 struct Implementation - Indexed with indices in bytes
840 * Copies noncontiguous data into contiguous memory.
841 * @param contiguous_struct - output struct
842 * @param noncontiguous_struct - input struct
843 * @param type - pointer contening :
844 * - stride - stride of between noncontiguous data
845 * - block_length - the width or height of blocked matrix
846 * - count - the number of rows of matrix
848 void serialize_struct( const void *noncontiguous_struct,
849 void *contiguous_struct,
853 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
855 char* contiguous_struct_char = (char*)contiguous_struct;
856 char* noncontiguous_struct_char = (char*)noncontiguous_struct;
857 for(j=0; j<count;j++){
858 for (i = 0; i < type_c->block_count; i++) {
859 if (type_c->old_types[i]->has_subtype == 0)
860 memcpy(contiguous_struct_char,
861 noncontiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
863 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->serialize( noncontiguous_struct_char,
864 contiguous_struct_char,
865 type_c->block_lengths[i],
866 type_c->old_types[i]->substruct);
869 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
870 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
871 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 ?
873 noncontiguous_struct=(void*)noncontiguous_struct_char;
877 * Copies contiguous data into noncontiguous memory.
878 * @param noncontiguous_struct - output struct
879 * @param contiguous_struct - input struct
880 * @param type - pointer contening :
881 * - stride - stride of between noncontiguous data
882 * - block_length - the width or height of blocked matrix
883 * - count - the number of rows of matrix
885 void unserialize_struct( const void *contiguous_struct,
886 void *noncontiguous_struct,
890 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
893 char* contiguous_struct_char = (char*)contiguous_struct;
894 char* noncontiguous_struct_char = (char*)noncontiguous_struct;
895 for(j=0; j<count;j++){
896 for (i = 0; i < type_c->block_count; i++) {
897 if (type_c->old_types[i]->has_subtype == 0)
898 memcpy(noncontiguous_struct_char,
899 contiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
901 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->unserialize( contiguous_struct_char,
902 noncontiguous_struct_char,
903 type_c->block_lengths[i],
904 type_c->old_types[i]->substruct);
906 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
907 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
908 else noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);
910 noncontiguous_struct=(void*)noncontiguous_struct_char;
915 void free_struct(MPI_Datatype* type){
916 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_lengths);
917 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_indices);
918 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types);
922 * Create a Sub type struct to be able to serialize and unserialize it
923 * the structure s_smpi_mpi_struct_t is derived from s_smpi_subtype which
924 * required the functions unserialize and serialize
926 s_smpi_mpi_struct_t* smpi_datatype_struct_create( int* block_lengths,
927 MPI_Aint* block_indices,
929 MPI_Datatype* old_types){
930 s_smpi_mpi_struct_t *new_t= xbt_new(s_smpi_mpi_struct_t,1);
931 new_t->base.serialize = &serialize_struct;
932 new_t->base.unserialize = &unserialize_struct;
933 new_t->base.subtype_free = &free_struct;
934 //TODO : add a custom function for each time to clean these
935 new_t->block_lengths= xbt_new(int, block_count);
936 new_t->block_indices= xbt_new(MPI_Aint, block_count);
937 new_t->old_types= xbt_new(MPI_Datatype, block_count);
939 for(i=0;i<block_count;i++){
940 new_t->block_lengths[i]=block_lengths[i];
941 new_t->block_indices[i]=block_indices[i];
942 new_t->old_types[i]=old_types[i];
944 //new_t->block_lengths = block_lengths;
945 //new_t->block_indices = block_indices;
946 new_t->block_count = block_count;
947 //new_t->old_types = old_types;
952 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type)
961 lb=indices[0] + smpi_datatype_lb(old_types[0]);
962 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_types[0]);
966 for(i=0; i< count; i++){
969 if (old_types[i]->has_subtype == 1)
972 size += blocklens[i]*smpi_datatype_size(old_types[i]);
973 if (old_types[i]==MPI_LB){
977 if (old_types[i]==MPI_UB){
982 if(!forced_lb && indices[i]+smpi_datatype_lb(old_types[i])<lb) lb = indices[i];
983 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]);
985 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_types[i]) != indices[i+1]) )contiguous=0;
989 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens,
994 smpi_datatype_create(new_type, size, lb, ub,1, subtype, DT_FLAG_DATA);
996 smpi_datatype_create(new_type, size, lb, ub,0, NULL, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
1001 void smpi_datatype_commit(MPI_Datatype *datatype)
1003 (*datatype)->flags= ((*datatype)->flags | DT_FLAG_COMMITED);
1006 typedef struct s_smpi_mpi_op {
1007 MPI_User_function *func;
1011 #define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a)
1012 #define MIN_OP(a, b) (b) = (a) < (b) ? (a) : (b)
1013 #define SUM_OP(a, b) (b) += (a)
1014 #define PROD_OP(a, b) (b) *= (a)
1015 #define LAND_OP(a, b) (b) = (a) && (b)
1016 #define LOR_OP(a, b) (b) = (a) || (b)
1017 #define LXOR_OP(a, b) (b) = (!(a) && (b)) || ((a) && !(b))
1018 #define BAND_OP(a, b) (b) &= (a)
1019 #define BOR_OP(a, b) (b) |= (a)
1020 #define BXOR_OP(a, b) (b) ^= (a)
1021 #define MAXLOC_OP(a, b) (b) = (a.value) < (b.value) ? (b) : (a)
1022 #define MINLOC_OP(a, b) (b) = (a.value) < (b.value) ? (a) : (b)
1023 //TODO : MINLOC & MAXLOC
1025 #define APPLY_FUNC(a, b, length, type, func) \
1028 type* x = (type*)(a); \
1029 type* y = (type*)(b); \
1030 for(i = 0; i < *(length); i++) { \
1035 static void max_func(void *a, void *b, int *length,
1036 MPI_Datatype * datatype)
1038 if (*datatype == MPI_CHAR) {
1039 APPLY_FUNC(a, b, length, char, MAX_OP);
1040 } else if (*datatype == MPI_SHORT) {
1041 APPLY_FUNC(a, b, length, short, MAX_OP);
1042 } else if (*datatype == MPI_INT) {
1043 APPLY_FUNC(a, b, length, int, MAX_OP);
1044 } else if (*datatype == MPI_LONG) {
1045 APPLY_FUNC(a, b, length, long, MAX_OP);
1046 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1047 APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
1048 } else if (*datatype == MPI_UNSIGNED) {
1049 APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
1050 } else if (*datatype == MPI_UNSIGNED_LONG) {
1051 APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
1052 } else if (*datatype == MPI_FLOAT) {
1053 APPLY_FUNC(a, b, length, float, MAX_OP);
1054 } else if (*datatype == MPI_DOUBLE) {
1055 APPLY_FUNC(a, b, length, double, MAX_OP);
1056 } else if (*datatype == MPI_LONG_DOUBLE) {
1057 APPLY_FUNC(a, b, length, long double, MAX_OP);
1061 static void min_func(void *a, void *b, int *length,
1062 MPI_Datatype * datatype)
1064 if (*datatype == MPI_CHAR) {
1065 APPLY_FUNC(a, b, length, char, MIN_OP);
1066 } else if (*datatype == MPI_SHORT) {
1067 APPLY_FUNC(a, b, length, short, MIN_OP);
1068 } else if (*datatype == MPI_INT) {
1069 APPLY_FUNC(a, b, length, int, MIN_OP);
1070 } else if (*datatype == MPI_LONG) {
1071 APPLY_FUNC(a, b, length, long, MIN_OP);
1072 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1073 APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
1074 } else if (*datatype == MPI_UNSIGNED) {
1075 APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
1076 } else if (*datatype == MPI_UNSIGNED_LONG) {
1077 APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
1078 } else if (*datatype == MPI_FLOAT) {
1079 APPLY_FUNC(a, b, length, float, MIN_OP);
1080 } else if (*datatype == MPI_DOUBLE) {
1081 APPLY_FUNC(a, b, length, double, MIN_OP);
1082 } else if (*datatype == MPI_LONG_DOUBLE) {
1083 APPLY_FUNC(a, b, length, long double, MIN_OP);
1087 static void sum_func(void *a, void *b, int *length,
1088 MPI_Datatype * datatype)
1090 if (*datatype == MPI_CHAR) {
1091 APPLY_FUNC(a, b, length, char, SUM_OP);
1092 } else if (*datatype == MPI_SHORT) {
1093 APPLY_FUNC(a, b, length, short, SUM_OP);
1094 } else if (*datatype == MPI_INT) {
1095 APPLY_FUNC(a, b, length, int, SUM_OP);
1096 } else if (*datatype == MPI_LONG) {
1097 APPLY_FUNC(a, b, length, long, SUM_OP);
1098 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1099 APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
1100 } else if (*datatype == MPI_UNSIGNED) {
1101 APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
1102 } else if (*datatype == MPI_UNSIGNED_LONG) {
1103 APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
1104 } else if (*datatype == MPI_FLOAT) {
1105 APPLY_FUNC(a, b, length, float, SUM_OP);
1106 } else if (*datatype == MPI_DOUBLE) {
1107 APPLY_FUNC(a, b, length, double, SUM_OP);
1108 } else if (*datatype == MPI_LONG_DOUBLE) {
1109 APPLY_FUNC(a, b, length, long double, SUM_OP);
1110 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1111 APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
1112 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1113 APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
1114 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1115 APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
1119 static void prod_func(void *a, void *b, int *length,
1120 MPI_Datatype * datatype)
1122 if (*datatype == MPI_CHAR) {
1123 APPLY_FUNC(a, b, length, char, PROD_OP);
1124 } else if (*datatype == MPI_SHORT) {
1125 APPLY_FUNC(a, b, length, short, PROD_OP);
1126 } else if (*datatype == MPI_INT) {
1127 APPLY_FUNC(a, b, length, int, PROD_OP);
1128 } else if (*datatype == MPI_LONG) {
1129 APPLY_FUNC(a, b, length, long, PROD_OP);
1130 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1131 APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
1132 } else if (*datatype == MPI_UNSIGNED) {
1133 APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
1134 } else if (*datatype == MPI_UNSIGNED_LONG) {
1135 APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
1136 } else if (*datatype == MPI_FLOAT) {
1137 APPLY_FUNC(a, b, length, float, PROD_OP);
1138 } else if (*datatype == MPI_DOUBLE) {
1139 APPLY_FUNC(a, b, length, double, PROD_OP);
1140 } else if (*datatype == MPI_LONG_DOUBLE) {
1141 APPLY_FUNC(a, b, length, long double, PROD_OP);
1142 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1143 APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
1144 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1145 APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
1146 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1147 APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
1151 static void land_func(void *a, void *b, int *length,
1152 MPI_Datatype * datatype)
1154 if (*datatype == MPI_CHAR) {
1155 APPLY_FUNC(a, b, length, char, LAND_OP);
1156 } else if (*datatype == MPI_SHORT) {
1157 APPLY_FUNC(a, b, length, short, LAND_OP);
1158 } else if (*datatype == MPI_INT) {
1159 APPLY_FUNC(a, b, length, int, LAND_OP);
1160 } else if (*datatype == MPI_LONG) {
1161 APPLY_FUNC(a, b, length, long, LAND_OP);
1162 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1163 APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
1164 } else if (*datatype == MPI_UNSIGNED) {
1165 APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
1166 } else if (*datatype == MPI_UNSIGNED_LONG) {
1167 APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
1168 } else if (*datatype == MPI_C_BOOL) {
1169 APPLY_FUNC(a, b, length, _Bool, LAND_OP);
1173 static void lor_func(void *a, void *b, int *length,
1174 MPI_Datatype * datatype)
1176 if (*datatype == MPI_CHAR) {
1177 APPLY_FUNC(a, b, length, char, LOR_OP);
1178 } else if (*datatype == MPI_SHORT) {
1179 APPLY_FUNC(a, b, length, short, LOR_OP);
1180 } else if (*datatype == MPI_INT) {
1181 APPLY_FUNC(a, b, length, int, LOR_OP);
1182 } else if (*datatype == MPI_LONG) {
1183 APPLY_FUNC(a, b, length, long, LOR_OP);
1184 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1185 APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
1186 } else if (*datatype == MPI_UNSIGNED) {
1187 APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
1188 } else if (*datatype == MPI_UNSIGNED_LONG) {
1189 APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
1190 } else if (*datatype == MPI_C_BOOL) {
1191 APPLY_FUNC(a, b, length, _Bool, LOR_OP);
1195 static void lxor_func(void *a, void *b, int *length,
1196 MPI_Datatype * datatype)
1198 if (*datatype == MPI_CHAR) {
1199 APPLY_FUNC(a, b, length, char, LXOR_OP);
1200 } else if (*datatype == MPI_SHORT) {
1201 APPLY_FUNC(a, b, length, short, LXOR_OP);
1202 } else if (*datatype == MPI_INT) {
1203 APPLY_FUNC(a, b, length, int, LXOR_OP);
1204 } else if (*datatype == MPI_LONG) {
1205 APPLY_FUNC(a, b, length, long, LXOR_OP);
1206 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1207 APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
1208 } else if (*datatype == MPI_UNSIGNED) {
1209 APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
1210 } else if (*datatype == MPI_UNSIGNED_LONG) {
1211 APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
1212 } else if (*datatype == MPI_C_BOOL) {
1213 APPLY_FUNC(a, b, length, _Bool, LXOR_OP);
1217 static void band_func(void *a, void *b, int *length,
1218 MPI_Datatype * datatype)
1220 if (*datatype == MPI_CHAR) {
1221 APPLY_FUNC(a, b, length, char, BAND_OP);
1223 if (*datatype == MPI_SHORT) {
1224 APPLY_FUNC(a, b, length, short, BAND_OP);
1225 } else if (*datatype == MPI_INT) {
1226 APPLY_FUNC(a, b, length, int, BAND_OP);
1227 } else if (*datatype == MPI_LONG) {
1228 APPLY_FUNC(a, b, length, long, BAND_OP);
1229 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1230 APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
1231 } else if (*datatype == MPI_UNSIGNED) {
1232 APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
1233 } else if (*datatype == MPI_UNSIGNED_LONG) {
1234 APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
1235 } else if (*datatype == MPI_BYTE) {
1236 APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
1240 static void bor_func(void *a, void *b, int *length,
1241 MPI_Datatype * datatype)
1243 if (*datatype == MPI_CHAR) {
1244 APPLY_FUNC(a, b, length, char, BOR_OP);
1245 } else if (*datatype == MPI_SHORT) {
1246 APPLY_FUNC(a, b, length, short, BOR_OP);
1247 } else if (*datatype == MPI_INT) {
1248 APPLY_FUNC(a, b, length, int, BOR_OP);
1249 } else if (*datatype == MPI_LONG) {
1250 APPLY_FUNC(a, b, length, long, BOR_OP);
1251 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1252 APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
1253 } else if (*datatype == MPI_UNSIGNED) {
1254 APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
1255 } else if (*datatype == MPI_UNSIGNED_LONG) {
1256 APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
1257 } else if (*datatype == MPI_BYTE) {
1258 APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
1262 static void bxor_func(void *a, void *b, int *length,
1263 MPI_Datatype * datatype)
1265 if (*datatype == MPI_CHAR) {
1266 APPLY_FUNC(a, b, length, char, BXOR_OP);
1267 } else if (*datatype == MPI_SHORT) {
1268 APPLY_FUNC(a, b, length, short, BXOR_OP);
1269 } else if (*datatype == MPI_INT) {
1270 APPLY_FUNC(a, b, length, int, BXOR_OP);
1271 } else if (*datatype == MPI_LONG) {
1272 APPLY_FUNC(a, b, length, long, BXOR_OP);
1273 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1274 APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
1275 } else if (*datatype == MPI_UNSIGNED) {
1276 APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
1277 } else if (*datatype == MPI_UNSIGNED_LONG) {
1278 APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
1279 } else if (*datatype == MPI_BYTE) {
1280 APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
1284 static void minloc_func(void *a, void *b, int *length,
1285 MPI_Datatype * datatype)
1287 if (*datatype == MPI_FLOAT_INT) {
1288 APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
1289 } else if (*datatype == MPI_LONG_INT) {
1290 APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
1291 } else if (*datatype == MPI_DOUBLE_INT) {
1292 APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
1293 } else if (*datatype == MPI_SHORT_INT) {
1294 APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
1295 } else if (*datatype == MPI_2INT) {
1296 APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
1297 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1298 APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
1299 } else if (*datatype == MPI_2FLOAT) {
1300 APPLY_FUNC(a, b, length, float_float, MINLOC_OP);
1301 } else if (*datatype == MPI_2DOUBLE) {
1302 APPLY_FUNC(a, b, length, double_double, MINLOC_OP);
1306 static void maxloc_func(void *a, void *b, int *length,
1307 MPI_Datatype * datatype)
1309 if (*datatype == MPI_FLOAT_INT) {
1310 APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
1311 } else if (*datatype == MPI_LONG_INT) {
1312 APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
1313 } else if (*datatype == MPI_DOUBLE_INT) {
1314 APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
1315 } else if (*datatype == MPI_SHORT_INT) {
1316 APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
1317 } else if (*datatype == MPI_2INT) {
1318 APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
1319 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1320 APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
1321 } else if (*datatype == MPI_2FLOAT) {
1322 APPLY_FUNC(a, b, length, float_float, MAXLOC_OP);
1323 } else if (*datatype == MPI_2DOUBLE) {
1324 APPLY_FUNC(a, b, length, double_double, MAXLOC_OP);
1329 #define CREATE_MPI_OP(name, func) \
1330 static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */, TRUE }; \
1331 MPI_Op name = &mpi_##name;
1333 CREATE_MPI_OP(MPI_MAX, max_func);
1334 CREATE_MPI_OP(MPI_MIN, min_func);
1335 CREATE_MPI_OP(MPI_SUM, sum_func);
1336 CREATE_MPI_OP(MPI_PROD, prod_func);
1337 CREATE_MPI_OP(MPI_LAND, land_func);
1338 CREATE_MPI_OP(MPI_LOR, lor_func);
1339 CREATE_MPI_OP(MPI_LXOR, lxor_func);
1340 CREATE_MPI_OP(MPI_BAND, band_func);
1341 CREATE_MPI_OP(MPI_BOR, bor_func);
1342 CREATE_MPI_OP(MPI_BXOR, bxor_func);
1343 CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
1344 CREATE_MPI_OP(MPI_MINLOC, minloc_func);
1346 MPI_Op smpi_op_new(MPI_User_function * function, int commute)
1349 op = xbt_new(s_smpi_mpi_op_t, 1);
1350 op->func = function;
1351 op-> is_commute = commute;
1355 int smpi_op_is_commute(MPI_Op op)
1357 return op-> is_commute;
1360 void smpi_op_destroy(MPI_Op op)
1365 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
1366 MPI_Datatype * datatype)
1368 op->func(invec, inoutvec, len, datatype);