+MPI_Comm smpi_comm_dup(MPI_Comm comm){
+ if(smpi_privatize_global_variables){ //we need to switch here, as the called function may silently touch global variables
+ smpi_switch_data_segment(smpi_process_index());
+ }
+ MPI_Comm newcomm = smpi_comm_new(smpi_comm_group(comm), smpi_comm_topo(comm));
+
+ if(comm->attributes !=NULL){
+ newcomm->attributes=xbt_dict_new();
+ xbt_dict_cursor_t cursor = NULL;
+ int *key;
+ int flag;
+ void* value_in;
+ void* value_out;
+ xbt_dict_foreach(comm->attributes, cursor, key, value_in){
+ smpi_key_elem elem = xbt_dict_get_or_null(smpi_keyvals, (const char*)key);
+ if(elem && elem->copy_fn!=MPI_NULL_COPY_FN){
+ elem->copy_fn(comm, *key, NULL, value_in, &value_out, &flag );
+ if(flag)
+ xbt_dict_set(newcomm->attributes, (const char*)key,value_out, NULL);
+ }
+ }
+ }
+ return newcomm;
+}
+
+