#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <mpi.h>
#include <yaxt.h>
#include "tests.h"
struct test_message {
int rank;
int num_pos;
const int *pos;
};
static void test_xmap(
int num_sends, const struct test_message send_messages[num_sends],
int num_recvs, const struct test_message recv_messages[num_recvs]);
int nsrc_com,
const struct Xt_com_list src_com[nsrc_com],
int ndst_com, const struct Xt_com_list dst_com[ndst_com],
Xt_idxlist src_idxlist, Xt_idxlist dst_idxlist, MPI_Comm comm);
static void
parse_options(int *argc, char ***argv);
int main(int argc, char **argv)
{
int my_rank, comm_size;
if (comm_size != 3) {
MPI_Finalize();
return 77;
}
parse_options(&argc, &argv);
{
int num_src_intersections = 1;
struct Xt_com_list src_com = {.
list = src_idxlist,
.rank = (my_rank+1)%comm_size};
int num_dst_intersections = 1;
struct Xt_com_list dst_com = {.
list = dst_idxlist,
.rank = (my_rank+comm_size-1)%comm_size};
Xt_xmap xmap = xmi_new(num_src_intersections, &src_com,
num_dst_intersections, &dst_com,
int send_pos = 0;
int num_sends = 1;
struct test_message send_messages[1] = {{.rank = (my_rank+1)%comm_size,
.pos = &send_pos, .num_pos = 1}};
int recv_pos = 0;
int num_recvs = 1;
struct test_message recv_messages[1] = {{.rank = (my_rank+comm_size-1)%comm_size,
.pos = &recv_pos, .num_pos = 1}};
test_xmap(xmap, num_sends, send_messages, num_recvs, recv_messages);
}
{
int num_src_intersections = (my_rank == 0)?0:1;
struct Xt_com_list src_com = {.
list = src_idxlist,
.rank = 0};
int num_dst_intersections = (my_rank == 0)?2:0;
struct Xt_com_list dst_com[2] = {{.
list = dst_idxlist, .rank = 1},
{.list = dst_idxlist, .rank = 2}};
Xt_xmap xmap = xmi_new(num_src_intersections, &src_com,
num_dst_intersections, dst_com,
int send_pos = 0;
int num_sends = (my_rank == 1)?1:0;
struct test_message send_messages[1] = {{.rank = 0, .pos = &send_pos,
.num_pos = 1}};
int recv_pos = 0;
int num_recvs = (my_rank == 0)?1:0;
struct test_message recv_messages[1] = {{.rank = 1, .pos = &recv_pos,
.num_pos = 1}};
test_xmap(xmap, num_sends, send_messages, num_recvs, recv_messages);
}
{
(
Xt_int)((my_rank+2)%comm_size) };
int num_src_intersections[3] = {2, 1, 0};
Xt_idxlist src_intersection_idxlist[2] = {
xt_idxvec_new(src_indices, 1),
struct Xt_com_list src_com[2] = {{.
list = src_intersection_idxlist[0],
.rank = 1},
{.list = src_intersection_idxlist[1],
.rank = (my_rank == 0)?2:0}};
int num_dst_intersections = 1;
struct Xt_com_list dst_com = {.
list = dst_idxlist, .rank = (my_rank == 0)?1:0};
Xt_xmap xmap = xmi_new(num_src_intersections[my_rank], src_com + my_rank,
num_dst_intersections, &dst_com,
if (my_rank == 0) {
int send_pos[2] = {0,1};
int num_sends = 2;
struct test_message send_messages[2] = {{.rank = 1, .pos = send_pos+0,
.num_pos = 1},
{.rank = 2, .pos = send_pos+1,
.num_pos = 1}};
int recv_pos = 0;
int num_recvs = 1;
struct test_message recv_messages[1] = {{.rank = 1, .pos = &recv_pos,
.num_pos = 1}};
test_xmap(xmap, num_sends, send_messages, num_recvs, recv_messages);
} else if (my_rank == 1) {
int send_pos = 1;
int num_sends = 1;
struct test_message send_messages[1] = {{.rank = 0, .pos = &send_pos,
.num_pos = 1}};
int recv_pos = 0;
int num_recvs = 1;
struct test_message recv_messages[1] = {{.rank = 0, .pos = &recv_pos,
.num_pos = 1}};
test_xmap(xmap, num_sends, send_messages, num_recvs, recv_messages);
} else {
int num_sends = 0;
int recv_pos = 0;
int num_recvs = 1;
struct test_message recv_messages[1] = {{.rank = 0, .pos = &recv_pos,
.num_pos = 1}};
test_xmap(xmap, num_sends, NULL, num_recvs, recv_messages);
}
}
{
static const Xt_int src_indices[3][5]
= {{0,1,2,3,4}, {3,4,5,6,7}, {6,7,8,0,1}};
static const Xt_int dst_indices[9] = {0,1,2,3,4,5,6,7,8};
struct Xt_com_list src_com[3] = {{.
list = src_idxlist, .rank = 0},
{.list = src_idxlist, .rank = 1},
{.list = src_idxlist, .rank = 2}};
struct Xt_com_list dst_com[3] =
Xt_xmap xmap = xmi_new(3, src_com, 3, dst_com,
static const int send_pos[3][5] = {{0,1,2,3,4}, {2,3,4}, {2}};
static const int num_send_pos[3] = {5, 3, 1};
struct test_message send_messages[3] = {{.rank = 0,
.pos = send_pos[my_rank],
.num_pos = num_send_pos[my_rank]},
{.rank = 1,
.pos = send_pos[my_rank],
.num_pos = num_send_pos[my_rank]},
{.rank = 2,
.pos = send_pos[my_rank],
.num_pos = num_send_pos[my_rank]}};
static const int recv_pos[3][5] = {{0,1,2,3,4}, {5,6,7}, {8}};
static const int num_recv_pos[3] = {5, 3, 1};
struct test_message recv_messages[3] = {{.rank = 0, .pos = recv_pos[0],
.num_pos = num_recv_pos[0]},
{.rank = 1, .pos = recv_pos[1],
.num_pos = num_recv_pos[1]},
{.rank = 2, .pos = recv_pos[2],
.num_pos = num_recv_pos[2]}};
test_xmap(xmap, 3, send_messages, 3, recv_messages);
}
{
Xt_int src_indices[2][2] = {{0,2}, {1,2}};
struct Xt_com_list * src_com, * dst_com;
int num_src_intersections, num_dst_intersections;
Xt_idxlist src_idxlist, dst_idxlist;
if (my_rank == 2) {
src_com = NULL;
num_src_intersections = 0;
dst_com = malloc(2 * sizeof(*dst_com));
num_dst_intersections = 2;
Xt_int dst_indices[3] = {0,1,2};
} else {
src_com = malloc(1 * sizeof(*src_com));
num_src_intersections = 1;
dst_com = NULL;
num_dst_intersections = 0;
}
Xt_xmap xmap = xmi_new(num_src_intersections, src_com,
num_dst_intersections, dst_com,
if (my_rank == 2) {
static const int recv_pos[2][2] = {{0,2}, {1}};
static const struct test_message recv_messages[2]
= {{.rank = 0, .pos = recv_pos[0], .num_pos = 2},
{.rank = 1, .pos = recv_pos[1], .num_pos = 1}};
test_xmap(xmap, 0, NULL, 2, recv_messages);
} else {
static const int send_pos[2][2] = {{0,1}, {0}};
static const int num_send_pos[2] = {2, 1};
struct test_message send_messages = {.rank = 2,
.pos = send_pos[my_rank],
.num_pos = num_send_pos[my_rank]};
test_xmap(xmap, 1, &send_messages, 0, NULL);
}
for (int i = 0; i < num_dst_intersections; ++i)
free(dst_com);
for (int i = 0; i < num_src_intersections; ++i)
free(src_com);
}
MPI_Finalize();
return TEST_EXIT_CODE;
}
const struct test_message msgs[num_msgs]) {
if (num_msgs == 0) {
if (iter != NULL)
PUT_ERR("ERROR: xt_xmap_get_*_iterator (iter should be NULL)\n");
} else if (iter == NULL) {
PUT_ERR("ERROR: xt_xmap_get_*_iterator (iter should not be NULL)\n");
} else {
int i = 0;
do {
PUT_ERR("ERROR: xt_xmap_iterator_get_rank\n");
PUT_ERR("ERROR: xt_xmap_iterator_get_num_transfer_pos\n");
for (int j = 0; j < msgs[i].num_pos; ++j)
if (pos[j] != msgs[i].pos[j])
PUT_ERR("ERROR: xt_xmap_iterator_get_transfer_pos\n");
++i;
if (i != num_msgs)
PUT_ERR("ERROR: xt_xmap_iterator_next (wrong number of message)\n");
}
}
static void test_xmap(
int num_sends, const struct test_message send_messages[num_sends],
int num_recvs, const struct test_message recv_messages[num_recvs]) {
enum { numXmaps2Test = 2 };
for (size_t i = 0; i < numXmaps2Test; ++i) {
PUT_ERR("ERROR: xt_xmap_get_num_destinations\n");
PUT_ERR("ERROR: xt_xmap_get_num_sources\n");
test_xmap_iter(send_iter, num_sends, send_messages);
test_xmap_iter(recv_iter, num_recvs, recv_messages);
}
}
static void
parse_options(int *argc, char ***argv)
{
int opt;
while ((opt = getopt(*argc, *argv, "m:")) != -1) {
switch (opt) {
case 'm':
if (!strcmp(optarg, "xt_xmap_intersection_new"))
else if (!strcmp(optarg, "xt_xmap_intersection_ext_new"))
else
{
fprintf(stderr, "Unknown xmap intersection constructor requested %s\n",
optarg);
exit(EXIT_FAILURE);
}
}
}
}