Skip to content

Commit 08b7d05

Browse files
committed
comm: use MPIR_Group_create_{map, stride)
Avoid access group internal fields.
1 parent 6fc034b commit 08b7d05

File tree

2 files changed

+23
-47
lines changed

2 files changed

+23
-47
lines changed

src/mpi/comm/comm_impl.c

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,19 @@ int MPIR_Comm_test_threadcomm_impl(MPIR_Comm * comm_ptr, int *flag)
6868
static int comm_create_local_group(MPIR_Comm * comm_ptr)
6969
{
7070
int mpi_errno = MPI_SUCCESS;
71-
MPIR_Group *group_ptr;
72-
int n = comm_ptr->local_size;
73-
74-
mpi_errno = MPIR_Group_create(n, &group_ptr);
75-
MPIR_ERR_CHECK(mpi_errno);
7671

77-
/* Group belongs to the same session as communicator */
78-
MPIR_Group_set_session_ptr(group_ptr, comm_ptr->session_ptr);
79-
80-
group_ptr->is_local_dense_monotonic = TRUE;
72+
int n = comm_ptr->local_size;
73+
MPIR_Lpid *map = MPL_malloc(n * sizeof(MPIR_Lpid), MPL_MEM_GROUP);
8174

82-
int comm_world_size = MPIR_Process.size;
8375
for (int i = 0; i < n; i++) {
8476
uint64_t lpid;
8577
(void) MPID_Comm_get_lpid(comm_ptr, i, &lpid, FALSE);
86-
group_ptr->lrank_to_lpid[i].lpid = lpid;
87-
if (lpid > comm_world_size || (i > 0 && group_ptr->lrank_to_lpid[i - 1].lpid != (lpid - 1))) {
88-
group_ptr->is_local_dense_monotonic = FALSE;
89-
}
78+
map[i] = lpid;
9079
}
9180

92-
group_ptr->size = n;
93-
group_ptr->rank = comm_ptr->rank;
94-
group_ptr->idx_of_first_lpid = -1;
95-
96-
comm_ptr->local_group = group_ptr;
97-
98-
/* FIXME : Add a sanity check that the size of the group is the same as
99-
* the size of the communicator. This helps catch corrupted
100-
* communicators */
81+
mpi_errno = MPIR_Group_create_map(n, comm_ptr->rank, comm_ptr->session_ptr, map,
82+
&comm_ptr->local_group);
83+
MPIR_ERR_CHECK(mpi_errno);
10184

10285
fn_exit:
10386
return mpi_errno;
@@ -926,31 +909,23 @@ int MPIR_Comm_idup_with_info_impl(MPIR_Comm * comm_ptr, MPIR_Info * info,
926909
int MPIR_Comm_remote_group_impl(MPIR_Comm * comm_ptr, MPIR_Group ** group_ptr)
927910
{
928911
int mpi_errno = MPI_SUCCESS;
929-
int i, n;
930-
931912
MPIR_FUNC_ENTER;
913+
932914
/* Create a group and populate it with the local process ids */
933915
if (!comm_ptr->remote_group) {
934-
n = comm_ptr->remote_size;
935-
mpi_errno = MPIR_Group_create(n, group_ptr);
936-
MPIR_ERR_CHECK(mpi_errno);
916+
int n = comm_ptr->remote_size;
917+
MPIR_Lpid *map = MPL_malloc(n * sizeof(MPIR_Lpid), MPL_MEM_GROUP);
937918

938-
for (i = 0; i < n; i++) {
919+
for (int i = 0; i < n; i++) {
939920
uint64_t lpid;
940921
(void) MPID_Comm_get_lpid(comm_ptr, i, &lpid, TRUE);
941-
(*group_ptr)->lrank_to_lpid[i].lpid = lpid;
942-
/* TODO calculate is_local_dense_monotonic */
922+
map[i] = lpid;
943923
}
944-
(*group_ptr)->size = n;
945-
(*group_ptr)->rank = MPI_UNDEFINED;
946-
(*group_ptr)->idx_of_first_lpid = -1;
947-
948-
MPIR_Group_set_session_ptr(*group_ptr, comm_ptr->session_ptr);
949-
950-
comm_ptr->remote_group = *group_ptr;
951-
} else {
952-
*group_ptr = comm_ptr->remote_group;
924+
mpi_errno = MPIR_Group_create_map(n, MPI_UNDEFINED, comm_ptr->session_ptr, map,
925+
&comm_ptr->remote_group);
926+
MPIR_ERR_CHECK(mpi_errno);
953927
}
928+
*group_ptr = comm_ptr->remote_group;
954929
MPIR_Group_add_ref(comm_ptr->remote_group);
955930

956931
fn_exit:

src/mpi/comm/ulfm_impl.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,22 @@ int MPIR_Comm_get_failed_impl(MPIR_Comm * comm_ptr, MPIR_Group ** failed_group_p
8787
/* create failed_group */
8888
int n = utarray_len(failed_procs);
8989

90+
MPIR_Lpid *map = MPL_malloc(n * sizeof(MPIR_Lpid), MPL_MEM_GROUP);
91+
9092
MPIR_Group *new_group;
91-
mpi_errno = MPIR_Group_create(n, &new_group);
92-
MPIR_ERR_CHECK(mpi_errno);
9393

94-
new_group->rank = MPI_UNDEFINED;
94+
int myrank = MPI_UNDEFINED;
9595
for (int i = 0; i < utarray_len(failed_procs); i++) {
9696
int *p = (int *) utarray_eltptr(failed_procs, i);
97-
new_group->lrank_to_lpid[i].lpid = *p;
97+
map[i] = *p;
9898
/* if calling process is part of the group, set the rank */
9999
if (*p == MPIR_Process.rank) {
100-
new_group->rank = i;
100+
myrank = i;
101101
}
102102
}
103-
new_group->size = n;
104-
new_group->idx_of_first_lpid = -1;
103+
104+
mpi_errno = MPIR_Group_create_map(n, myrank, comm_ptr->session_ptr, map, &new_group);
105+
MPIR_ERR_CHECK(mpi_errno);
105106

106107
MPIR_Group *comm_group;
107108
MPIR_Comm_group_impl(comm_ptr, &comm_group);

0 commit comments

Comments
 (0)