Skip to content

Commit

Permalink
Merge pull request #7225 from hzhou/2411_context_id_t
Browse files Browse the repository at this point in the history
misc: remove MPIR_Context_id_t

Approved-by: Ken Raffenetti
  • Loading branch information
hzhou authored Dec 5, 2024
2 parents a111912 + 0237c48 commit 8c5b354
Show file tree
Hide file tree
Showing 31 changed files with 97 additions and 115 deletions.
9 changes: 3 additions & 6 deletions doc/wiki/design/Communicators_and_Context_IDs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ fields of the context ID indicated by letter and color:
(`MPI_Send/MPI_Recv`) occur in a different context than collective
messages (`MPI_Bcast, etc`). This also [explained further below](#context-type-suffix).

The actual type of a context ID is `MPIR_Context_id_t`, which is
`typedef`ed to `uint16_t`.

All members of a communicator use the same context ID for that
communicator, but a context ID is not a globally unique ID. That is, the
communicator's group information combined with the context ID constitute
Expand Down Expand Up @@ -155,7 +152,7 @@ Finds the highest bit of the lowest word that is set in the given mask
and returns the corresponding context ID.

```
static int MPIR_Allocate_context_bit(uint32_t mask[], MPIR_Context_id_t id)
static int MPIR_Allocate_context_bit(uint32_t mask[], int id)
```

Clears the bit in `mask` corresponding to the given context `id`.
Expand All @@ -169,7 +166,7 @@ It resets that bit **in the `context_mask`** and returns the found ID
prefix.

```
int MPIR_Get_contextid(MPID_Comm *comm_ptr, MPIR_Context_id_t *context_id)
int MPIR_Get_contextid(MPID_Comm *comm_ptr, int *context_id)
```

Allocates a new context ID prefix collectively over the given
Expand All @@ -182,7 +179,7 @@ participating processes. The result of this reduction is fed to
prefix.

```
int MPIR_Get_intercomm_contextid( MPID_Comm *comm_ptr, MPIR_Context_id_t *context_id, MPIR_Context_id_t *recvcontext_id)
int MPIR_Get_intercomm_contextid( MPID_Comm *comm_ptr, int *context_id, int *recvcontext_id)
```

Called by `MPIR_Comm_copy` to get context IDs for a new
Expand Down
6 changes: 3 additions & 3 deletions src/include/mpir_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ enum MPIR_COMM_HINT_PREDEFINED_t {
struct MPIR_Comm {
MPIR_OBJECT_HEADER; /* adds handle and ref_count fields */
MPID_Thread_mutex_t mutex;
MPIR_Context_id_t context_id; /* Send context id. See notes */
MPIR_Context_id_t recvcontext_id; /* Recv context id (locally allocated). See notes */
int context_id; /* Send context id. See notes */
int recvcontext_id; /* Recv context id (locally allocated). See notes */
int remote_size; /* Value of MPI_Comm_(remote)_size */
int rank; /* Value of MPI_Comm_rank */
MPIR_Attribute *attributes; /* List of attributes */
Expand Down Expand Up @@ -378,7 +378,7 @@ int MPIR_Comm_commit(MPIR_Comm *);
int MPIR_Comm_is_parent_comm(MPIR_Comm *);

/* peer intercomm is an internal 1-to-1 intercomm used for connecting dynamic processes */
int MPIR_peer_intercomm_create(MPIR_Context_id_t context_id, MPIR_Context_id_t recvcontext_id,
int MPIR_peer_intercomm_create(int context_id, int recvcontext_id,
uint64_t remote_lpid, int is_low_group, MPIR_Comm ** newcomm);

#define MPIR_Comm_rank(comm_ptr) ((comm_ptr)->rank)
Expand Down
20 changes: 6 additions & 14 deletions src/include/mpir_contextid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
#ifndef MPIR_CONTEXTID_H_INCLUDED
#define MPIR_CONTEXTID_H_INCLUDED

#define MPIR_INVALID_CONTEXT_ID (-1)
#define MPIR_CONTEXT_ID_T_DATATYPE MPI_INT

#ifdef HAVE_EXTENDED_CONTEXT_BITS
#define MPIR_CONTEXT_ID_T_DATATYPE MPI_UINT32_T
typedef uint32_t MPIR_Context_id_t;
#define MPIR_INVALID_CONTEXT_ID ((MPIR_Context_id_t)0xffffffff)
#define MPIR_CONTEXT_ID_BITS (20)
#define CONTEXT_ID_FMT PRIu32
#else
/* Default context id type is uint16_t. Instead of always using uint32_t, we take a conservative
* approach to ensure the smallest possible packet header size for ch3 and ch4 active messages.
*/
#define MPIR_CONTEXT_ID_T_DATATYPE MPI_UINT16_T
typedef uint16_t MPIR_Context_id_t;
#define MPIR_INVALID_CONTEXT_ID ((MPIR_Context_id_t)0xffff)
#define MPIR_CONTEXT_ID_BITS (16)
#define CONTEXT_ID_FMT PRIu16
#endif

/* The following preprocessor macros provide bitfield access information for
Expand Down Expand Up @@ -105,14 +97,14 @@ void MPIR_context_id_init(void);
with the other comm routines (src/mpi/comm, in mpicomm.h). However,
to create a new communicator after a spawn or connect-accept operation,
the device may need to create a new contextid */
int MPIR_Get_contextid_sparse(MPIR_Comm * comm_ptr, MPIR_Context_id_t * context_id, int ignore_id);
int MPIR_Get_contextid_sparse(MPIR_Comm * comm_ptr, int *context_id, int ignore_id);
int MPIR_Get_contextid_sparse_group(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr, int tag,
MPIR_Context_id_t * context_id, int ignore_id);
int *context_id, int ignore_id);

int MPIR_Get_contextid_nonblock(MPIR_Comm * comm_ptr, MPIR_Comm * newcommp, MPIR_Request ** req);
int MPIR_Get_intercomm_contextid_nonblock(MPIR_Comm * comm_ptr, MPIR_Comm * newcommp,
MPIR_Request ** req);

void MPIR_Free_contextid(MPIR_Context_id_t);
void MPIR_Free_contextid(int context_id);

#endif /* MPIR_CONTEXTID_H_INCLUDED */
14 changes: 7 additions & 7 deletions src/mpi/comm/comm_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ int MPII_Comm_create_map(int local_n,
int MPIR_Comm_create_intra(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr, MPIR_Comm ** newcomm_ptr)
{
int mpi_errno = MPI_SUCCESS;
MPIR_Context_id_t new_context_id = 0;
int new_context_id = 0;
int *mapping = NULL;
int n;

Expand Down Expand Up @@ -400,7 +400,7 @@ int MPIR_Comm_create_intra(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr, MPIR_Co
int MPIR_Comm_create_inter(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr, MPIR_Comm ** newcomm_ptr)
{
int mpi_errno = MPI_SUCCESS;
MPIR_Context_id_t new_context_id;
int new_context_id;
int *mapping = NULL;
int *remote_mapping = NULL;
MPIR_Comm *mapping_comm = NULL;
Expand Down Expand Up @@ -581,7 +581,7 @@ int MPIR_Comm_create_group_impl(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr, in
MPIR_Comm ** newcomm_ptr)
{
int mpi_errno = MPI_SUCCESS;
MPIR_Context_id_t new_context_id = 0;
int new_context_id = 0;
int *mapping = NULL;
int n;

Expand Down Expand Up @@ -988,7 +988,7 @@ int MPIR_Intercomm_create_impl(MPIR_Comm * local_comm_ptr, int local_leader,
MPIR_Comm ** new_intercomm_ptr)
{
int mpi_errno = MPI_SUCCESS;
MPIR_Context_id_t final_context_id, recvcontext_id;
int final_context_id, recvcontext_id;
int remote_size = 0;
uint64_t *remote_lpids = NULL;
int comm_info[3];
Expand Down Expand Up @@ -1024,7 +1024,7 @@ int MPIR_Intercomm_create_impl(MPIR_Comm * local_comm_ptr, int local_leader,
/* Leaders can now swap context ids and then broadcast the value
* to the local group of processes */
if (local_comm_ptr->rank == local_leader) {
MPIR_Context_id_t remote_context_id;
int remote_context_id;

mpi_errno =
MPIC_Sendrecv(&recvcontext_id, 1, MPIR_CONTEXT_ID_T_DATATYPE, remote_leader, tag,
Expand Down Expand Up @@ -1103,7 +1103,7 @@ int MPIR_Intercomm_create_impl(MPIR_Comm * local_comm_ptr, int local_leader,
/* Peer intercomm is a 1-to-1 intercomm, internally created by device layer
* to facilitate connecting dynamic processes */

int MPIR_peer_intercomm_create(MPIR_Context_id_t context_id, MPIR_Context_id_t recvcontext_id,
int MPIR_peer_intercomm_create(int context_id, int recvcontext_id,
uint64_t remote_lpid, int is_low_group, MPIR_Comm ** newcomm)
{
int mpi_errno = MPI_SUCCESS;
Expand Down Expand Up @@ -1180,7 +1180,7 @@ int MPIR_Intercomm_merge_impl(MPIR_Comm * comm_ptr, int high, MPIR_Comm ** new_i
{
int mpi_errno = MPI_SUCCESS;
int local_high, remote_high, new_size;
MPIR_Context_id_t new_context_id;
int new_context_id;

MPIR_FUNC_ENTER;
/* Make sure that we have a local intercommunicator */
Expand Down
2 changes: 1 addition & 1 deletion src/mpi/comm/comm_split.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int MPIR_Comm_split_impl(MPIR_Comm * comm_ptr, int color, int key, MPIR_Comm **
int rank, size, remote_size, i, new_size, new_remote_size,
first_entry = 0, first_remote_entry = 0, *last_ptr;
int in_newcomm; /* TRUE iff *newcomm should be populated */
MPIR_Context_id_t new_context_id, remote_context_id;
int new_context_id, remote_context_id;
MPIR_Comm_map_t *mapper;
MPIR_CHKLMEM_DECL(4);

Expand Down
2 changes: 1 addition & 1 deletion src/mpi/comm/commutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ int MPII_Comm_dup(MPIR_Comm * comm_ptr, MPIR_Info * info, MPIR_Comm ** newcomm_p
int MPII_Comm_copy(MPIR_Comm * comm_ptr, int size, MPIR_Info * info, MPIR_Comm ** outcomm_ptr)
{
int mpi_errno = MPI_SUCCESS;
MPIR_Context_id_t new_context_id, new_recvcontext_id;
int new_context_id, new_recvcontext_id;
MPIR_Comm *newcomm_ptr = NULL;
MPIR_Comm_map_t *map = NULL;

Expand Down
33 changes: 15 additions & 18 deletions src/mpi/comm/contextid.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const int ALL_OWN_MASK_FLAG = MPIR_MAX_CONTEXT_MASK;
/* utility function to pretty print a context ID for debugging purposes, see
* mpiimpl.h for more info on the various fields */
#ifdef MPL_USE_DBG_LOGGING
static void dump_context_id(MPIR_Context_id_t context_id, char *out_str, int len)
static void dump_context_id(int context_id, char *out_str, int len)
{
int subcomm_type = MPIR_CONTEXT_READ_FIELD(SUBCOMM, context_id);
const char *subcomm_type_name = NULL;
Expand Down Expand Up @@ -225,7 +225,7 @@ static int locate_context_bit(uint32_t local_mask[])
/* Allocates a context ID from the given mask by clearing the bit
* corresponding to the the given id. Returns 0 on failure, id on
* success. */
static int allocate_context_bit(uint32_t mask[], MPIR_Context_id_t id)
static int allocate_context_bit(uint32_t mask[], int id)
{
int raw_prefix, idx, bitpos;
raw_prefix = MPIR_CONTEXT_READ_FIELD(PREFIX, id);
Expand All @@ -251,7 +251,7 @@ static int allocate_context_bit(uint32_t mask[], MPIR_Context_id_t id)
* Returns 0 on failure. Returns the allocated context ID on success. */
static int find_and_allocate_context_id(uint32_t local_mask[])
{
MPIR_Context_id_t context_id;
int context_id;
context_id = locate_context_bit(local_mask);
if (context_id != 0) {
context_id = allocate_context_bit(context_mask, context_id);
Expand Down Expand Up @@ -281,16 +281,16 @@ static volatile int mask_in_use = 0;
* used.
*/

int MPIR_Get_contextid_sparse(MPIR_Comm * comm_ptr, MPIR_Context_id_t * context_id, int ignore_id)
int MPIR_Get_contextid_sparse(MPIR_Comm * comm_ptr, int *context_id, int ignore_id)
{
return MPIR_Get_contextid_sparse_group(comm_ptr, NULL /*group_ptr */ ,
MPIR_Process.attrs.tag_ub /*tag */ ,
context_id, ignore_id);
}

struct gcn_state {
MPIR_Context_id_t *ctx0;
MPIR_Context_id_t *ctx1;
int *ctx0;
int *ctx1;
int own_mask;
int own_eager_mask;
int first_iter;
Expand Down Expand Up @@ -349,7 +349,7 @@ static void add_gcn_to_list(struct gcn_state *new_state)
* the given group.
*/
int MPIR_Get_contextid_sparse_group(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr, int tag,
MPIR_Context_id_t * context_id, int ignore_id)
int *context_id, int ignore_id)
{
int mpi_errno = MPI_SUCCESS;
struct gcn_state st;
Expand Down Expand Up @@ -478,8 +478,7 @@ int MPIR_Get_contextid_sparse_group(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr
/* There is a chance that we've found a context id */
/* Find_and_allocate_context_id updates the context_mask if it finds a match */
*context_id = find_and_allocate_context_id(st.local_mask);
MPL_DBG_MSG_D(MPIR_DBG_COMM, VERBOSE, "Context id is now %" CONTEXT_ID_FMT,
*context_id);
MPL_DBG_MSG_D(MPIR_DBG_COMM, VERBOSE, "Context id is now %d", *context_id);

st.own_eager_mask = 0;
eager_in_use = 0;
Expand All @@ -498,8 +497,7 @@ int MPIR_Get_contextid_sparse_group(MPIR_Comm * comm_ptr, MPIR_Group * group_ptr
/* There is a chance that we've found a context id */
/* Find_and_allocate_context_id updates the context_mask if it finds a match */
*context_id = find_and_allocate_context_id(st.local_mask);
MPL_DBG_MSG_D(MPIR_DBG_COMM, VERBOSE, "Context id is now %" CONTEXT_ID_FMT,
*context_id);
MPL_DBG_MSG_D(MPIR_DBG_COMM, VERBOSE, "Context id is now %d", *context_id);

mask_in_use = 0;

Expand Down Expand Up @@ -686,7 +684,7 @@ static int sched_cb_gcn_allocate_cid(MPIR_Comm * comm, int tag, void *state)
{
int mpi_errno = MPI_SUCCESS;
struct gcn_state *st = state, *tmp;
MPIR_Context_id_t newctxid;
int newctxid;
if (st->own_eager_mask) {
newctxid = find_and_allocate_context_id(st->local_mask);
if (st->ctx0)
Expand Down Expand Up @@ -887,7 +885,7 @@ static int sched_cb_gcn_copy_mask(MPIR_Comm * comm, int tag, void *state)
* multi-threaded MPIR_Get_contextid_sparse_group.
*/
static int sched_get_cid_nonblock(MPIR_Comm * comm_ptr, MPIR_Comm * newcomm,
MPIR_Context_id_t * ctx0, MPIR_Context_id_t * ctx1,
int *ctx0, int *ctx1,
MPIR_Sched_t s, MPIR_Comm_kind_t gcn_cid_kind)
{
int mpi_errno = MPI_SUCCESS;
Expand Down Expand Up @@ -1028,10 +1026,9 @@ int MPIR_Get_intercomm_contextid_nonblock(MPIR_Comm * comm_ptr, MPIR_Comm * newc
* This uses the thread-safe (if necessary) routine to get a context id
* and does not need its own thread-safe version.
*/
int MPIR_Get_intercomm_contextid(MPIR_Comm * comm_ptr, MPIR_Context_id_t * context_id,
MPIR_Context_id_t * recvcontext_id)
int MPIR_Get_intercomm_contextid(MPIR_Comm * comm_ptr, int *context_id, int *recvcontext_id)
{
MPIR_Context_id_t mycontext_id, remote_context_id;
int mycontext_id, remote_context_id;
int mpi_errno = MPI_SUCCESS;
int tag = 31567; /* FIXME - we need an internal tag or
* communication channel. Can we use a different
Expand All @@ -1052,7 +1049,7 @@ int MPIR_Get_intercomm_contextid(MPIR_Comm * comm_ptr, MPIR_Context_id_t * conte

/* MPIC routine uses an internal context id. The local leads (process 0)
* exchange data */
remote_context_id = (MPIR_Context_id_t) - 1;
remote_context_id = MPIR_INVALID_CONTEXT_ID;
if (comm_ptr->rank == 0) {
mpi_errno = MPIC_Sendrecv(&mycontext_id, 1, MPIR_CONTEXT_ID_T_DATATYPE, 0, tag,
&remote_context_id, 1, MPIR_CONTEXT_ID_T_DATATYPE, 0, tag,
Expand All @@ -1076,7 +1073,7 @@ int MPIR_Get_intercomm_contextid(MPIR_Comm * comm_ptr, MPIR_Context_id_t * conte
return mpi_errno;
}

void MPIR_Free_contextid(MPIR_Context_id_t context_id)
void MPIR_Free_contextid(int context_id)
{
int idx, bitpos, raw_prefix;

Expand Down
2 changes: 1 addition & 1 deletion src/mpi/comm/mpicomm.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define MPICOMM_H_INCLUDED

/* Function prototypes for communicator helper functions */
int MPIR_Get_intercomm_contextid(MPIR_Comm *, MPIR_Context_id_t *, MPIR_Context_id_t *);
int MPIR_Get_intercomm_contextid(MPIR_Comm *, int *, int *);

/* Utitlity function that retrieves an info key and ensures it is collectively equal */
int MPII_collect_info_key(MPIR_Comm * comm_ptr, MPIR_Info * info_ptr, const char *key,
Expand Down
2 changes: 1 addition & 1 deletion src/mpid/ch3/include/mpidimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ int MPIDI_CH3U_Receive_data_unexpected(MPIR_Request * rreq, void *buf, intptr_t
int MPIDI_CH3I_Comm_init(void);

int MPIDI_CH3I_Comm_handle_failed_procs(MPIR_Group *new_failed_procs);
void MPIDI_CH3I_Comm_find(MPIR_Context_id_t context_id, MPIR_Comm **comm);
void MPIDI_CH3I_Comm_find(int context_id, MPIR_Comm **comm);

/* The functions below allow channels to register functions to be
called immediately after a communicator has been created, and
Expand Down
2 changes: 1 addition & 1 deletion src/mpid/ch3/include/mpidpkt.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ typedef MPIDI_CH3_Pkt_conn_ack_t MPIDI_CH3_Pkt_accept_ack_t;

typedef struct MPIDI_CH3_Pkt_revoke {
MPIDI_CH3_Pkt_type_t type;
MPIR_Context_id_t revoked_comm;
int revoked_context_id;
} MPIDI_CH3_Pkt_revoke_t;

typedef union MPIDI_CH3_Pkt {
Expand Down
8 changes: 5 additions & 3 deletions src/mpid/ch3/include/mpidpre.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ typedef unsigned long MPID_Seqnum_t;

#include "mpichconf.h"

#if CH3_RANK_BITS == 16
#if CH3_RANK_BITS == 16 && !defined(HAVE_EXTENDED_CONTEXT_BITS)
typedef int16_t MPIDI_Rank_t;
#elif CH3_RANK_BITS == 32
typedef int16_t MPIDI_Context_id_t;
#else
typedef int32_t MPIDI_Rank_t;
typedef int32_t MPIDI_Context_id_t;
#endif /* CH3_RANK_BITS */

/* For the typical communication system for which the ch3 channel is
Expand Down Expand Up @@ -106,7 +108,7 @@ typedef int32_t MPIDI_Rank_t;
typedef struct MPIDI_Message_match_parts {
int32_t tag;
MPIDI_Rank_t rank;
MPIR_Context_id_t context_id;
MPIDI_Context_id_t context_id;
} MPIDI_Message_match_parts_t;
typedef union {
MPIDI_Message_match_parts_t parts;
Expand Down
2 changes: 1 addition & 1 deletion src/mpid/ch3/src/ch3u_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ int MPIDI_CH3I_Comm_handle_failed_procs(MPIR_Group *new_failed_procs)
goto fn_exit;
}

void MPIDI_CH3I_Comm_find(MPIR_Context_id_t context_id, MPIR_Comm **comm)
void MPIDI_CH3I_Comm_find(int context_id, MPIR_Comm **comm)
{
MPIR_FUNC_ENTER;

Expand Down
2 changes: 1 addition & 1 deletion src/mpid/ch3/src/ch3u_handle_revoke_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int MPIDI_CH3_PktHandler_Revoke(MPIDI_VC_t *vc, MPIDI_CH3_Pkt_t *pkt,
MPL_DBG_MSG_D(MPIDI_CH3_DBG_OTHER, VERBOSE, "Received revoke pkt from %d", vc->pg_rank);

/* Search through all of the communicators to find the right context_id */
MPIDI_CH3I_Comm_find(revoke_pkt->revoked_comm, &comm_ptr);
MPIDI_CH3I_Comm_find(revoke_pkt->revoked_context_id, &comm_ptr);
if (comm_ptr == NULL)
MPIR_ERR_SETANDJUMP1(mpi_errno, MPI_ERR_OTHER, "**ch3|postrecv",
"**ch3|postrecv %s", "MPIDI_CH3_PKT_REVOKE");
Expand Down
2 changes: 1 addition & 1 deletion src/mpid/ch3/src/ch3u_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ int MPIDI_Comm_connect(const char *port_name, MPIR_Info *info, int root,
pg_translation *local_translation = NULL, *remote_translation = NULL;
pg_node *pg_list = NULL;
MPIDI_PG_t **remote_pg = NULL;
MPIR_Context_id_t recvcontext_id = MPIR_INVALID_CONTEXT_ID;
int recvcontext_id = MPIR_INVALID_CONTEXT_ID;
MPIR_CHKLMEM_DECL(3);

MPIR_FUNC_ENTER;
Expand Down
2 changes: 1 addition & 1 deletion src/mpid/ch3/src/mpid_comm_revoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int MPID_Comm_revoke(MPIR_Comm *comm_ptr, int is_remote)

/* Send out the revoke message */
MPIDI_Pkt_init(revoke_pkt, MPIDI_CH3_PKT_REVOKE);
revoke_pkt->revoked_comm = comm_ptr->context_id;
revoke_pkt->revoked_context_id = comm_ptr->context_id;

size = comm_ptr->remote_size;
my_rank = comm_ptr->rank;
Expand Down
Loading

0 comments on commit 8c5b354

Please sign in to comment.