This example show how to set up a YAC instance. It uses nine processes.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <mpi.h>
#include "tests.h"
#include "test_common.h"
#include "yaxt.h"
static char const * component_names[3] = {"comp_1", "comp_2", "comp_3"};
void check_comm(
size_t * comp_idxs, size_t num_comps, int ref_size) ;
MPI_Init(NULL, NULL);
xt_initialize(MPI_COMM_WORLD);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size != 9) {
PUT_ERR("ERROR: wrong number of processes\n");
return TEST_EXIT_CODE;
}
{
instance, &(component_names[rank / 3]), 1);
if (rank < 6) check_comm(instance, (size_t[]){0, 1}, 2, 6);
if ((rank < 3) || (rank >= 6))
check_comm(instance, (size_t[]){0, 2}, 2, 6);
if (rank >= 3) check_comm(instance, (size_t[]){1, 2}, 2, 6);
check_comm(instance, (size_t[]){0, 1, 2}, 3, 9);
}
{
char const * comp_names[2] = {component_names[0], component_names[1]};
check_comm(instance, (size_t[]){0, 1}, 2, 9);
}
{
int num_comps;
char const * comp_names[2];
comp_names[0] = component_names[0];
if (rank < 3) {
comp_names[1] = component_names[1];
num_comps = 2;
} else if (rank < 6) {
num_comps = 1;
} else {
comp_names[1] = component_names[2];
num_comps = 2;
}
check_comm(instance, (size_t[]){0, 1}, 2, 9);
check_comm(instance, (size_t[]){0, 2}, 2, 9);
if ((rank < 3) || (rank >= 6))
check_comm(instance, (size_t[]){1, 2}, 2, 6);
check_comm(instance, (size_t[]){0, 1, 2}, 3, 9);
}
{
int num_comps = 0;
char const * comp_names[2];
if (rank < 3) comp_names[num_comps++] = component_names[0];
else if (rank < 8) comp_names[num_comps++] = component_names[1];
if (rank >= 6) comp_names[num_comps++] = component_names[2];
if (rank < 8) check_comm(instance, (size_t[]){0, 1}, 2, 8);
if ((rank < 3) || (rank >= 6))
check_comm(instance, (size_t[]){0, 2}, 2, 6);
if (rank >= 3) check_comm(instance, (size_t[]){1, 2}, 2, 6);
check_comm(instance, (size_t[]){0, 1, 2}, 3, 9);
}
{
if ((rank % 3) == 2) {
} else {
MPI_Comm yac_comm;
char const * yac_groupname = "yac";
MPI_Comm_free(&yac_comm);
char const * comp_names[] = {component_names[(rank & 1)]};
check_comm(instance, (size_t[]){0, 1}, 2, 6);
}
}
xt_finalize();
MPI_Finalize();
return TEST_EXIT_CODE;
}
void check_comm(
size_t * comp_idxs, size_t num_comps, int ref_size) {
char const ** comp_names =
xmalloc(num_comps *
sizeof(*comp_names));
for (size_t i = 0; i < num_comps; ++i)
comp_names[i] = component_names[comp_idxs[i]];
MPI_Comm comps_comm =
free(comp_names);
int comps_comm_size;
MPI_Comm_size(comps_comm, &comps_comm_size);
if (comps_comm_size != ref_size) PUT_ERR("invalid size of comps_comm");
MPI_Comm_free(&comps_comm);
}
int main(int argc, char **argv)
void yac_instance_delete(struct yac_instance *instance)
struct yac_instance * yac_instance_new(MPI_Comm comm)
void yac_instance_def_components(struct yac_instance *instance, char const **comp_names, size_t num_comps)
MPI_Comm yac_instance_get_comps_comm(struct yac_instance *instance, char const **comp_names, size_t num_comp_names)
void yac_cmpi_handshake(MPI_Comm comm, size_t n, char const **group_names, MPI_Comm *group_comms)