26 char ** comp_names,
size_t count);
33 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34 MPI_Comm_size(MPI_COMM_WORLD, &size);
38 PUT_ERR(
"ERROR: wrong number of processes\n");
47 char const * all_comp_names[] = {
"comp_a",
"comp_b",
"comp_c"};
48 enum {NUM_COMPS =
sizeof(all_comp_names) /
sizeof(all_comp_names[0])};
50 int comp_ranks[NUM_COMPS][4] = {{0, 1, 2, 4}, {0, 1, 3, 5}, {0, 2, 3, 6}};
52 int num_comp_ranks[NUM_COMPS] = {4, 4, 4};
55 char const * local_comp_names[NUM_COMPS];
56 size_t num_local_comps = 0;
57 for (
int i = 0;
i < NUM_COMPS; ++
i)
58 for (
int j = 0; j < num_comp_ranks[
i]; ++j)
59 if (rank == comp_ranks[i][j])
60 local_comp_names[num_local_comps++] = all_comp_names[
i];
64 utest_generate_couple_config((
char**)all_comp_names, NUM_COMPS);
69 couple_config, (
char const **)local_comp_names, num_local_comps,
81 MPI_Comm ref_comp_comm[NUM_COMPS], ref_comp_pair_comm[NUM_COMPS], ref_all_comps_comm;
83 MPI_Group world_group, comp_group[NUM_COMPS];
84 MPI_Comm_group(MPI_COMM_WORLD, &world_group);
85 for (
int i = 0;
i < NUM_COMPS; ++
i) {
87 world_group, num_comp_ranks[i], comp_ranks[i], &comp_group[i]);
88 MPI_Comm_create(MPI_COMM_WORLD, comp_group[i], &ref_comp_comm[i]);
90 for (
int i = 0, k = 0;
i < NUM_COMPS; ++
i) {
91 for (
int j = i + 1; j < NUM_COMPS; ++j, ++k) {
92 MPI_Group comp_pair_group;
93 MPI_Group_union(comp_group[i], comp_group[j], &comp_pair_group);
95 MPI_COMM_WORLD, comp_pair_group, &ref_comp_pair_comm[k]);
96 MPI_Group_free(&comp_pair_group);
100 MPI_Group all_comps_group = MPI_GROUP_EMPTY;
101 for (
int i = 0;
i < NUM_COMPS; ++
i) {
102 MPI_Group merge_group;
103 MPI_Group_union(all_comps_group, comp_group[i], &merge_group);
104 if (all_comps_group != MPI_GROUP_EMPTY)
105 MPI_Group_free(&all_comps_group);
106 all_comps_group = merge_group;
109 MPI_COMM_WORLD, all_comps_group, &ref_all_comps_comm);
110 MPI_Group_free(&all_comps_group);
112 for (
int i = 0;
i < NUM_COMPS; ++
i)
113 MPI_Group_free(&comp_group[i]);
114 MPI_Group_free(&world_group);
121 for (
int i = 0;
i < NUM_COMPS; ++
i) {
124 for (rank_idx = 0; (rank_idx < num_comp_ranks[
i]) && !is_local; ++rank_idx)
125 if (comp_ranks[i][rank_idx] == rank) is_local = 1;
127 comp_config, all_comp_names[i]) != is_local)
128 PUT_ERR(
"error in yac_component_config_contains_component");
132 PUT_ERR(
"error in yac_component_config_comp_size");
135 PUT_ERR(
"error in yac_component_config_comp_rank");
139 PUT_ERR(
"error in yac_component_config_contains_component");
143 for (
size_t i = 0;
i < num_local_comps; ++
i)
144 comp_flags |= (1 << (local_comp_names[i][5] -
'a'));
147 for (
int i = 0, k = 0;
i < NUM_COMPS; ++
i) {
148 for (
int j = i + 1; j < NUM_COMPS; ++j, ++k) {
149 if ((comp_flags & (1 << i)) || (comp_flags & (1 << j))) {
150 MPI_Comm comp_pair_comm =
153 (
char const *[]){all_comp_names[
i], all_comp_names[j]}, 2);
156 ref_comp_pair_comm[k], comp_pair_comm, &compare_result);
157 if (compare_result != MPI_CONGRUENT)
158 PUT_ERR(
"error in yac_component_config_get_comps_comm");
159 MPI_Comm_free(&comp_pair_comm);
165 if (ref_all_comps_comm != MPI_COMM_NULL) {
166 MPI_Comm all_comps_comm =
169 MPI_Comm_compare(ref_all_comps_comm, all_comps_comm, &compare_result);
170 if (compare_result != MPI_CONGRUENT)
171 PUT_ERR(
"error in yac_component_config_get_comps_comm");
172 MPI_Comm_free(&all_comps_comm);
177 comp_config, NULL, 0) != MPI_COMM_NULL)
178 PUT_ERR(
"error in yac_component_config_get_comps_comm");
186 if (ref_all_comps_comm != MPI_COMM_NULL)
187 MPI_Comm_free(&ref_all_comps_comm);
188 for (
int i = 0;
i < NUM_COMPS; ++
i) {
189 if (ref_comp_comm[i] != MPI_COMM_NULL)
190 MPI_Comm_free(&ref_comp_comm[i]);
191 if (ref_comp_pair_comm[i] != MPI_COMM_NULL)
192 MPI_Comm_free(&ref_comp_pair_comm[i]);
202 char ** comp_names,
size_t count) {
205 for (
size_t i = 0;
i < count; ++
i)
207 return couple_config;
int yac_component_config_comp_size(struct yac_component_config *comp_config, char const *comp_name)
int yac_component_config_comp_rank(struct yac_component_config *comp_config, char const *comp_name)
void yac_component_config_delete(struct yac_component_config *comp_config)
MPI_Comm yac_component_config_get_comps_comm(struct yac_component_config *comp_config, const char **names, size_t num_names)
int yac_component_config_contains_component(struct yac_component_config *comp_config, char const *comp_name)
struct yac_component_config * yac_component_config_new(struct yac_couple_config *couple_config, char const **names, size_t num_names, MPI_Comm comm_)
struct yac_couple_config * yac_couple_config_new()
void yac_couple_config_add_component(struct yac_couple_config *couple_config, char const *name)
void yac_couple_config_delete(struct yac_couple_config *couple_config)