#include "private.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi,
- "Logging specific to SMPI (group)");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi, "Logging specific to SMPI (group)");
typedef struct s_smpi_mpi_group {
int size;
static s_smpi_mpi_group_t mpi_MPI_GROUP_EMPTY = {
0, /* size */
- NULL, /* rank_to_index_map */
- NULL, /* index_to_rank_map */
+ nullptr, /* rank_to_index_map */
+ nullptr, /* index_to_rank_map */
1, /* refcount: start > 0 so that this group never gets freed */
};
MPI_Group group=origin;
char *key;
char *ptr_rank;
- xbt_dict_cursor_t cursor = NULL;
+ xbt_dict_cursor_t cursor = nullptr;
int i;
- if(origin!= smpi_comm_group(MPI_COMM_WORLD)
- && origin != MPI_GROUP_NULL
- && origin != smpi_comm_group(MPI_COMM_SELF)
+ if(origin != MPI_GROUP_NULL
&& origin != MPI_GROUP_EMPTY)
{
group = xbt_new(s_smpi_mpi_group_t, 1);
}
xbt_dict_foreach(origin->index_to_rank_map, cursor, key, ptr_rank) {
- xbt_dict_set(group->index_to_rank_map, key, ptr_rank, NULL);
+ int * cp = static_cast<int*>(xbt_malloc(sizeof(int)));
+ *cp=*reinterpret_cast<int*>(ptr_rank);
+ xbt_dict_set(group->index_to_rank_map, key, cp, nullptr);
}
}
return group;
}
-
void smpi_group_destroy(MPI_Group group)
{
if(group!= smpi_comm_group(MPI_COMM_WORLD)
&& group != MPI_GROUP_NULL
- && group != smpi_comm_group(MPI_COMM_SELF)
&& group != MPI_GROUP_EMPTY)
smpi_group_unuse(group);
}
void smpi_group_set_mapping(MPI_Group group, int index, int rank)
{
- char * key;
int * val_rank;
if (rank < group->size) {
group->rank_to_index_map[rank] = index;
if (index!=MPI_UNDEFINED ) {
- val_rank = (int *) malloc(sizeof(int));
- *val_rank = rank;
- int size = asprintf(&key, "%d", index);
- if (size!=-1){
- xbt_dict_set(group->index_to_rank_map, key, val_rank, NULL);
- free(key);
- } else {
- xbt_die("could not allocate memory for asprintf");
- }
+ val_rank = static_cast<int *>(xbt_malloc(sizeof(int)));
+ *val_rank = rank;
+
+ char * key = bprintf("%d", index);
+ xbt_dict_set(group->index_to_rank_map, key, val_rank, nullptr);
+ xbt_free(key);
}
}
}
int smpi_group_rank(MPI_Group group, int index)
{
- int * ptr_rank = NULL;
- char * key;
- int size = asprintf(&key, "%d", index);
- if (size!=-1){
- ptr_rank = static_cast<int*>(xbt_dict_get_or_null(group->index_to_rank_map, key));
- xbt_free(key);
- }else
- xbt_die("could not allocate memory for asprintf");
- if (!ptr_rank)
+ int * ptr_rank = nullptr;
+ char * key = bprintf("%d", index);
+ ptr_rank = static_cast<int*>(xbt_dict_get_or_null(group->index_to_rank_map, key));
+ xbt_free(key);
+
+ if (ptr_rank==nullptr)
return MPI_UNDEFINED;
return *ptr_rank;
}
return 0;
}
return group->refcount;
-
}
int smpi_group_size(MPI_Group group)