Commit 3a017faa authored by Xin Zhao's avatar Xin Zhao
Browse files

Code-refactoring for RMA operations routines.



This patch just does code refactoring for RMA operation rountines
to make the code structure clearer. This patch does not change any
functionality.

After code refactoring, in each operation routine, for non-SHM operations
we do the work in the following order:

(1) allocate a new op struct;
(2) fill areas in op struct, except for packet struct in op struct;
(3) initialize packet struct in op struct, fill areas in packet struct;
(4) enqueue op to data structure on window.
Signed-off-by: Pavan Balaji's avatarPavan Balaji <balaji@anl.gov>
parent 81e2b274
......@@ -128,17 +128,7 @@ int MPIDI_CH3I_Put(const void *origin_addr, int origin_count, MPI_Datatype
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
put_pkt = &(new_ptr->pkt.put);
MPIDI_Pkt_init(put_pkt, MPIDI_CH3_PKT_PUT);
put_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
put_pkt->count = target_count;
put_pkt->datatype = target_datatype;
put_pkt->dataloop_size = 0;
put_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
put_pkt->source_win_handle = win_ptr->handle;
put_pkt->immed_len = 0;
put_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
/******************** Setting operation struct areas ***********************/
/* FIXME: For contig and very short operations, use a streamlined op */
new_ptr->origin_addr = (void *) origin_addr;
......@@ -152,14 +142,6 @@ int MPIDI_CH3I_Put(const void *origin_addr, int origin_count, MPI_Datatype
new_ptr->ureq = ureq;
}
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
if (mpi_errno)
MPIU_ERR_POP(mpi_errno);
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
/* if source or target datatypes are derived, increment their
* reference counts */
if (!MPIR_DATATYPE_IS_PREDEFINED(origin_datatype)) {
......@@ -184,8 +166,26 @@ int MPIDI_CH3I_Put(const void *origin_addr, int origin_count, MPI_Datatype
new_ptr->piggyback_lock_candidate = 1;
}
/************** Setting packet struct areas in operation ****************/
put_pkt = &(new_ptr->pkt.put);
MPIDI_Pkt_init(put_pkt, MPIDI_CH3_PKT_PUT);
put_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
put_pkt->count = target_count;
put_pkt->datatype = target_datatype;
put_pkt->dataloop_size = 0;
put_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
put_pkt->source_win_handle = win_ptr->handle;
put_pkt->immed_len = 0;
put_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
if (mpi_errno)
MPIU_ERR_POP(mpi_errno);
mpi_errno = MPIDI_CH3I_RMA_Make_progress_target(win_ptr, target_rank, &made_progress);
if (mpi_errno != MPI_SUCCESS) MPIU_ERR_POP(mpi_errno);
......@@ -295,16 +295,7 @@ int MPIDI_CH3I_Get(void *origin_addr, int origin_count, MPI_Datatype
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
get_pkt = &(new_ptr->pkt.get);
MPIDI_Pkt_init(get_pkt, MPIDI_CH3_PKT_GET);
get_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
get_pkt->count = target_count;
get_pkt->datatype = target_datatype;
get_pkt->dataloop_size = 0;
get_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_pkt->source_win_handle = win_ptr->handle;
get_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
/******************** Setting operation struct areas ***********************/
/* FIXME: For contig and very short operations, use a streamlined op */
new_ptr->origin_addr = origin_addr;
......@@ -318,14 +309,6 @@ int MPIDI_CH3I_Get(void *origin_addr, int origin_count, MPI_Datatype
new_ptr->ureq = ureq;
}
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
if (mpi_errno)
MPIU_ERR_POP(mpi_errno);
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
/* if source or target datatypes are derived, increment their
* reference counts */
if (!MPIR_DATATYPE_IS_PREDEFINED(origin_datatype)) {
......@@ -344,8 +327,25 @@ int MPIDI_CH3I_Get(void *origin_addr, int origin_count, MPI_Datatype
new_ptr->piggyback_lock_candidate = 1;
}
/************** Setting packet struct areas in operation ****************/
get_pkt = &(new_ptr->pkt.get);
MPIDI_Pkt_init(get_pkt, MPIDI_CH3_PKT_GET);
get_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
get_pkt->count = target_count;
get_pkt->datatype = target_datatype;
get_pkt->dataloop_size = 0;
get_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_pkt->source_win_handle = win_ptr->handle;
get_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
if (mpi_errno)
MPIU_ERR_POP(mpi_errno);
mpi_errno = MPIDI_CH3I_RMA_Make_progress_target(win_ptr, target_rank, &made_progress);
if (mpi_errno != MPI_SUCCESS) MPIU_ERR_POP(mpi_errno);
......@@ -457,19 +457,7 @@ int MPIDI_CH3I_Accumulate(const void *origin_addr, int origin_count, MPI_Datatyp
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
accum_pkt = &(new_ptr->pkt.accum);
MPIDI_Pkt_init(accum_pkt, MPIDI_CH3_PKT_ACCUMULATE);
accum_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
accum_pkt->count = target_count;
accum_pkt->datatype = target_datatype;
accum_pkt->dataloop_size = 0;
accum_pkt->op = op;
accum_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
accum_pkt->source_win_handle = win_ptr->handle;
accum_pkt->immed_len = 0;
accum_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
/******************** Setting operation struct areas ***********************/
new_ptr->origin_addr = (void *) origin_addr;
new_ptr->origin_count = origin_count;
......@@ -482,14 +470,6 @@ int MPIDI_CH3I_Accumulate(const void *origin_addr, int origin_count, MPI_Datatyp
new_ptr->ureq = ureq;
}
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
if (mpi_errno)
MPIU_ERR_POP(mpi_errno);
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
/* if source or target datatypes are derived, increment their
* reference counts */
if (!MPIR_DATATYPE_IS_PREDEFINED(origin_datatype)) {
......@@ -514,8 +494,28 @@ int MPIDI_CH3I_Accumulate(const void *origin_addr, int origin_count, MPI_Datatyp
new_ptr->piggyback_lock_candidate = 1;
}
/************** Setting packet struct areas in operation ****************/
accum_pkt = &(new_ptr->pkt.accum);
MPIDI_Pkt_init(accum_pkt, MPIDI_CH3_PKT_ACCUMULATE);
accum_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
accum_pkt->count = target_count;
accum_pkt->datatype = target_datatype;
accum_pkt->dataloop_size = 0;
accum_pkt->op = op;
accum_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
accum_pkt->source_win_handle = win_ptr->handle;
accum_pkt->immed_len = 0;
accum_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
if (mpi_errno)
MPIU_ERR_POP(mpi_errno);
mpi_errno = MPIDI_CH3I_RMA_Make_progress_target(win_ptr, target_rank, &made_progress);
if (mpi_errno != MPI_SUCCESS) MPIU_ERR_POP(mpi_errno);
......@@ -633,21 +633,20 @@ int MPIDI_CH3I_Get_accumulate(const void *origin_addr, int origin_count,
if (op == MPI_NO_OP) {
/* Convert GAcc to a Get */
MPIDI_CH3_Pkt_get_t *get_pkt = &(new_ptr->pkt.get);
MPIDI_Pkt_init(get_pkt, MPIDI_CH3_PKT_GET);
get_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
get_pkt->count = target_count;
get_pkt->datatype = target_datatype;
get_pkt->dataloop_size = 0;
get_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_pkt->source_win_handle = win_ptr->handle;
get_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
MPIDI_CH3_Pkt_get_t *get_pkt;
/******************** Setting operation struct areas ***********************/
new_ptr->origin_addr = result_addr;
new_ptr->origin_count = result_count;
new_ptr->origin_datatype = result_datatype;
new_ptr->target_rank = target_rank;
new_ptr->ureq = NULL; /* reset user request */
/* Remember user request */
if (ureq) {
new_ptr->ureq = ureq;
}
if (!MPIR_DATATYPE_IS_PREDEFINED(result_datatype)) {
MPID_Datatype_get_ptr(result_datatype, dtp);
......@@ -664,21 +663,25 @@ int MPIDI_CH3I_Get_accumulate(const void *origin_addr, int origin_count,
if (!new_ptr->is_dt) {
new_ptr->piggyback_lock_candidate = 1;
}
/************** Setting packet struct areas in operation ****************/
get_pkt = &(new_ptr->pkt.get);
MPIDI_Pkt_init(get_pkt, MPIDI_CH3_PKT_GET);
get_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
get_pkt->count = target_count;
get_pkt->datatype = target_datatype;
get_pkt->dataloop_size = 0;
get_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_pkt->source_win_handle = win_ptr->handle;
get_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
}
else {
MPIDI_CH3_Pkt_get_accum_t *get_accum_pkt = &(new_ptr->pkt.get_accum);
MPIDI_Pkt_init(get_accum_pkt, MPIDI_CH3_PKT_GET_ACCUM);
get_accum_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
get_accum_pkt->count = target_count;
get_accum_pkt->datatype = target_datatype;
get_accum_pkt->dataloop_size = 0;
get_accum_pkt->op = op;
get_accum_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_accum_pkt->source_win_handle = win_ptr->handle;
get_accum_pkt->immed_len = 0;
get_accum_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
MPIDI_CH3_Pkt_get_accum_t *get_accum_pkt;
/******************** Setting operation struct areas ***********************/
new_ptr->origin_addr = (void *) origin_addr;
new_ptr->origin_count = origin_count;
......@@ -687,6 +690,12 @@ int MPIDI_CH3I_Get_accumulate(const void *origin_addr, int origin_count,
new_ptr->result_count = result_count;
new_ptr->result_datatype = result_datatype;
new_ptr->target_rank = target_rank;
new_ptr->ureq = NULL; /* reset user request */
/* Remember user request */
if (ureq) {
new_ptr->ureq = ureq;
}
/* if source or target datatypes are derived, increment their
* reference counts */
......@@ -716,13 +725,21 @@ int MPIDI_CH3I_Get_accumulate(const void *origin_addr, int origin_count,
MPIR_CVAR_CH3_RMA_OP_PIGGYBACK_LOCK_DATA_SIZE))
new_ptr->piggyback_lock_candidate = 1;
}
}
new_ptr->ureq = NULL; /* reset user request */
/************** Setting packet struct areas in operation ****************/
/* Remember user request */
if (ureq) {
new_ptr->ureq = ureq;
get_accum_pkt = &(new_ptr->pkt.get_accum);
MPIDI_Pkt_init(get_accum_pkt, MPIDI_CH3_PKT_GET_ACCUM);
get_accum_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
get_accum_pkt->count = target_count;
get_accum_pkt->datatype = target_datatype;
get_accum_pkt->dataloop_size = 0;
get_accum_pkt->op = op;
get_accum_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_accum_pkt->source_win_handle = win_ptr->handle;
get_accum_pkt->immed_len = 0;
get_accum_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
}
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
......@@ -943,14 +960,7 @@ int MPIDI_Compare_and_swap(const void *origin_addr, const void *compare_addr,
MPIR_T_PVAR_TIMER_START(RMA, rma_rmaqueue_set);
cas_pkt = &(new_ptr->pkt.cas);
MPIDI_Pkt_init(cas_pkt, MPIDI_CH3_PKT_CAS);
cas_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
cas_pkt->datatype = datatype;
cas_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
cas_pkt->source_win_handle = win_ptr->handle;
cas_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
/******************** Setting operation struct areas ***********************/
new_ptr->origin_addr = (void *) origin_addr;
new_ptr->origin_count = 1;
......@@ -963,6 +973,17 @@ int MPIDI_Compare_and_swap(const void *origin_addr, const void *compare_addr,
new_ptr->piggyback_lock_candidate = 1; /* CAS is always able to piggyback LOCK */
new_ptr->ureq = NULL; /* reset user request */
/************** Setting packet struct areas in operation ****************/
cas_pkt = &(new_ptr->pkt.cas);
MPIDI_Pkt_init(cas_pkt, MPIDI_CH3_PKT_CAS);
cas_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
cas_pkt->datatype = datatype;
cas_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
cas_pkt->source_win_handle = win_ptr->handle;
cas_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
......@@ -1068,7 +1089,20 @@ int MPIDI_Fetch_and_op(const void *origin_addr, void *result_addr,
if (op == MPI_NO_OP) {
/* Convert FOP to a Get */
MPIDI_CH3_Pkt_get_t *get_pkt = &(new_ptr->pkt.get);
MPIDI_CH3_Pkt_get_t *get_pkt;
/******************** Setting operation struct areas ***********************/
new_ptr->origin_addr = result_addr;
new_ptr->origin_count = 1;
new_ptr->origin_datatype = datatype;
new_ptr->target_rank = target_rank;
new_ptr->piggyback_lock_candidate = 1;
new_ptr->ureq = NULL; /* reset user request */
/************** Setting packet struct areas in operation ****************/
get_pkt = &(new_ptr->pkt.get);
MPIDI_Pkt_init(get_pkt, MPIDI_CH3_PKT_GET);
get_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
win_ptr->disp_units[target_rank] * target_disp;
......@@ -1078,15 +1112,24 @@ int MPIDI_Fetch_and_op(const void *origin_addr, void *result_addr,
get_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
get_pkt->source_win_handle = win_ptr->handle;
get_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
}
else {
MPIDI_CH3_Pkt_fop_t *fop_pkt;
new_ptr->origin_addr = result_addr;
/******************** Setting operation struct areas ***********************/
new_ptr->origin_addr = (void *) origin_addr;
new_ptr->origin_count = 1;
new_ptr->origin_datatype = datatype;
new_ptr->result_addr = result_addr;
new_ptr->result_datatype = datatype;
new_ptr->target_rank = target_rank;
new_ptr->piggyback_lock_candidate = 1;
}
else {
MPIDI_CH3_Pkt_fop_t *fop_pkt = &(new_ptr->pkt.fop);
new_ptr->ureq = NULL; /* reset user request */
/************** Setting packet struct areas in operation ****************/
fop_pkt = &(new_ptr->pkt.fop);
MPIDI_Pkt_init(fop_pkt, MPIDI_CH3_PKT_FOP);
fop_pkt->addr = (char *) win_ptr->base_addrs[target_rank] +
......@@ -1097,18 +1140,8 @@ int MPIDI_Fetch_and_op(const void *origin_addr, void *result_addr,
fop_pkt->target_win_handle = win_ptr->all_win_handles[target_rank];
fop_pkt->immed_len = 0;
fop_pkt->flags = MPIDI_CH3_PKT_FLAG_NONE;
new_ptr->origin_addr = (void *) origin_addr;
new_ptr->origin_count = 1;
new_ptr->origin_datatype = datatype;
new_ptr->result_addr = result_addr;
new_ptr->result_datatype = datatype;
new_ptr->target_rank = target_rank;
new_ptr->piggyback_lock_candidate = 1;
}
new_ptr->ureq = NULL; /* reset user request */
MPIR_T_PVAR_TIMER_END(RMA, rma_rmaqueue_set);
mpi_errno = MPIDI_CH3I_Win_enqueue_op(win_ptr, new_ptr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment