Commit 436442ad authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Combine allocations in xt_redist_agg_msg_count.

parent da054436
......@@ -221,14 +221,28 @@ 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 */
size_t num_ranks_total = 0;
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);
/* sort list */
xt_sort_int(ranks[j], nranks);
size_t redist_num_ranks
= (size_t)(redists[j]->vtable->get_num_msg(redists[j], direction));
num_ranks[j] = redist_num_ranks;
num_ranks_total += redist_num_ranks;
}
if (num_ranks_total) {
int *ranks_buf = xmalloc(num_ranks_total * sizeof (*ranks_buf));
size_t ofs = 0;
for (size_t j = 0; j < num_redists; ++j) {
ranks[j] = ranks_buf + ofs;
size_t nranks
= (size_t)xt_redist_get_msg_ranks(redists[j], direction, ranks + j);
ranks_left |= (nranks > 0);
/* sort list */
xt_sort_int(ranks[j], nranks);
ofs += nranks;
}
} else
for (size_t j = 0; j < num_redists; ++j)
ranks[j] = NULL;
/* count number of different ranks to send/receive message to/from */
size_t num_messages = ranks_left
? xt_ranks_uniq_count(num_redists, num_ranks, (const int *const *)ranks)
......
......@@ -182,8 +182,7 @@ static void align_component_dt(unsigned num_redists, unsigned nmsgs,
+= (rank_pos[j] < num_ranks[j] && in_ranks[j][rank_pos[j]] == min_rank);
}
}
for (size_t j = 0; j < num_redists; ++j)
free(in_ranks[j]);
free(in_ranks[0]);
}
/* not yet used cache entries are marked with -1 as first displacement,
......
......@@ -113,8 +113,7 @@ generate_msg_infos(struct Xt_redist_msg ** msgs,
}
}
}
for (size_t j = 0; j < num_redists; ++j)
free(ranks[j]);
free(ranks[0]);
*msgs = p;
return num_messages;
}
......
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