Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move all smpi colls to cpp.
[simgrid.git] / src / smpi / smpi_comm.cpp
1 /* Copyright (c) 2010-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdlib.h>
8 #include <limits.h>
9
10 #include <xbt/dict.h>
11 #include <xbt/ex.h>
12 #include <xbt/ex.hpp>
13
14 #include <simgrid/s4u/host.hpp>
15
16 #include "private.h"
17 #include "smpi_mpi_dt_private.h"
18 #include "src/simix/smx_private.h"
19 #include "colls/colls.h"
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_comm, smpi, "Logging specific to SMPI (comm)");
22
23 xbt_dict_t smpi_comm_keyvals = nullptr;
24 int comm_keyval_id = 0;//avoid collisions
25
26 /* Support for cartesian topology was added, but there are 2 other types of topology, graph et dist graph. In order to
27  * support them, we have to add a field MPIR_Topo_type, and replace the MPI_Topology field by an union. */
28
29 typedef struct s_smpi_mpi_communicator {
30   MPI_Group group;
31   MPIR_Topo_type topoType; 
32   MPI_Topology topo; // to be replaced by an union
33   int refcount;
34   MPI_Comm leaders_comm;//inter-node communicator
35   MPI_Comm intra_comm;//intra-node communicator . For MPI_COMM_WORLD this can't be used, as var is global.
36   //use an intracomm stored in the process data instead
37   int* leaders_map; //who is the leader of each process
38   int is_uniform;
39   int* non_uniform_map; //set if smp nodes have a different number of processes allocated
40   int is_blocked;// are ranks allocated on the same smp node contiguous ?
41   xbt_dict_t attributes;
42 } s_smpi_mpi_communicator_t;
43
44 static int smpi_compare_rankmap(const void *a, const void *b)
45 {
46   const int* x = static_cast<const int*>(a);
47   const int* y = static_cast<const int*>(b);
48
49   if (x[1] < y[1]) {
50     return -1;
51   }
52   if (x[1] == y[1]) {
53     if (x[0] < y[0]) {
54       return -1;
55     }
56     if (x[0] == y[0]) {
57       return 0;
58     }
59     return 1;
60   }
61   return 1;
62 }
63
64 MPI_Comm smpi_comm_new(MPI_Group group, MPI_Topology topo)
65 {
66   MPI_Comm comm;
67
68   comm = xbt_new(s_smpi_mpi_communicator_t, 1);
69   comm->group = group;
70   comm->refcount=1;
71   comm->topoType = MPI_INVALID_TOPO;
72   comm->topo = topo;
73   comm->intra_comm = MPI_COMM_NULL;
74   comm->leaders_comm = MPI_COMM_NULL;
75   comm->is_uniform=1;
76   comm->non_uniform_map = nullptr;
77   comm->leaders_map = nullptr;
78   comm->is_blocked=0;
79   comm->attributes=nullptr;
80   return comm;
81 }
82
83 void smpi_comm_destroy(MPI_Comm comm)
84 {
85   if (comm == MPI_COMM_UNINITIALIZED)
86     comm = smpi_process_comm_world();
87   smpi_topo_destroy(comm->topo); // there's no use count on topos
88   smpi_comm_unuse(comm);
89 }
90
91 int smpi_comm_dup(MPI_Comm comm, MPI_Comm* newcomm){
92   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
93      smpi_switch_data_segment(smpi_process_index());
94    }
95   MPI_Group cp=smpi_group_copy(smpi_comm_group(comm));
96   (*newcomm) = smpi_comm_new(cp, smpi_comm_topo(comm));
97   int ret = MPI_SUCCESS;
98
99   if(comm->attributes !=nullptr){
100     (*newcomm)->attributes   = xbt_dict_new_homogeneous(nullptr);
101     xbt_dict_cursor_t cursor = nullptr;
102     char* key;
103     int flag;
104     void* value_in;
105     void* value_out;
106     xbt_dict_foreach (comm->attributes, cursor, key, value_in) {
107       smpi_comm_key_elem elem =
108           static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, key, sizeof(int)));
109       if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) {
110         ret = elem->copy_fn(comm, atoi(key), nullptr, value_in, &value_out, &flag);
111         if (ret != MPI_SUCCESS) {
112           smpi_comm_destroy(*newcomm);
113           *newcomm = MPI_COMM_NULL;
114           xbt_dict_cursor_free(&cursor);
115           return ret;
116         }
117         if (flag)
118           xbt_dict_set_ext((*newcomm)->attributes, key, sizeof(int), value_out, nullptr);
119       }
120       }
121     }
122   return ret;
123 }
124
125 MPI_Group smpi_comm_group(MPI_Comm comm)
126 {
127   if (comm == MPI_COMM_UNINITIALIZED)
128     comm = smpi_process_comm_world();
129   return comm->group;
130 }
131
132 MPI_Topology smpi_comm_topo(MPI_Comm comm) {
133   if (comm != MPI_COMM_NULL)
134     return comm->topo;
135   return nullptr;
136 }
137
138 int smpi_comm_size(MPI_Comm comm)
139 {
140   if (comm == MPI_COMM_UNINITIALIZED)
141     comm = smpi_process_comm_world();
142   return smpi_group_size(smpi_comm_group(comm));
143 }
144
145 int smpi_comm_rank(MPI_Comm comm)
146 {
147   if (comm == MPI_COMM_UNINITIALIZED)
148     comm = smpi_process_comm_world();
149   return smpi_group_rank(smpi_comm_group(comm), smpi_process_index());
150 }
151
152 void smpi_comm_get_name (MPI_Comm comm, char* name, int* len)
153 {
154   if (comm == MPI_COMM_UNINITIALIZED)
155     comm = smpi_process_comm_world();
156   if(comm == MPI_COMM_WORLD) {
157     strncpy(name, "WORLD",5);
158     *len = 5;
159   } else {
160     *len = snprintf(name, MPI_MAX_NAME_STRING, "%p", comm);
161   }
162 }
163
164 void smpi_comm_set_leaders_comm(MPI_Comm comm, MPI_Comm leaders){
165   if (comm == MPI_COMM_UNINITIALIZED)
166     comm = smpi_process_comm_world();
167   comm->leaders_comm=leaders;
168 }
169
170 void smpi_comm_set_intra_comm(MPI_Comm comm, MPI_Comm leaders){
171   comm->intra_comm=leaders;
172 }
173
174 int* smpi_comm_get_non_uniform_map(MPI_Comm comm){
175   if (comm == MPI_COMM_UNINITIALIZED)
176     comm = smpi_process_comm_world();
177   return comm->non_uniform_map;
178 }
179
180 int* smpi_comm_get_leaders_map(MPI_Comm comm){
181   if (comm == MPI_COMM_UNINITIALIZED)
182     comm = smpi_process_comm_world();
183   return comm->leaders_map;
184 }
185
186 MPI_Comm smpi_comm_get_leaders_comm(MPI_Comm comm){
187   if (comm == MPI_COMM_UNINITIALIZED)
188     comm = smpi_process_comm_world();
189   return comm->leaders_comm;
190 }
191
192 MPI_Comm smpi_comm_get_intra_comm(MPI_Comm comm){
193   if (comm == MPI_COMM_UNINITIALIZED || comm==MPI_COMM_WORLD) 
194     return smpi_process_get_comm_intra();
195   else return comm->intra_comm;
196 }
197
198 int smpi_comm_is_uniform(MPI_Comm comm){
199   if (comm == MPI_COMM_UNINITIALIZED)
200     comm = smpi_process_comm_world();
201   return comm->is_uniform;
202 }
203
204 int smpi_comm_is_blocked(MPI_Comm comm){
205   if (comm == MPI_COMM_UNINITIALIZED)
206     comm = smpi_process_comm_world();
207   return comm->is_blocked;
208 }
209
210 MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key)
211 {
212   if (comm == MPI_COMM_UNINITIALIZED)
213     comm = smpi_process_comm_world();
214   int system_tag = 123;
215   int* recvbuf;
216
217   MPI_Group group_root = nullptr;
218   MPI_Group group_out  = nullptr;
219   MPI_Group group      = smpi_comm_group(comm);
220   int rank             = smpi_comm_rank(comm);
221   int size             = smpi_comm_size(comm);
222   /* Gather all colors and keys on rank 0 */
223   int* sendbuf = xbt_new(int, 2);
224   sendbuf[0] = color;
225   sendbuf[1] = key;
226   if(rank == 0) {
227     recvbuf = xbt_new(int, 2 * size);
228   } else {
229     recvbuf = nullptr;
230   }
231   smpi_mpi_gather(sendbuf, 2, MPI_INT, recvbuf, 2, MPI_INT, 0, comm);
232   xbt_free(sendbuf);
233   /* Do the actual job */
234   if(rank == 0) {
235     MPI_Group* group_snd = xbt_new(MPI_Group, size);
236     int* rankmap         = xbt_new(int, 2 * size);
237     for (int i = 0; i < size; i++) {
238       if (recvbuf[2 * i] != MPI_UNDEFINED) {
239         int count = 0;
240         for (int j = i + 1; j < size; j++) {
241           if(recvbuf[2 * i] == recvbuf[2 * j]) {
242             recvbuf[2 * j] = MPI_UNDEFINED;
243             rankmap[2 * count] = j;
244             rankmap[2 * count + 1] = recvbuf[2 * j + 1];
245             count++;
246           }
247         }
248         /* Add self in the group */
249         recvbuf[2 * i] = MPI_UNDEFINED;
250         rankmap[2 * count] = i;
251         rankmap[2 * count + 1] = recvbuf[2 * i + 1];
252         count++;
253         qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
254         group_out = smpi_group_new(count);
255         if (i == 0) {
256           group_root = group_out; /* Save root's group */
257         }
258         for (int j = 0; j < count; j++) {
259           int index = smpi_group_index(group, rankmap[2 * j]);
260           smpi_group_set_mapping(group_out, index, j);
261         }
262         MPI_Request* requests = xbt_new(MPI_Request, count);
263         int reqs              = 0;
264         for (int j = 0; j < count; j++) {
265           if(rankmap[2 * j] != 0) {
266             group_snd[reqs]=smpi_group_copy(group_out);
267             requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, comm);
268             reqs++;
269           }
270         }
271         if(i != 0) {
272           smpi_group_destroy(group_out);
273         }
274         smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
275         xbt_free(requests);
276       }
277     }
278     xbt_free(recvbuf);
279     xbt_free(rankmap);
280     xbt_free(group_snd);
281     group_out = group_root; /* exit with root's group */
282   } else {
283     if(color != MPI_UNDEFINED) {
284       smpi_mpi_recv(&group_out, 1, MPI_PTR, 0, system_tag, comm, MPI_STATUS_IGNORE);
285     } /* otherwise, exit with group_out == nullptr */
286   }
287   return group_out!=nullptr ? smpi_comm_new(group_out, nullptr) : MPI_COMM_NULL;
288 }
289
290 void smpi_comm_use(MPI_Comm comm){
291   if (comm == MPI_COMM_UNINITIALIZED)
292     comm = smpi_process_comm_world();
293   smpi_group_use(comm->group);
294   comm->refcount++;
295 }
296
297 void smpi_comm_cleanup_attributes(MPI_Comm comm){
298   if(comm->attributes !=nullptr){
299     xbt_dict_cursor_t cursor = nullptr;
300     char* key;
301     void* value;
302     int flag;
303     xbt_dict_foreach (comm->attributes, cursor, key, value) {
304       smpi_comm_key_elem elem = static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null(smpi_comm_keyvals, key));
305       if (elem != nullptr && elem->delete_fn != nullptr)
306         elem->delete_fn(comm, atoi(key), value, &flag);
307     }
308     xbt_dict_free(&comm->attributes);
309   }
310 }
311
312 void smpi_comm_cleanup_smp(MPI_Comm comm){
313   if (comm->intra_comm != MPI_COMM_NULL)
314     smpi_comm_unuse(comm->intra_comm);
315   if (comm->leaders_comm != MPI_COMM_NULL)
316     smpi_comm_unuse(comm->leaders_comm);
317   if (comm->non_uniform_map != nullptr)
318     xbt_free(comm->non_uniform_map);
319   if (comm->leaders_map != nullptr)
320     xbt_free(comm->leaders_map);
321 }
322
323 void smpi_comm_unuse(MPI_Comm comm){
324   if (comm == MPI_COMM_UNINITIALIZED)
325     comm = smpi_process_comm_world();
326   comm->refcount--;
327   smpi_group_unuse(comm->group);
328
329   if(comm->refcount==0){
330     smpi_comm_cleanup_smp(comm);
331     smpi_comm_cleanup_attributes(comm);
332     xbt_free(comm);
333   }
334 }
335
336 static int compare_ints (const void *a, const void *b)
337 {
338   const int *da = static_cast<const int *>(a);
339   const int *db = static_cast<const int *>(b);
340
341   return static_cast<int>(*da > *db) - static_cast<int>(*da < *db);
342 }
343
344 void smpi_comm_init_smp(MPI_Comm comm){
345   int leader = -1;
346
347   if (comm == MPI_COMM_UNINITIALIZED)
348     comm = smpi_process_comm_world();
349
350   int comm_size =smpi_comm_size(comm);
351   
352   // If we are in replay - perform an ugly hack  
353   // tell SimGrid we are not in replay for a while, because we need the buffers to be copied for the following calls
354   bool replaying = false; //cache data to set it back again after
355   if(smpi_process_get_replaying()){
356    replaying=true;
357    smpi_process_set_replaying(false);
358   }
359
360   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
361      smpi_switch_data_segment(smpi_process_index());
362    }
363   //identify neighbours in comm
364   //get the indexes of all processes sharing the same simix host
365   xbt_swag_t process_list = SIMIX_host_self()->processes();
366   int intra_comm_size = 0;
367   int i =0;
368   int min_index=INT_MAX;//the minimum index will be the leader
369   smx_actor_t process = nullptr;
370   xbt_swag_foreach(process, process_list) {
371     int index = process->pid -1;
372
373     if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
374         intra_comm_size++;
375       //the process is in the comm
376       if(index < min_index)
377         min_index=index;
378       i++;
379     }
380   }
381   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
382   MPI_Group group_intra = smpi_group_new(intra_comm_size);
383   i=0;
384   process = nullptr;
385   xbt_swag_foreach(process, process_list) {
386     int index = process->pid -1;
387     if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
388       smpi_group_set_mapping(group_intra, index, i);
389       i++;
390     }
391   }
392
393   MPI_Comm comm_intra = smpi_comm_new(group_intra, nullptr);
394   leader=min_index;
395
396   int * leaders_map= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
397   int * leader_list= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
398   for(i=0; i<comm_size; i++){
399       leader_list[i]=-1;
400   }
401
402   smpi_coll_tuned_allgather_mpich(&leader, 1, MPI_INT , leaders_map, 1, MPI_INT, comm);
403
404   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
405      smpi_switch_data_segment(smpi_process_index());
406    }
407
408   if(comm->leaders_map==nullptr){
409     comm->leaders_map= leaders_map;
410   }else{
411     xbt_free(leaders_map);
412   }
413   int j=0;
414   int leader_group_size = 0;
415   for(i=0; i<comm_size; i++){
416       int already_done=0;
417       for(j=0;j<leader_group_size; j++){
418         if(comm->leaders_map[i]==leader_list[j]){
419             already_done=1;
420         }
421       }
422       if(already_done==0){
423         leader_list[leader_group_size]=comm->leaders_map[i];
424         leader_group_size++;
425       }
426   }
427   qsort(leader_list, leader_group_size, sizeof(int),compare_ints);
428
429   MPI_Group leaders_group = smpi_group_new(leader_group_size);
430
431   MPI_Comm leader_comm = MPI_COMM_NULL;
432   if(MPI_COMM_WORLD!=MPI_COMM_UNINITIALIZED && comm!=MPI_COMM_WORLD){
433     //create leader_communicator
434     for (i=0; i< leader_group_size;i++)
435       smpi_group_set_mapping(leaders_group, leader_list[i], i);
436     leader_comm = smpi_comm_new(leaders_group, nullptr);
437     smpi_comm_set_leaders_comm(comm, leader_comm);
438     smpi_comm_set_intra_comm(comm, comm_intra);
439
440    //create intracommunicator
441   }else{
442     for (i=0; i< leader_group_size;i++)
443       smpi_group_set_mapping(leaders_group, leader_list[i], i);
444
445     if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
446       leader_comm = smpi_comm_new(leaders_group, nullptr);
447       smpi_comm_set_leaders_comm(comm, leader_comm);
448     }else{
449       leader_comm=smpi_comm_get_leaders_comm(comm);
450       smpi_group_unuse(leaders_group);
451     }
452     smpi_process_set_comm_intra(comm_intra);
453   }
454
455   int is_uniform = 1;
456
457   // Are the nodes uniform ? = same number of process/node
458   int my_local_size=smpi_comm_size(comm_intra);
459   if(smpi_comm_rank(comm_intra)==0) {
460     int* non_uniform_map = xbt_new0(int,leader_group_size);
461     smpi_coll_tuned_allgather_mpich(&my_local_size, 1, MPI_INT,
462         non_uniform_map, 1, MPI_INT, leader_comm);
463     for(i=0; i < leader_group_size; i++) {
464       if(non_uniform_map[0] != non_uniform_map[i]) {
465         is_uniform = 0;
466         break;
467       }
468     }
469     if(is_uniform==0 && smpi_comm_is_uniform(comm)!=0){
470         comm->non_uniform_map= non_uniform_map;
471     }else{
472         xbt_free(non_uniform_map);
473     }
474     comm->is_uniform=is_uniform;
475   }
476   smpi_coll_tuned_bcast_mpich(&(comm->is_uniform),1, MPI_INT, 0, comm_intra );
477
478   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
479      smpi_switch_data_segment(smpi_process_index());
480    }
481   // Are the ranks blocked ? = allocated contiguously on the SMP nodes
482   int is_blocked=1;
483   int prev=smpi_group_rank(smpi_comm_group(comm), smpi_group_index(smpi_comm_group(comm_intra), 0));
484     for (i=1; i<my_local_size; i++){
485       int that=smpi_group_rank(smpi_comm_group(comm),smpi_group_index(smpi_comm_group(comm_intra), i));
486       if(that!=prev+1){
487         is_blocked=0;
488         break;
489       }
490       prev = that;
491   }
492
493   int global_blocked;
494   smpi_mpi_allreduce(&is_blocked, &(global_blocked), 1, MPI_INT, MPI_LAND, comm);
495
496   if(MPI_COMM_WORLD==MPI_COMM_UNINITIALIZED || comm==MPI_COMM_WORLD){
497     if(smpi_comm_rank(comm)==0){
498         comm->is_blocked=global_blocked;
499     }
500   }else{
501     comm->is_blocked=global_blocked;
502   }
503   xbt_free(leader_list);
504   
505   if(replaying)
506     smpi_process_set_replaying(true); 
507 }
508
509 int smpi_comm_attr_delete(MPI_Comm comm, int keyval){
510   smpi_comm_key_elem elem =
511      static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
512   if(elem==nullptr)
513     return MPI_ERR_ARG;
514   if(elem->delete_fn!=MPI_NULL_DELETE_FN){
515     void* value = nullptr;
516     int flag;
517     if(smpi_comm_attr_get(comm, keyval, &value, &flag)==MPI_SUCCESS){
518       int ret = elem->delete_fn(comm, keyval, value, &flag);
519       if(ret!=MPI_SUCCESS) 
520         return ret;
521     }
522   }
523   if(comm->attributes==nullptr)
524     return MPI_ERR_ARG;
525
526   xbt_dict_remove_ext(comm->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
527   return MPI_SUCCESS;
528 }
529
530 int smpi_comm_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
531   smpi_comm_key_elem elem =
532     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
533   if(elem==nullptr)
534     return MPI_ERR_ARG;
535   if(comm->attributes==nullptr){
536     *flag=0;
537     return MPI_SUCCESS;
538   }
539   try {
540     *static_cast<void**>(attr_value) =
541         xbt_dict_get_ext(comm->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
542     *flag=1;
543   }
544   catch (xbt_ex& ex) {
545     *flag=0;
546   }
547   return MPI_SUCCESS;
548 }
549
550 int smpi_comm_attr_put(MPI_Comm comm, int keyval, void* attr_value){
551   if(smpi_comm_keyvals==nullptr)
552     smpi_comm_keyvals = xbt_dict_new_homogeneous(nullptr);
553   smpi_comm_key_elem elem =
554     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(&keyval), sizeof(int)));
555   if(elem==nullptr)
556     return MPI_ERR_ARG;
557   int flag;
558   void* value = nullptr;
559   smpi_comm_attr_get(comm, keyval, &value, &flag);
560   if(flag!=0 && elem->delete_fn!=MPI_NULL_DELETE_FN){
561     int ret = elem->delete_fn(comm, keyval, value, &flag);
562     if(ret!=MPI_SUCCESS) 
563       return ret;
564   }
565   if(comm->attributes==nullptr)
566     comm->attributes = xbt_dict_new_homogeneous(nullptr);
567
568   xbt_dict_set_ext(comm->attributes,  reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
569   return MPI_SUCCESS;
570 }
571
572 int smpi_comm_keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
573                             void* extra_state){
574   if(smpi_comm_keyvals==nullptr)
575     smpi_comm_keyvals = xbt_dict_new_homogeneous(nullptr);
576
577   smpi_comm_key_elem value = static_cast<smpi_comm_key_elem>(xbt_new0(s_smpi_mpi_comm_key_elem_t,1));
578
579   value->copy_fn=copy_fn;
580   value->delete_fn=delete_fn;
581
582   *keyval = comm_keyval_id;
583   xbt_dict_set_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(keyval), sizeof(int),static_cast<void*>(value), nullptr);
584   comm_keyval_id++;
585   return MPI_SUCCESS;
586 }
587
588 int smpi_comm_keyval_free(int* keyval){
589   smpi_comm_key_elem elem =
590      static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int)));
591   if(elem==nullptr)
592     return MPI_ERR_ARG;
593   xbt_dict_remove_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int));
594   xbt_free(elem);
595   return MPI_SUCCESS;
596 }