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,count/smpi_datatype_size(sendtype), subtype);
184 subtype = recvtype->substruct;
185 subtype->unserialize( buf_tmp, recvbuf,count/smpi_datatype_size(recvtype), 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 if((i+1)%type_c->block_count ==0)
225 noncontiguous_vector_char += type_c->block_length*smpi_datatype_get_extent(type_c->old_type);
227 noncontiguous_vector_char += type_c->block_stride*smpi_datatype_get_extent(type_c->old_type);
232 * Copies contiguous data into noncontiguous memory.
233 * @param noncontiguous_vector - output vector
234 * @param contiguous_vector - input vector
235 * @param type - pointer contening :
236 * - stride - stride of between noncontiguous data
237 * - block_length - the width or height of blocked matrix
238 * - count - the number of rows of matrix
240 void unserialize_vector( const void *contiguous_vector,
241 void *noncontiguous_vector,
245 s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)type;
248 char* contiguous_vector_char = (char*)contiguous_vector;
249 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
251 for (i = 0; i < type_c->block_count * count; i++) {
252 if (type_c->old_type->has_subtype == 0)
253 memcpy(noncontiguous_vector_char,
254 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
256 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
257 noncontiguous_vector_char,
258 type_c->block_length,
259 type_c->old_type->substruct);
260 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
261 if((i+1)%type_c->block_count ==0)
262 noncontiguous_vector_char += type_c->block_length*smpi_datatype_get_extent(type_c->old_type);
264 noncontiguous_vector_char += type_c->block_stride*smpi_datatype_get_extent(type_c->old_type);
269 * Create a Sub type vector to be able to serialize and unserialize it
270 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
271 * required the functions unserialize and serialize
274 s_smpi_mpi_vector_t* smpi_datatype_vector_create( int block_stride,
277 MPI_Datatype old_type,
279 s_smpi_mpi_vector_t *new_t= xbt_new(s_smpi_mpi_vector_t,1);
280 new_t->base.serialize = &serialize_vector;
281 new_t->base.unserialize = &unserialize_vector;
282 new_t->base.subtype_free = &free_vector;
283 new_t->block_stride = block_stride;
284 new_t->block_length = block_length;
285 new_t->block_count = block_count;
286 new_t->old_type = old_type;
287 new_t->size_oldtype = size_oldtype;
291 void smpi_datatype_create(MPI_Datatype* new_type, int size,int lb, int ub, int has_subtype,
292 void *struct_type, int flags){
293 MPI_Datatype new_t= xbt_new(s_smpi_mpi_datatype_t,1);
295 new_t->has_subtype = size>0? has_subtype:0;
298 new_t->flags = flags;
299 new_t->substruct = struct_type;
304 void smpi_datatype_free(MPI_Datatype* type){
306 if((*type)->flags & DT_FLAG_PREDEFINED)return;
308 //if still used, mark for deletion
309 if((*type)->in_use!=0){
310 (*type)->flags |=DT_FLAG_DESTROYED;
314 if ((*type)->has_subtype == 1){
315 ((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);
316 xbt_free((*type)->substruct);
322 void smpi_datatype_use(MPI_Datatype type){
323 if(type)type->in_use++;
327 void smpi_datatype_unuse(MPI_Datatype type){
328 if(type && type->in_use-- == 0 && (type->flags & DT_FLAG_DESTROYED))
329 smpi_datatype_free(&type);
336 Contiguous Implementation
341 * Copies noncontiguous data into contiguous memory.
342 * @param contiguous_hvector - output hvector
343 * @param noncontiguous_hvector - input hvector
344 * @param type - pointer contening :
345 * - stride - stride of between noncontiguous data, in bytes
346 * - block_length - the width or height of blocked matrix
347 * - count - the number of rows of matrix
349 void serialize_contiguous( const void *noncontiguous_hvector,
350 void *contiguous_hvector,
354 s_smpi_mpi_contiguous_t* type_c = (s_smpi_mpi_contiguous_t*)type;
355 char* contiguous_vector_char = (char*)contiguous_hvector;
356 char* noncontiguous_vector_char = (char*)noncontiguous_hvector+type_c->lb;
357 memcpy(contiguous_vector_char,
358 noncontiguous_vector_char, count* type_c->block_count * type_c->size_oldtype);
361 * Copies contiguous data into noncontiguous memory.
362 * @param noncontiguous_vector - output hvector
363 * @param contiguous_vector - input hvector
364 * @param type - pointer contening :
365 * - stride - stride of between noncontiguous data, in bytes
366 * - block_length - the width or height of blocked matrix
367 * - count - the number of rows of matrix
369 void unserialize_contiguous( const void *contiguous_vector,
370 void *noncontiguous_vector,
374 s_smpi_mpi_contiguous_t* type_c = (s_smpi_mpi_contiguous_t*)type;
375 char* contiguous_vector_char = (char*)contiguous_vector;
376 char* noncontiguous_vector_char = (char*)noncontiguous_vector+type_c->lb;
378 memcpy(noncontiguous_vector_char,
379 contiguous_vector_char, count* type_c->block_count * type_c->size_oldtype);
382 void free_contiguous(MPI_Datatype* d){
386 * Create a Sub type contiguous to be able to serialize and unserialize it
387 * the structure s_smpi_mpi_contiguous_t is derived from s_smpi_subtype which
388 * required the functions unserialize and serialize
391 s_smpi_mpi_contiguous_t* smpi_datatype_contiguous_create( MPI_Aint lb,
393 MPI_Datatype old_type,
395 s_smpi_mpi_contiguous_t *new_t= xbt_new(s_smpi_mpi_contiguous_t,1);
396 new_t->base.serialize = &serialize_contiguous;
397 new_t->base.unserialize = &unserialize_contiguous;
398 new_t->base.subtype_free = &free_contiguous;
400 new_t->block_count = block_count;
401 new_t->old_type = old_type;
402 new_t->size_oldtype = size_oldtype;
409 int smpi_datatype_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type, MPI_Aint lb)
412 if(old_type->has_subtype){
413 //handle this case as a hvector with stride equals to the extent of the datatype
414 return smpi_datatype_hvector(count, 1, smpi_datatype_get_extent(old_type), old_type, new_type);
417 s_smpi_mpi_contiguous_t* subtype = smpi_datatype_contiguous_create( lb,
420 smpi_datatype_size(old_type));
422 smpi_datatype_create(new_type,
423 count * smpi_datatype_size(old_type),
424 lb,lb + count * smpi_datatype_size(old_type),
425 1,subtype, DT_FLAG_CONTIGUOUS);
430 int smpi_datatype_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type)
433 if (blocklen<0) return MPI_ERR_ARG;
437 lb=smpi_datatype_lb(old_type);
438 ub=((count-1)*stride+blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
440 if(old_type->has_subtype || stride != blocklen){
443 s_smpi_mpi_vector_t* subtype = smpi_datatype_vector_create( stride,
447 smpi_datatype_size(old_type));
448 smpi_datatype_create(new_type,
449 count * (blocklen) * smpi_datatype_size(old_type), lb,
456 /* in this situation the data are contignous thus it's not
457 * required to serialize and unserialize it*/
458 smpi_datatype_create(new_type, count * blocklen *
459 smpi_datatype_size(old_type), 0, ((count -1) * stride + blocklen)*
460 smpi_datatype_size(old_type),
463 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
469 void free_vector(MPI_Datatype* d){
473 Hvector Implementation - Vector with stride in bytes
478 * Copies noncontiguous data into contiguous memory.
479 * @param contiguous_hvector - output hvector
480 * @param noncontiguous_hvector - input hvector
481 * @param type - pointer contening :
482 * - stride - stride of between noncontiguous data, in bytes
483 * - block_length - the width or height of blocked matrix
484 * - count - the number of rows of matrix
486 void serialize_hvector( const void *noncontiguous_hvector,
487 void *contiguous_hvector,
491 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
493 char* contiguous_vector_char = (char*)contiguous_hvector;
494 char* noncontiguous_vector_char = (char*)noncontiguous_hvector;
496 for (i = 0; i < type_c->block_count * count; i++) {
497 if (type_c->old_type->has_subtype == 0)
498 memcpy(contiguous_vector_char,
499 noncontiguous_vector_char, type_c->block_length * type_c->size_oldtype);
501 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_vector_char,
502 contiguous_vector_char,
503 type_c->block_length,
504 type_c->old_type->substruct);
506 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
507 if((i+1)%type_c->block_count ==0)
508 noncontiguous_vector_char += type_c->block_length*type_c->size_oldtype;
510 noncontiguous_vector_char += type_c->block_stride;
514 * Copies contiguous data into noncontiguous memory.
515 * @param noncontiguous_vector - output hvector
516 * @param contiguous_vector - input hvector
517 * @param type - pointer contening :
518 * - stride - stride of between noncontiguous data, in bytes
519 * - block_length - the width or height of blocked matrix
520 * - count - the number of rows of matrix
522 void unserialize_hvector( const void *contiguous_vector,
523 void *noncontiguous_vector,
527 s_smpi_mpi_hvector_t* type_c = (s_smpi_mpi_hvector_t*)type;
530 char* contiguous_vector_char = (char*)contiguous_vector;
531 char* noncontiguous_vector_char = (char*)noncontiguous_vector;
533 for (i = 0; i < type_c->block_count * count; i++) {
534 if (type_c->old_type->has_subtype == 0)
535 memcpy(noncontiguous_vector_char,
536 contiguous_vector_char, type_c->block_length * type_c->size_oldtype);
538 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_vector_char,
539 noncontiguous_vector_char,
540 type_c->block_length,
541 type_c->old_type->substruct);
542 contiguous_vector_char += type_c->block_length*type_c->size_oldtype;
543 if((i+1)%type_c->block_count ==0)
544 noncontiguous_vector_char += type_c->block_length*type_c->size_oldtype;
546 noncontiguous_vector_char += type_c->block_stride;
551 * Create a Sub type vector to be able to serialize and unserialize it
552 * the structure s_smpi_mpi_vector_t is derived from s_smpi_subtype which
553 * required the functions unserialize and serialize
556 s_smpi_mpi_hvector_t* smpi_datatype_hvector_create( MPI_Aint block_stride,
559 MPI_Datatype old_type,
561 s_smpi_mpi_hvector_t *new_t= xbt_new(s_smpi_mpi_hvector_t,1);
562 new_t->base.serialize = &serialize_hvector;
563 new_t->base.unserialize = &unserialize_hvector;
564 new_t->base.subtype_free = &free_hvector;
565 new_t->block_stride = block_stride;
566 new_t->block_length = block_length;
567 new_t->block_count = block_count;
568 new_t->old_type = old_type;
569 new_t->size_oldtype = size_oldtype;
573 //do nothing for vector types
574 void free_hvector(MPI_Datatype* d){
577 int smpi_datatype_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type)
580 if (blocklen<0) return MPI_ERR_ARG;
584 lb=smpi_datatype_lb(old_type);
585 ub=((count-1)*stride)+(blocklen-1)*smpi_datatype_get_extent(old_type)+smpi_datatype_ub(old_type);
587 if(old_type->has_subtype || stride != blocklen*smpi_datatype_get_extent(old_type)){
588 s_smpi_mpi_hvector_t* subtype = smpi_datatype_hvector_create( stride,
592 smpi_datatype_size(old_type));
594 smpi_datatype_create(new_type, count * blocklen * smpi_datatype_size(old_type),
601 smpi_datatype_create(new_type, count * blocklen *
602 smpi_datatype_size(old_type),0,count * blocklen *
603 smpi_datatype_size(old_type),
606 DT_FLAG_VECTOR|DT_FLAG_CONTIGUOUS);
614 Indexed Implementation
618 * Copies noncontiguous data into contiguous memory.
619 * @param contiguous_indexed - output indexed
620 * @param noncontiguous_indexed - input indexed
621 * @param type - pointer contening :
622 * - block_lengths - the width or height of blocked matrix
623 * - block_indices - indices of each data, in element
624 * - count - the number of rows of matrix
626 void serialize_indexed( const void *noncontiguous_indexed,
627 void *contiguous_indexed,
631 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
633 char* contiguous_indexed_char = (char*)contiguous_indexed;
634 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed+type_c->block_indices[0] * type_c->size_oldtype;
635 for(j=0; j<count;j++){
636 for (i = 0; i < type_c->block_count; i++) {
637 if (type_c->old_type->has_subtype == 0)
638 memcpy(contiguous_indexed_char,
639 noncontiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
641 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_indexed_char,
642 contiguous_indexed_char,
643 type_c->block_lengths[i],
644 type_c->old_type->substruct);
647 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
648 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);
649 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
651 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
655 * Copies contiguous data into noncontiguous memory.
656 * @param noncontiguous_indexed - output indexed
657 * @param contiguous_indexed - input indexed
658 * @param type - pointer contening :
659 * - block_lengths - the width or height of blocked matrix
660 * - block_indices - indices of each data, in element
661 * - count - the number of rows of matrix
663 void unserialize_indexed( const void *contiguous_indexed,
664 void *noncontiguous_indexed,
669 s_smpi_mpi_indexed_t* type_c = (s_smpi_mpi_indexed_t*)type;
671 char* contiguous_indexed_char = (char*)contiguous_indexed;
672 char* noncontiguous_indexed_char = (char*)noncontiguous_indexed+type_c->block_indices[0]*smpi_datatype_get_extent(type_c->old_type);
673 for(j=0; j<count;j++){
674 for (i = 0; i < type_c->block_count; i++) {
675 if (type_c->old_type->has_subtype == 0)
676 memcpy(noncontiguous_indexed_char ,
677 contiguous_indexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
679 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_indexed_char,
680 noncontiguous_indexed_char,
681 type_c->block_lengths[i],
682 type_c->old_type->substruct);
684 contiguous_indexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
685 if (i<type_c->block_count-1)
686 noncontiguous_indexed_char = (char*)noncontiguous_indexed + type_c->block_indices[i+1]*smpi_datatype_get_extent(type_c->old_type);
687 else noncontiguous_indexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
689 noncontiguous_indexed=(void*)noncontiguous_indexed_char;
693 void free_indexed(MPI_Datatype* type){
694 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_lengths);
695 xbt_free(((s_smpi_mpi_indexed_t *)(*type)->substruct)->block_indices);
699 * Create a Sub type indexed to be able to serialize and unserialize it
700 * the structure s_smpi_mpi_indexed_t is derived from s_smpi_subtype which
701 * required the functions unserialize and serialize
703 s_smpi_mpi_indexed_t* smpi_datatype_indexed_create( int* block_lengths,
706 MPI_Datatype old_type,
708 s_smpi_mpi_indexed_t *new_t= xbt_new(s_smpi_mpi_indexed_t,1);
709 new_t->base.serialize = &serialize_indexed;
710 new_t->base.unserialize = &unserialize_indexed;
711 new_t->base.subtype_free = &free_indexed;
712 //TODO : add a custom function for each time to clean these
713 new_t->block_lengths= xbt_new(int, block_count);
714 new_t->block_indices= xbt_new(int, block_count);
716 for(i=0;i<block_count;i++){
717 new_t->block_lengths[i]=block_lengths[i];
718 new_t->block_indices[i]=block_indices[i];
720 new_t->block_count = block_count;
721 new_t->old_type = old_type;
722 new_t->size_oldtype = size_oldtype;
727 int smpi_datatype_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
736 lb=indices[0]*smpi_datatype_get_extent(old_type);
737 ub=indices[0]*smpi_datatype_get_extent(old_type) + blocklens[0]*smpi_datatype_ub(old_type);
740 for(i=0; i< count; i++){
743 size += blocklens[i];
745 if(indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type)<lb)
746 lb = indices[i]*smpi_datatype_get_extent(old_type)+smpi_datatype_lb(old_type);
747 if(indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type)>ub)
748 ub = indices[i]*smpi_datatype_get_extent(old_type)+blocklens[i]*smpi_datatype_ub(old_type);
750 if ( (i< count -1) && (indices[i]+blocklens[i] != indices[i+1]) )contiguous=0;
752 if (old_type->has_subtype == 1)
756 s_smpi_mpi_indexed_t* subtype = smpi_datatype_indexed_create( blocklens,
760 smpi_datatype_size(old_type));
761 smpi_datatype_create(new_type, size *
762 smpi_datatype_size(old_type),lb,ub,1, subtype, DT_FLAG_DATA);
764 s_smpi_mpi_contiguous_t* subtype = smpi_datatype_contiguous_create( lb,
767 smpi_datatype_size(old_type));
768 smpi_datatype_create(new_type, size *
769 smpi_datatype_size(old_type),lb,ub,1, subtype, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
777 Hindexed Implementation - Indexed with indices in bytes
781 * Copies noncontiguous data into contiguous memory.
782 * @param contiguous_hindexed - output hindexed
783 * @param noncontiguous_hindexed - input hindexed
784 * @param type - pointer contening :
785 * - block_lengths - the width or height of blocked matrix
786 * - block_indices - indices of each data, in bytes
787 * - count - the number of rows of matrix
789 void serialize_hindexed( const void *noncontiguous_hindexed,
790 void *contiguous_hindexed,
794 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
796 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
797 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed+ type_c->block_indices[0];
798 for(j=0; j<count;j++){
799 for (i = 0; i < type_c->block_count; i++) {
800 if (type_c->old_type->has_subtype == 0)
801 memcpy(contiguous_hindexed_char,
802 noncontiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
804 ((s_smpi_subtype_t*)type_c->old_type->substruct)->serialize( noncontiguous_hindexed_char,
805 contiguous_hindexed_char,
806 type_c->block_lengths[i],
807 type_c->old_type->substruct);
809 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
810 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
811 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
813 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
817 * Copies contiguous data into noncontiguous memory.
818 * @param noncontiguous_hindexed - output hindexed
819 * @param contiguous_hindexed - input hindexed
820 * @param type - pointer contening :
821 * - block_lengths - the width or height of blocked matrix
822 * - block_indices - indices of each data, in bytes
823 * - count - the number of rows of matrix
825 void unserialize_hindexed( const void *contiguous_hindexed,
826 void *noncontiguous_hindexed,
830 s_smpi_mpi_hindexed_t* type_c = (s_smpi_mpi_hindexed_t*)type;
833 char* contiguous_hindexed_char = (char*)contiguous_hindexed;
834 char* noncontiguous_hindexed_char = (char*)noncontiguous_hindexed+ type_c->block_indices[0];
835 for(j=0; j<count;j++){
836 for (i = 0; i < type_c->block_count; i++) {
837 if (type_c->old_type->has_subtype == 0)
838 memcpy(noncontiguous_hindexed_char,
839 contiguous_hindexed_char, type_c->block_lengths[i] * type_c->size_oldtype);
841 ((s_smpi_subtype_t*)type_c->old_type->substruct)->unserialize( contiguous_hindexed_char,
842 noncontiguous_hindexed_char,
843 type_c->block_lengths[i],
844 type_c->old_type->substruct);
846 contiguous_hindexed_char += type_c->block_lengths[i]*type_c->size_oldtype;
847 if (i<type_c->block_count-1)noncontiguous_hindexed_char = (char*)noncontiguous_hindexed + type_c->block_indices[i+1];
848 else noncontiguous_hindexed_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_type);
850 noncontiguous_hindexed=(void*)noncontiguous_hindexed_char;
854 void free_hindexed(MPI_Datatype* type){
855 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_lengths);
856 xbt_free(((s_smpi_mpi_hindexed_t *)(*type)->substruct)->block_indices);
860 * Create a Sub type hindexed to be able to serialize and unserialize it
861 * the structure s_smpi_mpi_hindexed_t is derived from s_smpi_subtype which
862 * required the functions unserialize and serialize
864 s_smpi_mpi_hindexed_t* smpi_datatype_hindexed_create( int* block_lengths,
865 MPI_Aint* block_indices,
867 MPI_Datatype old_type,
869 s_smpi_mpi_hindexed_t *new_t= xbt_new(s_smpi_mpi_hindexed_t,1);
870 new_t->base.serialize = &serialize_hindexed;
871 new_t->base.unserialize = &unserialize_hindexed;
872 new_t->base.subtype_free = &free_hindexed;
873 //TODO : add a custom function for each time to clean these
874 new_t->block_lengths= xbt_new(int, block_count);
875 new_t->block_indices= xbt_new(MPI_Aint, block_count);
877 for(i=0;i<block_count;i++){
878 new_t->block_lengths[i]=block_lengths[i];
879 new_t->block_indices[i]=block_indices[i];
881 new_t->block_count = block_count;
882 new_t->old_type = old_type;
883 new_t->size_oldtype = size_oldtype;
888 int smpi_datatype_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type)
897 lb=indices[0] + smpi_datatype_lb(old_type);
898 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_type);
900 for(i=0; i< count; i++){
903 size += blocklens[i];
905 if(indices[i]+smpi_datatype_lb(old_type)<lb) lb = indices[i]+smpi_datatype_lb(old_type);
906 if(indices[i]+blocklens[i]*smpi_datatype_ub(old_type)>ub) ub = indices[i]+blocklens[i]*smpi_datatype_ub(old_type);
908 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_type) != indices[i+1]) )contiguous=0;
910 if (old_type->has_subtype == 1 || lb!=0)
914 s_smpi_mpi_hindexed_t* subtype = smpi_datatype_hindexed_create( blocklens,
918 smpi_datatype_size(old_type));
919 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
922 ,1, subtype, DT_FLAG_DATA);
924 s_smpi_mpi_contiguous_t* subtype = smpi_datatype_contiguous_create( lb,
927 smpi_datatype_size(old_type));
928 smpi_datatype_create(new_type, size * smpi_datatype_size(old_type),
929 0,size * smpi_datatype_size(old_type),
930 1, subtype, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
938 struct Implementation - Indexed with indices in bytes
942 * Copies noncontiguous data into contiguous memory.
943 * @param contiguous_struct - output struct
944 * @param noncontiguous_struct - input struct
945 * @param type - pointer contening :
946 * - stride - stride of between noncontiguous data
947 * - block_length - the width or height of blocked matrix
948 * - count - the number of rows of matrix
950 void serialize_struct( const void *noncontiguous_struct,
951 void *contiguous_struct,
955 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
957 char* contiguous_struct_char = (char*)contiguous_struct;
958 char* noncontiguous_struct_char = (char*)noncontiguous_struct+ type_c->block_indices[0];
959 for(j=0; j<count;j++){
960 for (i = 0; i < type_c->block_count; i++) {
961 if (type_c->old_types[i]->has_subtype == 0)
962 memcpy(contiguous_struct_char,
963 noncontiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
965 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->serialize( noncontiguous_struct_char,
966 contiguous_struct_char,
967 type_c->block_lengths[i],
968 type_c->old_types[i]->substruct);
971 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
972 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
973 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 ?
975 noncontiguous_struct=(void*)noncontiguous_struct_char;
979 * Copies contiguous data into noncontiguous memory.
980 * @param noncontiguous_struct - output struct
981 * @param contiguous_struct - input struct
982 * @param type - pointer contening :
983 * - stride - stride of between noncontiguous data
984 * - block_length - the width or height of blocked matrix
985 * - count - the number of rows of matrix
987 void unserialize_struct( const void *contiguous_struct,
988 void *noncontiguous_struct,
992 s_smpi_mpi_struct_t* type_c = (s_smpi_mpi_struct_t*)type;
995 char* contiguous_struct_char = (char*)contiguous_struct;
996 char* noncontiguous_struct_char = (char*)noncontiguous_struct+ type_c->block_indices[0];
997 for(j=0; j<count;j++){
998 for (i = 0; i < type_c->block_count; i++) {
999 if (type_c->old_types[i]->has_subtype == 0)
1000 memcpy(noncontiguous_struct_char,
1001 contiguous_struct_char, type_c->block_lengths[i] * smpi_datatype_size(type_c->old_types[i]));
1003 ((s_smpi_subtype_t*)type_c->old_types[i]->substruct)->unserialize( contiguous_struct_char,
1004 noncontiguous_struct_char,
1005 type_c->block_lengths[i],
1006 type_c->old_types[i]->substruct);
1008 contiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_size(type_c->old_types[i]);
1009 if (i<type_c->block_count-1)noncontiguous_struct_char = (char*)noncontiguous_struct + type_c->block_indices[i+1];
1010 else noncontiguous_struct_char += type_c->block_lengths[i]*smpi_datatype_get_extent(type_c->old_types[i]);
1012 noncontiguous_struct=(void*)noncontiguous_struct_char;
1017 void free_struct(MPI_Datatype* type){
1018 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_lengths);
1019 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->block_indices);
1020 xbt_free(((s_smpi_mpi_struct_t *)(*type)->substruct)->old_types);
1024 * Create a Sub type struct to be able to serialize and unserialize it
1025 * the structure s_smpi_mpi_struct_t is derived from s_smpi_subtype which
1026 * required the functions unserialize and serialize
1028 s_smpi_mpi_struct_t* smpi_datatype_struct_create( int* block_lengths,
1029 MPI_Aint* block_indices,
1031 MPI_Datatype* old_types){
1032 s_smpi_mpi_struct_t *new_t= xbt_new(s_smpi_mpi_struct_t,1);
1033 new_t->base.serialize = &serialize_struct;
1034 new_t->base.unserialize = &unserialize_struct;
1035 new_t->base.subtype_free = &free_struct;
1036 //TODO : add a custom function for each time to clean these
1037 new_t->block_lengths= xbt_new(int, block_count);
1038 new_t->block_indices= xbt_new(MPI_Aint, block_count);
1039 new_t->old_types= xbt_new(MPI_Datatype, block_count);
1041 for(i=0;i<block_count;i++){
1042 new_t->block_lengths[i]=block_lengths[i];
1043 new_t->block_indices[i]=block_indices[i];
1044 new_t->old_types[i]=old_types[i];
1046 //new_t->block_lengths = block_lengths;
1047 //new_t->block_indices = block_indices;
1048 new_t->block_count = block_count;
1049 //new_t->old_types = old_types;
1054 int smpi_datatype_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type)
1063 lb=indices[0] + smpi_datatype_lb(old_types[0]);
1064 ub=indices[0] + blocklens[0]*smpi_datatype_ub(old_types[0]);
1068 for(i=0; i< count; i++){
1071 if (old_types[i]->has_subtype == 1)
1074 size += blocklens[i]*smpi_datatype_size(old_types[i]);
1075 if (old_types[i]==MPI_LB){
1079 if (old_types[i]==MPI_UB){
1084 if(!forced_lb && indices[i]+smpi_datatype_lb(old_types[i])<lb) lb = indices[i];
1085 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]);
1087 if ( (i< count -1) && (indices[i]+blocklens[i]*smpi_datatype_size(old_types[i]) != indices[i+1]) )contiguous=0;
1091 s_smpi_mpi_struct_t* subtype = smpi_datatype_struct_create( blocklens,
1096 smpi_datatype_create(new_type, size, lb, ub,1, subtype, DT_FLAG_DATA);
1098 s_smpi_mpi_contiguous_t* subtype = smpi_datatype_contiguous_create( lb,
1102 smpi_datatype_create(new_type, size, lb, ub,1, subtype, DT_FLAG_DATA|DT_FLAG_CONTIGUOUS);
1107 void smpi_datatype_commit(MPI_Datatype *datatype)
1109 (*datatype)->flags= ((*datatype)->flags | DT_FLAG_COMMITED);
1112 typedef struct s_smpi_mpi_op {
1113 MPI_User_function *func;
1117 #define MAX_OP(a, b) (b) = (a) < (b) ? (b) : (a)
1118 #define MIN_OP(a, b) (b) = (a) < (b) ? (a) : (b)
1119 #define SUM_OP(a, b) (b) += (a)
1120 #define PROD_OP(a, b) (b) *= (a)
1121 #define LAND_OP(a, b) (b) = (a) && (b)
1122 #define LOR_OP(a, b) (b) = (a) || (b)
1123 #define LXOR_OP(a, b) (b) = (!(a) && (b)) || ((a) && !(b))
1124 #define BAND_OP(a, b) (b) &= (a)
1125 #define BOR_OP(a, b) (b) |= (a)
1126 #define BXOR_OP(a, b) (b) ^= (a)
1127 #define MAXLOC_OP(a, b) (b) = (a.value) < (b.value) ? (b) : (a)
1128 #define MINLOC_OP(a, b) (b) = (a.value) < (b.value) ? (a) : (b)
1129 //TODO : MINLOC & MAXLOC
1131 #define APPLY_FUNC(a, b, length, type, func) \
1134 type* x = (type*)(a); \
1135 type* y = (type*)(b); \
1136 for(i = 0; i < *(length); i++) { \
1141 static void max_func(void *a, void *b, int *length,
1142 MPI_Datatype * datatype)
1144 if (*datatype == MPI_CHAR) {
1145 APPLY_FUNC(a, b, length, char, MAX_OP);
1146 } else if (*datatype == MPI_SHORT) {
1147 APPLY_FUNC(a, b, length, short, MAX_OP);
1148 } else if (*datatype == MPI_INT) {
1149 APPLY_FUNC(a, b, length, int, MAX_OP);
1150 } else if (*datatype == MPI_LONG) {
1151 APPLY_FUNC(a, b, length, long, MAX_OP);
1152 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1153 APPLY_FUNC(a, b, length, unsigned short, MAX_OP);
1154 } else if (*datatype == MPI_UNSIGNED) {
1155 APPLY_FUNC(a, b, length, unsigned int, MAX_OP);
1156 } else if (*datatype == MPI_UNSIGNED_LONG) {
1157 APPLY_FUNC(a, b, length, unsigned long, MAX_OP);
1158 } else if (*datatype == MPI_FLOAT) {
1159 APPLY_FUNC(a, b, length, float, MAX_OP);
1160 } else if (*datatype == MPI_DOUBLE) {
1161 APPLY_FUNC(a, b, length, double, MAX_OP);
1162 } else if (*datatype == MPI_LONG_DOUBLE) {
1163 APPLY_FUNC(a, b, length, long double, MAX_OP);
1167 static void min_func(void *a, void *b, int *length,
1168 MPI_Datatype * datatype)
1170 if (*datatype == MPI_CHAR) {
1171 APPLY_FUNC(a, b, length, char, MIN_OP);
1172 } else if (*datatype == MPI_SHORT) {
1173 APPLY_FUNC(a, b, length, short, MIN_OP);
1174 } else if (*datatype == MPI_INT) {
1175 APPLY_FUNC(a, b, length, int, MIN_OP);
1176 } else if (*datatype == MPI_LONG) {
1177 APPLY_FUNC(a, b, length, long, MIN_OP);
1178 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1179 APPLY_FUNC(a, b, length, unsigned short, MIN_OP);
1180 } else if (*datatype == MPI_UNSIGNED) {
1181 APPLY_FUNC(a, b, length, unsigned int, MIN_OP);
1182 } else if (*datatype == MPI_UNSIGNED_LONG) {
1183 APPLY_FUNC(a, b, length, unsigned long, MIN_OP);
1184 } else if (*datatype == MPI_FLOAT) {
1185 APPLY_FUNC(a, b, length, float, MIN_OP);
1186 } else if (*datatype == MPI_DOUBLE) {
1187 APPLY_FUNC(a, b, length, double, MIN_OP);
1188 } else if (*datatype == MPI_LONG_DOUBLE) {
1189 APPLY_FUNC(a, b, length, long double, MIN_OP);
1193 static void sum_func(void *a, void *b, int *length,
1194 MPI_Datatype * datatype)
1196 if (*datatype == MPI_CHAR) {
1197 APPLY_FUNC(a, b, length, char, SUM_OP);
1198 } else if (*datatype == MPI_SHORT) {
1199 APPLY_FUNC(a, b, length, short, SUM_OP);
1200 } else if (*datatype == MPI_INT) {
1201 APPLY_FUNC(a, b, length, int, SUM_OP);
1202 } else if (*datatype == MPI_LONG) {
1203 APPLY_FUNC(a, b, length, long, SUM_OP);
1204 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1205 APPLY_FUNC(a, b, length, unsigned short, SUM_OP);
1206 } else if (*datatype == MPI_UNSIGNED) {
1207 APPLY_FUNC(a, b, length, unsigned int, SUM_OP);
1208 } else if (*datatype == MPI_UNSIGNED_LONG) {
1209 APPLY_FUNC(a, b, length, unsigned long, SUM_OP);
1210 } else if (*datatype == MPI_FLOAT) {
1211 APPLY_FUNC(a, b, length, float, SUM_OP);
1212 } else if (*datatype == MPI_DOUBLE) {
1213 APPLY_FUNC(a, b, length, double, SUM_OP);
1214 } else if (*datatype == MPI_LONG_DOUBLE) {
1215 APPLY_FUNC(a, b, length, long double, SUM_OP);
1216 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1217 APPLY_FUNC(a, b, length, float _Complex, SUM_OP);
1218 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1219 APPLY_FUNC(a, b, length, double _Complex, SUM_OP);
1220 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1221 APPLY_FUNC(a, b, length, long double _Complex, SUM_OP);
1225 static void prod_func(void *a, void *b, int *length,
1226 MPI_Datatype * datatype)
1228 if (*datatype == MPI_CHAR) {
1229 APPLY_FUNC(a, b, length, char, PROD_OP);
1230 } else if (*datatype == MPI_SHORT) {
1231 APPLY_FUNC(a, b, length, short, PROD_OP);
1232 } else if (*datatype == MPI_INT) {
1233 APPLY_FUNC(a, b, length, int, PROD_OP);
1234 } else if (*datatype == MPI_LONG) {
1235 APPLY_FUNC(a, b, length, long, PROD_OP);
1236 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1237 APPLY_FUNC(a, b, length, unsigned short, PROD_OP);
1238 } else if (*datatype == MPI_UNSIGNED) {
1239 APPLY_FUNC(a, b, length, unsigned int, PROD_OP);
1240 } else if (*datatype == MPI_UNSIGNED_LONG) {
1241 APPLY_FUNC(a, b, length, unsigned long, PROD_OP);
1242 } else if (*datatype == MPI_FLOAT) {
1243 APPLY_FUNC(a, b, length, float, PROD_OP);
1244 } else if (*datatype == MPI_DOUBLE) {
1245 APPLY_FUNC(a, b, length, double, PROD_OP);
1246 } else if (*datatype == MPI_LONG_DOUBLE) {
1247 APPLY_FUNC(a, b, length, long double, PROD_OP);
1248 } else if (*datatype == MPI_C_FLOAT_COMPLEX) {
1249 APPLY_FUNC(a, b, length, float _Complex, PROD_OP);
1250 } else if (*datatype == MPI_C_DOUBLE_COMPLEX) {
1251 APPLY_FUNC(a, b, length, double _Complex, PROD_OP);
1252 } else if (*datatype == MPI_C_LONG_DOUBLE_COMPLEX) {
1253 APPLY_FUNC(a, b, length, long double _Complex, PROD_OP);
1257 static void land_func(void *a, void *b, int *length,
1258 MPI_Datatype * datatype)
1260 if (*datatype == MPI_CHAR) {
1261 APPLY_FUNC(a, b, length, char, LAND_OP);
1262 } else if (*datatype == MPI_SHORT) {
1263 APPLY_FUNC(a, b, length, short, LAND_OP);
1264 } else if (*datatype == MPI_INT) {
1265 APPLY_FUNC(a, b, length, int, LAND_OP);
1266 } else if (*datatype == MPI_LONG) {
1267 APPLY_FUNC(a, b, length, long, LAND_OP);
1268 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1269 APPLY_FUNC(a, b, length, unsigned short, LAND_OP);
1270 } else if (*datatype == MPI_UNSIGNED) {
1271 APPLY_FUNC(a, b, length, unsigned int, LAND_OP);
1272 } else if (*datatype == MPI_UNSIGNED_LONG) {
1273 APPLY_FUNC(a, b, length, unsigned long, LAND_OP);
1274 } else if (*datatype == MPI_C_BOOL) {
1275 APPLY_FUNC(a, b, length, _Bool, LAND_OP);
1279 static void lor_func(void *a, void *b, int *length,
1280 MPI_Datatype * datatype)
1282 if (*datatype == MPI_CHAR) {
1283 APPLY_FUNC(a, b, length, char, LOR_OP);
1284 } else if (*datatype == MPI_SHORT) {
1285 APPLY_FUNC(a, b, length, short, LOR_OP);
1286 } else if (*datatype == MPI_INT) {
1287 APPLY_FUNC(a, b, length, int, LOR_OP);
1288 } else if (*datatype == MPI_LONG) {
1289 APPLY_FUNC(a, b, length, long, LOR_OP);
1290 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1291 APPLY_FUNC(a, b, length, unsigned short, LOR_OP);
1292 } else if (*datatype == MPI_UNSIGNED) {
1293 APPLY_FUNC(a, b, length, unsigned int, LOR_OP);
1294 } else if (*datatype == MPI_UNSIGNED_LONG) {
1295 APPLY_FUNC(a, b, length, unsigned long, LOR_OP);
1296 } else if (*datatype == MPI_C_BOOL) {
1297 APPLY_FUNC(a, b, length, _Bool, LOR_OP);
1301 static void lxor_func(void *a, void *b, int *length,
1302 MPI_Datatype * datatype)
1304 if (*datatype == MPI_CHAR) {
1305 APPLY_FUNC(a, b, length, char, LXOR_OP);
1306 } else if (*datatype == MPI_SHORT) {
1307 APPLY_FUNC(a, b, length, short, LXOR_OP);
1308 } else if (*datatype == MPI_INT) {
1309 APPLY_FUNC(a, b, length, int, LXOR_OP);
1310 } else if (*datatype == MPI_LONG) {
1311 APPLY_FUNC(a, b, length, long, LXOR_OP);
1312 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1313 APPLY_FUNC(a, b, length, unsigned short, LXOR_OP);
1314 } else if (*datatype == MPI_UNSIGNED) {
1315 APPLY_FUNC(a, b, length, unsigned int, LXOR_OP);
1316 } else if (*datatype == MPI_UNSIGNED_LONG) {
1317 APPLY_FUNC(a, b, length, unsigned long, LXOR_OP);
1318 } else if (*datatype == MPI_C_BOOL) {
1319 APPLY_FUNC(a, b, length, _Bool, LXOR_OP);
1323 static void band_func(void *a, void *b, int *length,
1324 MPI_Datatype * datatype)
1326 if (*datatype == MPI_CHAR) {
1327 APPLY_FUNC(a, b, length, char, BAND_OP);
1329 if (*datatype == MPI_SHORT) {
1330 APPLY_FUNC(a, b, length, short, BAND_OP);
1331 } else if (*datatype == MPI_INT) {
1332 APPLY_FUNC(a, b, length, int, BAND_OP);
1333 } else if (*datatype == MPI_LONG) {
1334 APPLY_FUNC(a, b, length, long, BAND_OP);
1335 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1336 APPLY_FUNC(a, b, length, unsigned short, BAND_OP);
1337 } else if (*datatype == MPI_UNSIGNED) {
1338 APPLY_FUNC(a, b, length, unsigned int, BAND_OP);
1339 } else if (*datatype == MPI_UNSIGNED_LONG) {
1340 APPLY_FUNC(a, b, length, unsigned long, BAND_OP);
1341 } else if (*datatype == MPI_BYTE) {
1342 APPLY_FUNC(a, b, length, uint8_t, BAND_OP);
1346 static void bor_func(void *a, void *b, int *length,
1347 MPI_Datatype * datatype)
1349 if (*datatype == MPI_CHAR) {
1350 APPLY_FUNC(a, b, length, char, BOR_OP);
1351 } else if (*datatype == MPI_SHORT) {
1352 APPLY_FUNC(a, b, length, short, BOR_OP);
1353 } else if (*datatype == MPI_INT) {
1354 APPLY_FUNC(a, b, length, int, BOR_OP);
1355 } else if (*datatype == MPI_LONG) {
1356 APPLY_FUNC(a, b, length, long, BOR_OP);
1357 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1358 APPLY_FUNC(a, b, length, unsigned short, BOR_OP);
1359 } else if (*datatype == MPI_UNSIGNED) {
1360 APPLY_FUNC(a, b, length, unsigned int, BOR_OP);
1361 } else if (*datatype == MPI_UNSIGNED_LONG) {
1362 APPLY_FUNC(a, b, length, unsigned long, BOR_OP);
1363 } else if (*datatype == MPI_BYTE) {
1364 APPLY_FUNC(a, b, length, uint8_t, BOR_OP);
1368 static void bxor_func(void *a, void *b, int *length,
1369 MPI_Datatype * datatype)
1371 if (*datatype == MPI_CHAR) {
1372 APPLY_FUNC(a, b, length, char, BXOR_OP);
1373 } else if (*datatype == MPI_SHORT) {
1374 APPLY_FUNC(a, b, length, short, BXOR_OP);
1375 } else if (*datatype == MPI_INT) {
1376 APPLY_FUNC(a, b, length, int, BXOR_OP);
1377 } else if (*datatype == MPI_LONG) {
1378 APPLY_FUNC(a, b, length, long, BXOR_OP);
1379 } else if (*datatype == MPI_UNSIGNED_SHORT) {
1380 APPLY_FUNC(a, b, length, unsigned short, BXOR_OP);
1381 } else if (*datatype == MPI_UNSIGNED) {
1382 APPLY_FUNC(a, b, length, unsigned int, BXOR_OP);
1383 } else if (*datatype == MPI_UNSIGNED_LONG) {
1384 APPLY_FUNC(a, b, length, unsigned long, BXOR_OP);
1385 } else if (*datatype == MPI_BYTE) {
1386 APPLY_FUNC(a, b, length, uint8_t, BXOR_OP);
1390 static void minloc_func(void *a, void *b, int *length,
1391 MPI_Datatype * datatype)
1393 if (*datatype == MPI_FLOAT_INT) {
1394 APPLY_FUNC(a, b, length, float_int, MINLOC_OP);
1395 } else if (*datatype == MPI_LONG_INT) {
1396 APPLY_FUNC(a, b, length, long_int, MINLOC_OP);
1397 } else if (*datatype == MPI_DOUBLE_INT) {
1398 APPLY_FUNC(a, b, length, double_int, MINLOC_OP);
1399 } else if (*datatype == MPI_SHORT_INT) {
1400 APPLY_FUNC(a, b, length, short_int, MINLOC_OP);
1401 } else if (*datatype == MPI_2INT) {
1402 APPLY_FUNC(a, b, length, int_int, MINLOC_OP);
1403 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1404 APPLY_FUNC(a, b, length, long_double_int, MINLOC_OP);
1405 } else if (*datatype == MPI_2FLOAT) {
1406 APPLY_FUNC(a, b, length, float_float, MINLOC_OP);
1407 } else if (*datatype == MPI_2DOUBLE) {
1408 APPLY_FUNC(a, b, length, double_double, MINLOC_OP);
1412 static void maxloc_func(void *a, void *b, int *length,
1413 MPI_Datatype * datatype)
1415 if (*datatype == MPI_FLOAT_INT) {
1416 APPLY_FUNC(a, b, length, float_int, MAXLOC_OP);
1417 } else if (*datatype == MPI_LONG_INT) {
1418 APPLY_FUNC(a, b, length, long_int, MAXLOC_OP);
1419 } else if (*datatype == MPI_DOUBLE_INT) {
1420 APPLY_FUNC(a, b, length, double_int, MAXLOC_OP);
1421 } else if (*datatype == MPI_SHORT_INT) {
1422 APPLY_FUNC(a, b, length, short_int, MAXLOC_OP);
1423 } else if (*datatype == MPI_2INT) {
1424 APPLY_FUNC(a, b, length, int_int, MAXLOC_OP);
1425 } else if (*datatype == MPI_LONG_DOUBLE_INT) {
1426 APPLY_FUNC(a, b, length, long_double_int, MAXLOC_OP);
1427 } else if (*datatype == MPI_2FLOAT) {
1428 APPLY_FUNC(a, b, length, float_float, MAXLOC_OP);
1429 } else if (*datatype == MPI_2DOUBLE) {
1430 APPLY_FUNC(a, b, length, double_double, MAXLOC_OP);
1435 #define CREATE_MPI_OP(name, func) \
1436 static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */, TRUE }; \
1437 MPI_Op name = &mpi_##name;
1439 CREATE_MPI_OP(MPI_MAX, max_func);
1440 CREATE_MPI_OP(MPI_MIN, min_func);
1441 CREATE_MPI_OP(MPI_SUM, sum_func);
1442 CREATE_MPI_OP(MPI_PROD, prod_func);
1443 CREATE_MPI_OP(MPI_LAND, land_func);
1444 CREATE_MPI_OP(MPI_LOR, lor_func);
1445 CREATE_MPI_OP(MPI_LXOR, lxor_func);
1446 CREATE_MPI_OP(MPI_BAND, band_func);
1447 CREATE_MPI_OP(MPI_BOR, bor_func);
1448 CREATE_MPI_OP(MPI_BXOR, bxor_func);
1449 CREATE_MPI_OP(MPI_MAXLOC, maxloc_func);
1450 CREATE_MPI_OP(MPI_MINLOC, minloc_func);
1452 MPI_Op smpi_op_new(MPI_User_function * function, int commute)
1455 op = xbt_new(s_smpi_mpi_op_t, 1);
1456 op->func = function;
1457 op-> is_commute = commute;
1461 int smpi_op_is_commute(MPI_Op op)
1463 return (op==MPI_OP_NULL) ? 1 : op-> is_commute;
1466 void smpi_op_destroy(MPI_Op op)
1471 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
1472 MPI_Datatype * datatype)
1474 op->func(invec, inoutvec, len, datatype);