Logo AND Algorithmique Numérique Distribuée

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