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

Extract common code.

parent 17fa9a6c
......@@ -56,6 +56,7 @@
#include "xt/xt_redist.h"
#include "xt/xt_mpi.h"
#include "xt/xt_request.h"
#include "xt/xt_sort.h"
#include "core/ppm_xfuncs.h"
#include "xt_redist_internal.h"
......@@ -183,6 +184,28 @@ xt_redist_check_comms(Xt_redist *redists, int num_redists, MPI_Comm comm) {
}
}
unsigned
xt_redist_agg_msg_count(size_t num_redists, enum xt_msg_direction direction,
const Xt_redist redists[num_redists],
size_t num_ranks[num_redists],
int *restrict ranks[num_redists])
{
bool ranks_left = false;
/* get lists of ranks to send/receive message to/from */
for (size_t j = 0; j < num_redists; ++j) {
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);
}
/* 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)
: 0;
return (unsigned)num_messages;
}
size_t
xt_ranks_uniq_count(size_t num_rank_sets,
const size_t *restrict num_ranks,
......
......@@ -58,7 +58,6 @@
#include "core/core.h"
#include "core/ppm_xfuncs.h"
#include "xt/xt_mpi.h"
#include "xt/xt_sort.h"
#include "xt_mpi_internal.h"
#include "xt/xt_redist_collection.h"
#include "ensure_array_size.h"
......@@ -150,29 +149,6 @@ struct Xt_redist_collection_ {
MPI_Datatype all_component_dt[];
};
static unsigned
get_msg_count(const Xt_redist *redists, unsigned num_redists,
enum xt_msg_direction direction,
size_t num_ranks[num_redists],
int *restrict ranks[num_redists])
{
bool ranks_left = false;
/* get lists of ranks to send/receive message to/from */
for (size_t j = 0; j < num_redists; ++j) {
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);
}
/* 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)
: 0;
return (unsigned)num_messages;
}
static void align_component_dt(unsigned num_redists, unsigned nmsgs,
const Xt_redist *redists,
int *restrict in_ranks[num_redists],
......@@ -247,10 +223,10 @@ Xt_redist xt_redist_collection_new(Xt_redist * redists, int num_redists,
unsigned num_redists_ = num_redists >= 0 ? (unsigned)num_redists : 0;
size_t num_ranks[2][num_redists_];
int *restrict ranks[2][num_redists_];
unsigned nmsg_send = get_msg_count(redists, num_redists_, SEND,
num_ranks[SEND], ranks[SEND]),
nmsg_recv = get_msg_count(redists, num_redists_, RECV,
num_ranks[RECV], ranks[RECV]);
unsigned nmsg_send = xt_redist_agg_msg_count(num_redists_, SEND, redists,
num_ranks[SEND], ranks[SEND]),
nmsg_recv = xt_redist_agg_msg_count(num_redists_, RECV, redists,
num_ranks[RECV], ranks[RECV]);
size_t nmsg = (size_t)nmsg_send + nmsg_recv;
size_t size_all_component_dt = sizeof (MPI_Datatype) * num_redists_ * nmsg;
Xt_redist_collection redist_coll
......
......@@ -63,38 +63,30 @@
#include "ensure_array_size.h"
#include "xt/xt_redist.h"
#include "xt_redist_internal.h"
#include "xt/xt_sort.h"
static size_t
generate_msg_infos(struct Xt_redist_msg ** msgs,
const MPI_Aint *displacements, Xt_redist *redists,
const MPI_Aint *displacements,
const Xt_redist *redists,
size_t num_redists, MPI_Comm comm,
enum xt_msg_direction direction)
{
int block_lengths[num_redists];
MPI_Datatype datatypes[num_redists];
for (size_t i = 0; i < num_redists; ++i)
block_lengths[i] = 1;
size_t num_ranks[num_redists], rank_pos[num_redists];
size_t num_ranks[num_redists];
int *restrict ranks[num_redists];
bool ranks_left = false;
size_t num_messages = xt_redist_agg_msg_count(num_redists, direction,
redists, num_ranks, ranks);
/* get lists of ranks to send/receive message to/from */
for (size_t j = 0; j < num_redists; ++j) {
num_ranks[j]
= (size_t)xt_redist_get_msg_ranks(redists[j], direction, ranks + j);
/* sort list */
xt_sort_int(ranks[j], num_ranks[j]);
ranks_left |= (num_ranks[j] > 0);
size_t rank_pos[num_redists];
for (size_t j = 0; j < num_redists; ++j)
rank_pos[j] = 0;
}
size_t num_messages = ranks_left
? xt_ranks_uniq_count(num_redists, num_ranks, (const int **)ranks) : 0;
struct Xt_redist_msg *p = NULL;
if (num_messages) {
MPI_Datatype datatypes[num_redists];
int block_lengths[num_redists];
for (size_t i = 0; i < num_redists; ++i)
block_lengths[i] = 1;
p = xmalloc(sizeof (*p) * num_messages);
for (size_t i = 0; i < num_messages; ++i) {
int min_rank = INT_MAX;
......
......@@ -118,6 +118,12 @@ xt_create_compound_datatype(size_t num_redists,
const int block_lengths[num_redists],
MPI_Comm comm);
unsigned
xt_redist_agg_msg_count(size_t num_redists, enum xt_msg_direction direction,
const Xt_redist redists[num_redists],
size_t num_ranks[num_redists],
int *restrict ranks[num_redists]);
#endif
/*
* Local Variables:
......
Supports Markdown
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