Skip to content

Commit

Permalink
group: add builtin MPIR_GROUP_{WORLD,SELF}
Browse files Browse the repository at this point in the history
Add builtin MPIR_GROUP_WORLD and MPIR_GROUP_SELF, so we can create
builtin communicators from builtin groups.
  • Loading branch information
hzhou committed Dec 12, 2024
1 parent 09b119a commit e0c851e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/include/mpir_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
S*/

/* In addition to MPI_GROUP_EMPTY, internally we have a few more builtins */
#define MPIR_GROUP_WORLD ((MPI_Group)0x48000001)
#define MPIR_GROUP_SELF ((MPI_Group)0x48000002)

#define MPIR_GROUP_WORLD_PTR (MPIR_Group_builtin + 1)
#define MPIR_GROUP_SELF_PTR (MPIR_Group_builtin + 2)

/* Worlds -
* We need a device-independent way of identifying processes. Assuming the concept of
* "worlds", we can describe a process with (world_idx, world_rank).
Expand Down
2 changes: 1 addition & 1 deletion src/include/mpir_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const char *MPIR_Handle_get_kind_str(int kind);
#define MPIR_COMM_PREALLOC 8
#endif

#define MPIR_GROUP_N_BUILTIN 1
#define MPIR_GROUP_N_BUILTIN 3
#ifdef MPID_GROUP_PREALLOC
#define MPIR_GROUP_PREALLOC MPID_GROUP_PREALLOC
#else
Expand Down
9 changes: 4 additions & 5 deletions src/mpi/group/group_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,11 @@ int MPIR_Group_from_session_pset_impl(MPIR_Session * session_ptr, const char *ps
int mpi_errno = MPI_SUCCESS;

if (MPL_stricmp(pset_name, "mpi://WORLD") == 0) {
mpi_errno = MPIR_Group_create_stride(MPIR_Process.size, MPIR_Process.rank, session_ptr,
0, 1, 1, new_group_ptr);
MPIR_ERR_CHECK(mpi_errno);
*new_group_ptr = MPIR_GROUP_WORLD_PTR;
MPIR_Group_add_ref(*new_group_ptr);
} else if (MPL_stricmp(pset_name, "mpi://SELF") == 0) {
mpi_errno = MPIR_Group_create_stride(1, 0, session_ptr, 0, 1, 1, new_group_ptr);
MPIR_ERR_CHECK(mpi_errno);
*new_group_ptr = MPIR_GROUP_SELF_PTR;
MPIR_Group_add_ref(*new_group_ptr);
} else {
/* TODO: Implement pset struct, locate pset struct ptr */
MPIR_ERR_SETANDSTMT(mpi_errno, MPI_ERR_ARG, goto fn_fail, "**psetinvalidname");
Expand Down
28 changes: 27 additions & 1 deletion src/mpi/group/grouputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ int MPIR_Group_init(void)
{
int mpi_errno = MPI_SUCCESS;

MPIR_Assert(MPIR_GROUP_N_BUILTIN == 1); /* update this func if this ever triggers */
MPIR_Assert(MPIR_GROUP_N_BUILTIN == 3); /* update this func if this ever triggers */

struct MPIR_Pmap *pmap;

MPIR_Group_builtin[0].handle = MPI_GROUP_EMPTY;
MPIR_Object_set_ref(&MPIR_Group_builtin[0], 1);
Expand All @@ -57,6 +59,30 @@ int MPIR_Group_init(void)
MPIR_Group_builtin[0].session_ptr = NULL;
memset(&MPIR_Group_builtin[0].pmap, 0, sizeof(struct MPIR_Pmap));

MPIR_Group_builtin[1].handle = MPIR_GROUP_WORLD;
MPIR_Object_set_ref(&MPIR_Group_builtin[1], 1);
MPIR_Group_builtin[1].size = MPIR_Process.size;
MPIR_Group_builtin[1].rank = MPIR_Process.rank;
MPIR_Group_builtin[1].session_ptr = NULL;
pmap = &MPIR_Group_builtin[1].pmap;
pmap->size = MPIR_Process.size;
pmap->use_map = false;
pmap->u.stride.offset = 0;
pmap->u.stride.stride = 1;
pmap->u.stride.blocksize = 1;

MPIR_Group_builtin[2].handle = MPIR_GROUP_SELF;
MPIR_Object_set_ref(&MPIR_Group_builtin[2], 1);
MPIR_Group_builtin[2].size = 1;
MPIR_Group_builtin[2].rank = 0;
MPIR_Group_builtin[2].session_ptr = NULL;
pmap = &MPIR_Group_builtin[2].pmap;
pmap->size = MPIR_Process.size;
pmap->use_map = false;
pmap->u.stride.offset = MPIR_Process.rank;
pmap->u.stride.stride = 1;
pmap->u.stride.blocksize = 1;

return mpi_errno;
}

Expand Down

0 comments on commit e0c851e

Please sign in to comment.