Logo AND Algorithmique Numérique Distribuée

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