3 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi,
4 "Logging specific to SMPI (group)");
6 typedef struct s_smpi_mpi_group {
8 int* rank_to_index_map;
9 int* index_to_rank_map;
13 static s_smpi_mpi_group_t mpi_MPI_GROUP_EMPTY = {
15 NULL, /* rank_to_index_map */
16 NULL, /* index_to_rank_map */
17 1, /* refcount: start > 0 so that this group never gets freed */
19 MPI_Group MPI_GROUP_EMPTY = &mpi_MPI_GROUP_EMPTY;
21 MPI_Group smpi_group_new(int size) {
25 count = smpi_process_count();
26 group = xbt_new(s_smpi_mpi_group_t, 1);
28 group->rank_to_index_map = xbt_new(int, size);
29 group->index_to_rank_map = xbt_new(int, count);
31 for(i = 0; i < size; i++) {
32 group->rank_to_index_map[i] = MPI_UNDEFINED;
34 for(i = 0; i < count; i++) {
35 group->index_to_rank_map[i] = MPI_UNDEFINED;
40 void smpi_group_destroy(MPI_Group group) {
41 if(smpi_group_unuse(group) <= 0) {
42 xbt_free(group->rank_to_index_map);
43 xbt_free(group->index_to_rank_map);
48 void smpi_group_set_mapping(MPI_Group group, int index, int rank) {
49 if(rank < group->size && index < smpi_process_count()) {
50 group->rank_to_index_map[rank] = index;
51 group->index_to_rank_map[index] = rank;
55 int smpi_group_index(MPI_Group group, int rank) {
56 int index = MPI_UNDEFINED;
58 if(rank < group->size) {
59 index = group->rank_to_index_map[rank];
64 int smpi_group_rank(MPI_Group group, int index) {
65 int rank = MPI_UNDEFINED;
67 if(index < smpi_process_count()) {
68 rank = group->index_to_rank_map[index];
73 int smpi_group_use(MPI_Group group) {
75 return group->refcount;
78 int smpi_group_unuse(MPI_Group group) {
80 return group->refcount;
83 int smpi_group_size(MPI_Group group) {
87 int smpi_group_compare(MPI_Group group1, MPI_Group group2) {
89 int i, index, rank, size;
92 if(smpi_group_size(group1) != smpi_group_size(group2)) {
95 size = smpi_group_size(group2);
96 for(i = 0; i < size; i++) {
97 index = smpi_group_index(group1, i);
98 rank = smpi_group_rank(group2, index);
99 if(rank == MPI_UNDEFINED) {
100 result = MPI_UNEQUAL;
104 result = MPI_SIMILAR;