Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a smpi/grow-injected-times option.
[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();
101       xbt_dict_cursor_t cursor = nullptr;
102       int *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, reinterpret_cast<const char*>(key), sizeof(int)));
109         if(elem!=nullptr && elem->copy_fn!=MPI_NULL_COPY_FN){
110           ret = elem->copy_fn(comm, *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, reinterpret_cast<const char*>(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 index, rank, size, i, j, count, reqs;
216   int* sendbuf;
217   int* recvbuf;
218   int* rankmap;
219   MPI_Group group, group_root, group_out;
220   MPI_Group* group_snd;
221   MPI_Request* requests;
222
223   group_root = nullptr;
224   group_out = nullptr;
225   group = smpi_comm_group(comm);
226   rank = smpi_comm_rank(comm);
227   size = smpi_comm_size(comm);
228   /* Gather all colors and keys on rank 0 */
229   sendbuf = xbt_new(int, 2);
230   sendbuf[0] = color;
231   sendbuf[1] = key;
232   if(rank == 0) {
233     recvbuf = xbt_new(int, 2 * size);
234   } else {
235     recvbuf = nullptr;
236   }
237   smpi_mpi_gather(sendbuf, 2, MPI_INT, recvbuf, 2, MPI_INT, 0, comm);
238   xbt_free(sendbuf);
239   /* Do the actual job */
240   if(rank == 0) {
241     group_snd = xbt_new(MPI_Group, size);
242     rankmap = xbt_new(int, 2 * size);
243     for(i = 0; i < size; i++) {
244       if(recvbuf[2 * i] != MPI_UNDEFINED) {
245       
246         count = 0;
247         for(j = i + 1; j < size; j++)  {
248           if(recvbuf[2 * i] == recvbuf[2 * j]) {
249             recvbuf[2 * j] = MPI_UNDEFINED;
250             rankmap[2 * count] = j;
251             rankmap[2 * count + 1] = recvbuf[2 * j + 1];
252             count++;
253           }
254         }
255         /* Add self in the group */
256         recvbuf[2 * i] = MPI_UNDEFINED;
257         rankmap[2 * count] = i;
258         rankmap[2 * count + 1] = recvbuf[2 * i + 1];
259         count++;
260         qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
261         group_out = smpi_group_new(count);
262         if(i == 0) {
263           group_root = group_out; /* Save root's group */
264         }
265         for(j = 0; j < count; j++) {
266           index = smpi_group_index(group, rankmap[2 * j]);
267           smpi_group_set_mapping(group_out, index, j);
268         }
269         requests = xbt_new(MPI_Request, count);
270         reqs = 0;
271         for(j = 0; j < count; j++) {
272           if(rankmap[2 * j] != 0) {
273             group_snd[reqs]=smpi_group_copy(group_out);
274             requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, comm);
275             reqs++;
276           }
277         }
278         if(i != 0) {
279           smpi_group_destroy(group_out);
280         }
281         smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
282         xbt_free(requests);
283       }
284     }
285     xbt_free(recvbuf);
286     xbt_free(rankmap);
287     xbt_free(group_snd);
288     group_out = group_root; /* exit with root's group */
289   } else {
290     if(color != MPI_UNDEFINED) {
291       smpi_mpi_recv(&group_out, 1, MPI_PTR, 0, system_tag, comm, MPI_STATUS_IGNORE);
292     } /* otherwise, exit with group_out == nullptr */
293   }
294   return group_out!=nullptr ? smpi_comm_new(group_out, nullptr) : MPI_COMM_NULL;
295 }
296
297 void smpi_comm_use(MPI_Comm comm){
298   if (comm == MPI_COMM_UNINITIALIZED)
299     comm = smpi_process_comm_world();
300   smpi_group_use(comm->group);
301   comm->refcount++;
302 }
303
304 void smpi_comm_cleanup_attributes(MPI_Comm comm){
305   if(comm->attributes !=nullptr){
306     xbt_dict_cursor_t cursor = nullptr;
307     int* key;
308     void * value;
309     int flag;
310     xbt_dict_foreach(comm->attributes, cursor, key, value){
311       smpi_comm_key_elem elem =
312          static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null(smpi_comm_keyvals, reinterpret_cast<const char*>(key)));
313       if(elem!=nullptr &&  elem->delete_fn!=nullptr)
314         elem->delete_fn(comm, *key, value, &flag);
315     }
316     xbt_dict_free(&comm->attributes);
317   }
318 }
319
320 void smpi_comm_cleanup_smp(MPI_Comm comm){
321     if(comm->intra_comm != MPI_COMM_NULL)
322       smpi_comm_unuse(comm->intra_comm);
323     if(comm->leaders_comm != MPI_COMM_NULL)
324       smpi_comm_unuse(comm->leaders_comm);
325     if(comm->non_uniform_map !=nullptr)
326       xbt_free(comm->non_uniform_map);
327     if(comm->leaders_map !=nullptr)
328       xbt_free(comm->leaders_map);
329 }
330
331 void smpi_comm_unuse(MPI_Comm comm){
332   if (comm == MPI_COMM_UNINITIALIZED)
333     comm = smpi_process_comm_world();
334   comm->refcount--;
335   smpi_group_unuse(comm->group);
336
337   if(comm->refcount==0){
338     smpi_comm_cleanup_smp(comm);
339     smpi_comm_cleanup_attributes(comm);
340     xbt_free(comm);
341   }
342 }
343
344 static int compare_ints (const void *a, const void *b)
345 {
346   const int *da = static_cast<const int *>(a);
347   const int *db = static_cast<const int *>(b);
348
349   return static_cast<int>(*da > *db) - static_cast<int>(*da < *db);
350 }
351
352 void smpi_comm_init_smp(MPI_Comm comm){
353   int leader = -1;
354
355   if (comm == MPI_COMM_UNINITIALIZED)
356     comm = smpi_process_comm_world();
357
358   int comm_size =smpi_comm_size(comm);
359   
360   // If we are in replay - perform an ugly hack  
361   // tell SimGrid we are not in replay for a while, because we need the buffers to be copied for the following calls
362   bool replaying = false; //cache data to set it back again after
363   if(smpi_process_get_replaying()){
364    replaying=true;
365    smpi_process_set_replaying(false);
366   }
367
368   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
369      smpi_switch_data_segment(smpi_process_index());
370    }
371   //identify neighbours in comm
372   //get the indexes of all processes sharing the same simix host
373   xbt_swag_t process_list = SIMIX_host_self()->processes();
374   int intra_comm_size = 0;
375   int i =0;
376   int min_index=INT_MAX;//the minimum index will be the leader
377   smx_actor_t process = nullptr;
378   xbt_swag_foreach(process, process_list) {
379     int index = process->pid -1;
380
381     if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
382         intra_comm_size++;
383       //the process is in the comm
384       if(index < min_index)
385         min_index=index;
386       i++;
387     }
388   }
389   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
390   MPI_Group group_intra = smpi_group_new(intra_comm_size);
391   i=0;
392   process = nullptr;
393   xbt_swag_foreach(process, process_list) {
394     int index = process->pid -1;
395     if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
396       smpi_group_set_mapping(group_intra, index, i);
397       i++;
398     }
399   }
400
401   MPI_Comm comm_intra = smpi_comm_new(group_intra, nullptr);
402   leader=min_index;
403
404   int * leaders_map= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
405   int * leader_list= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
406   for(i=0; i<comm_size; i++){
407       leader_list[i]=-1;
408   }
409
410   smpi_coll_tuned_allgather_mpich(&leader, 1, MPI_INT , leaders_map, 1, MPI_INT, comm);
411
412   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
413      smpi_switch_data_segment(smpi_process_index());
414    }
415
416   if(comm->leaders_map==nullptr){
417     comm->leaders_map= leaders_map;
418   }else{
419     xbt_free(leaders_map);
420   }
421   int j=0;
422   int leader_group_size = 0;
423   for(i=0; i<comm_size; i++){
424       int already_done=0;
425       for(j=0;j<leader_group_size; j++){
426         if(comm->leaders_map[i]==leader_list[j]){
427             already_done=1;
428         }
429       }
430       if(already_done==0){
431         leader_list[leader_group_size]=comm->leaders_map[i];
432         leader_group_size++;
433       }
434   }
435   qsort(leader_list, leader_group_size, sizeof(int),compare_ints);
436
437   MPI_Group leaders_group = smpi_group_new(leader_group_size);
438
439   MPI_Comm leader_comm = MPI_COMM_NULL;
440   if(MPI_COMM_WORLD!=MPI_COMM_UNINITIALIZED && comm!=MPI_COMM_WORLD){
441     //create leader_communicator
442     for (i=0; i< leader_group_size;i++)
443       smpi_group_set_mapping(leaders_group, leader_list[i], i);
444     leader_comm = smpi_comm_new(leaders_group, nullptr);
445     smpi_comm_set_leaders_comm(comm, leader_comm);
446     smpi_comm_set_intra_comm(comm, comm_intra);
447
448    //create intracommunicator
449   }else{
450     for (i=0; i< leader_group_size;i++)
451       smpi_group_set_mapping(leaders_group, leader_list[i], i);
452
453     if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
454       leader_comm = smpi_comm_new(leaders_group, nullptr);
455       smpi_comm_set_leaders_comm(comm, leader_comm);
456     }else{
457       leader_comm=smpi_comm_get_leaders_comm(comm);
458       smpi_group_unuse(leaders_group);
459     }
460     smpi_process_set_comm_intra(comm_intra);
461   }
462
463   int is_uniform = 1;
464
465   // Are the nodes uniform ? = same number of process/node
466   int my_local_size=smpi_comm_size(comm_intra);
467   if(smpi_comm_rank(comm_intra)==0) {
468     int* non_uniform_map = xbt_new0(int,leader_group_size);
469     smpi_coll_tuned_allgather_mpich(&my_local_size, 1, MPI_INT,
470         non_uniform_map, 1, MPI_INT, leader_comm);
471     for(i=0; i < leader_group_size; i++) {
472       if(non_uniform_map[0] != non_uniform_map[i]) {
473         is_uniform = 0;
474         break;
475       }
476     }
477     if(is_uniform==0 && smpi_comm_is_uniform(comm)!=0){
478         comm->non_uniform_map= non_uniform_map;
479     }else{
480         xbt_free(non_uniform_map);
481     }
482     comm->is_uniform=is_uniform;
483   }
484   smpi_coll_tuned_bcast_mpich(&(comm->is_uniform),1, MPI_INT, 0, comm_intra );
485
486   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
487      smpi_switch_data_segment(smpi_process_index());
488    }
489   // Are the ranks blocked ? = allocated contiguously on the SMP nodes
490   int is_blocked=1;
491   int prev=smpi_group_rank(smpi_comm_group(comm), smpi_group_index(smpi_comm_group(comm_intra), 0));
492     for (i=1; i<my_local_size; i++){
493       int that=smpi_group_rank(smpi_comm_group(comm),smpi_group_index(smpi_comm_group(comm_intra), i));
494       if(that!=prev+1){
495         is_blocked=0;
496         break;
497       }
498       prev = that;
499   }
500
501   int global_blocked;
502   smpi_mpi_allreduce(&is_blocked, &(global_blocked), 1, MPI_INT, MPI_LAND, comm);
503
504   if(MPI_COMM_WORLD==MPI_COMM_UNINITIALIZED || comm==MPI_COMM_WORLD){
505     if(smpi_comm_rank(comm)==0){
506         comm->is_blocked=global_blocked;
507     }
508   }else{
509     comm->is_blocked=global_blocked;
510   }
511   xbt_free(leader_list);
512   
513   if(replaying)
514     smpi_process_set_replaying(true); 
515 }
516
517 int smpi_comm_attr_delete(MPI_Comm comm, int keyval){
518   smpi_comm_key_elem elem =
519      static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
520   if(elem==nullptr)
521     return MPI_ERR_ARG;
522   if(elem->delete_fn!=MPI_NULL_DELETE_FN){
523     void* value = nullptr;
524     int flag;
525     if(smpi_comm_attr_get(comm, keyval, &value, &flag)==MPI_SUCCESS){
526       int ret = elem->delete_fn(comm, keyval, value, &flag);
527       if(ret!=MPI_SUCCESS) 
528         return ret;
529     }
530   }
531   if(comm->attributes==nullptr)
532     return MPI_ERR_ARG;
533
534   xbt_dict_remove_ext(comm->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
535   return MPI_SUCCESS;
536 }
537
538 int smpi_comm_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
539   smpi_comm_key_elem elem =
540     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
541   if(elem==nullptr)
542     return MPI_ERR_ARG;
543   if(comm->attributes==nullptr){
544     *flag=0;
545     return MPI_SUCCESS;
546   }
547   try {
548     *static_cast<void**>(attr_value) = xbt_dict_get_ext(comm->attributes, 
549                             reinterpret_cast<const char*>(&keyval), sizeof(int));
550     *flag=1;
551   }
552   catch (xbt_ex& ex) {
553     *flag=0;
554   }
555   return MPI_SUCCESS;
556 }
557
558 int smpi_comm_attr_put(MPI_Comm comm, int keyval, void* attr_value){
559   if(smpi_comm_keyvals==nullptr)
560     smpi_comm_keyvals = xbt_dict_new();
561   smpi_comm_key_elem elem =
562     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(&keyval), sizeof(int)));
563   if(elem==nullptr)
564     return MPI_ERR_ARG;
565   int flag;
566   void* value = nullptr;
567   smpi_comm_attr_get(comm, keyval, &value, &flag);
568   if(flag!=0 && elem->delete_fn!=MPI_NULL_DELETE_FN){
569     int ret = elem->delete_fn(comm, keyval, value, &flag);
570     if(ret!=MPI_SUCCESS) 
571       return ret;
572   }
573   if(comm->attributes==nullptr)
574     comm->attributes=xbt_dict_new();
575
576   xbt_dict_set_ext(comm->attributes,  reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
577   return MPI_SUCCESS;
578 }
579
580 int smpi_comm_keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
581                             void* extra_state){
582   if(smpi_comm_keyvals==nullptr)
583     smpi_comm_keyvals = xbt_dict_new();
584
585   smpi_comm_key_elem value = static_cast<smpi_comm_key_elem>(xbt_new0(s_smpi_mpi_comm_key_elem_t,1));
586
587   value->copy_fn=copy_fn;
588   value->delete_fn=delete_fn;
589
590   *keyval = comm_keyval_id;
591   xbt_dict_set_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(keyval), sizeof(int),static_cast<void*>(value), nullptr);
592   comm_keyval_id++;
593   return MPI_SUCCESS;
594 }
595
596 int smpi_comm_keyval_free(int* keyval){
597   smpi_comm_key_elem elem =
598      static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int)));
599   if(elem==nullptr)
600     return MPI_ERR_ARG;
601   xbt_dict_remove_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int));
602   xbt_free(elem);
603   return MPI_SUCCESS;
604 }