Commit da054436 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Change internal routine for on-demand allocation.

parent f2eb6034
......@@ -280,7 +280,9 @@ xt_exchanger_mix_isend_irecv_get_msg_ranks(Xt_exchanger exchanger,
const struct mix_msg *restrict msgs = exchanger_msr->msgs;
for (size_t i = 0; i < nmsg_all; ++i)
nmsg += MSG_DIR(msgs[i]) == direction;
int *restrict ranks_ = *ranks = xmalloc(nmsg * sizeof (*ranks_));
int *restrict ranks_ = *ranks;
if (!ranks_)
ranks_ = *ranks = xmalloc(nmsg * sizeof (*ranks_));
for (size_t i = 0, j = (size_t)-1; i < nmsg_all; ++i)
if (MSG_DIR(msgs[i]) == direction)
ranks_[++j] = msgs[i].data.rank;
......
......@@ -300,8 +300,10 @@ xt_exchanger_neigh_alltoall_get_msg_ranks(Xt_exchanger exchanger,
size_t nsend = (size_t)exchanger_na->nmsg[SEND],
nmsg = (size_t)exchanger_na->nmsg[direction],
ofs = direction == SEND ? 0 : nsend;
*ranks = xmalloc(nmsg * sizeof(**ranks));
memcpy(*ranks, exchanger_na->ranks + ofs, nmsg * sizeof(**ranks));
int *ranks_ = *ranks;
if (!ranks_)
ranks_ = *ranks = xmalloc(nmsg * sizeof(**ranks));
memcpy(ranks_, exchanger_na->ranks + ofs, nmsg * sizeof(**ranks));
return (int)nmsg;
}
......
......@@ -262,7 +262,9 @@ xt_exchanger_simple_base_get_msg_ranks(Xt_exchanger exchanger,
size_t nmsg = (size_t)exchanger_sb->nmsg[direction];
struct Xt_redist_msg *restrict msgs = exchanger_sb->msgs
+ (direction == RECV ? (size_t)exchanger_sb->nmsg[SEND] : 0);
int *restrict ranks_ = *ranks = xmalloc(nmsg * sizeof (*ranks_));
int *restrict ranks_ = *ranks;
if (!ranks_)
ranks_ = *ranks = xmalloc(nmsg * sizeof (*ranks_));
for (size_t i = 0; i < nmsg; ++i)
ranks_[i] = msgs[i].rank;
return (int)nmsg;
......
......@@ -222,6 +222,7 @@ xt_redist_agg_msg_count(size_t num_redists, enum xt_msg_direction direction,
bool ranks_left = false;
/* get lists of ranks to send/receive message to/from */
for (size_t j = 0; j < num_redists; ++j) {
ranks[j] = NULL;
size_t nranks = num_ranks[j]
= (size_t)xt_redist_get_msg_ranks(redists[j], direction, ranks + j);
ranks_left |= (nranks > 0);
......
......@@ -154,7 +154,7 @@ struct Xt_redist_collection_ {
static void align_component_dt(unsigned num_redists, unsigned nmsgs,
const Xt_redist *redists,
int *restrict in_ranks[num_redists],
size_t num_ranks[num_redists],
const size_t num_ranks[num_redists],
int *out_ranks,
MPI_Datatype *component_dt,
enum xt_msg_direction direction)
......@@ -601,8 +601,12 @@ redist_collection_get_msg_ranks(Xt_redist redist,
int *ranks_orig
= (int *)(redist_coll->all_component_dt + nmsg * redist_coll->num_redists)
+ (((unsigned)direction-1) & nmsg_send);
int *ranks_ = *ranks = xmalloc(nmsg_direction * sizeof (*ranks_));
memcpy(ranks_, ranks_orig, nmsg_direction * sizeof (*ranks));
if (nmsg_direction > 0) {
int *ranks_ = *ranks;
if (!ranks_)
ranks_ = *ranks = xmalloc(nmsg_direction * sizeof (*ranks_));
memcpy(ranks_, ranks_orig, nmsg_direction * sizeof (*ranks));
}
return (int)nmsg_direction;
}
......
......@@ -118,10 +118,11 @@ xt_redist_check_comms(Xt_redist *redists, int num_redists, MPI_Comm comm);
* @param[in] redist redistribution object
* @param[in] direction specifices whether ranks for the outgoing or incoming
* messages are requested
* @param[out] ranks ranks for all outgoing/incoming messages
* @param[inout] ranks ranks for all outgoing/incoming messages
* @return number of outgoing/incoming message
* @remark the user needs to ensure that array ranks is big enough to hold all
* ranks
* ranks, each element of ranks must be either a pointer to a valid
* output array or NULL, in which case it will be allocated
*/
PPM_DSO_INTERNAL int
xt_redist_get_msg_ranks(Xt_redist redist, enum xt_msg_direction direction,
......
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