MoCSI API Reference
Loading...
Searching...
No Matches
MpiDomainDecomposition.h
Go to the documentation of this file.
1#ifndef MPI_DOMAIN_DECOMPOSITION_H
2#define MPI_DOMAIN_DECOMPOSITION_H
3
4#ifdef MPI_PRESENT
5
6#include <mpi.h>
7
9
18template <typename T>
20{
21 MPI_Comm_rank(MPI_COMM_WORLD, &sim->my_rank);
22 MPI_Comm_size(MPI_COMM_WORLD, &sim->world_size);
24 try
25 {
26 number_of_facets = sim->m_simulation_config.getIntParameters("number_of_facets");
27 }
28 catch (const BadInput& e)
29 {
30 std::cerr << static_cast<std::string>("[MpiDomainDecomposition]: ")
31 << static_cast<std::string>(e.what()) << '\n';
32 throw BadInput(static_cast<std::string>("[MpiDomainDecomposition]: ")
33 + static_cast<std::string>(e.what()));
34 }
35 sim->m_simulation_config.forceValueOverwrite("global_number_of_facets",
36 std::to_string(number_of_facets));
37
38 // The following distinction is needed for if the number of facets is not evenly divisable by
39 // the number of processes.
40 // Minimum number of of facets manages by each process (that's why its rounded off).
41 sim->min_number_facets_per_proc = number_of_facets / sim->world_size;
42 // Number of processes that need to manage min_number_facets_per_proc + 1 facet.
43 sim->number_of_larger_procs =
44 number_of_facets - sim->min_number_facets_per_proc * sim->world_size;
45
46 // Check if no color split needs to be done, if number_of_facets is integer divisible by
47 // world_size
48 sim->other_color_exists = sim->number_of_larger_procs > 0 ? 1 : 0;
49 // The first number_of_larger_procs processes get one extra facet, so that all facets are
50 // accounted for in the end.
51 if (sim->my_rank < sim->number_of_larger_procs)
52 {
53 sim->m_simulation_config.forceValueOverwrite(
54 "number_of_facets", std::to_string(sim->min_number_facets_per_proc + 1));
55 sim->m_simulation_config.forceValueOverwrite(
56 "global_starting_facet_number",
57 std::to_string(sim->my_rank * (sim->min_number_facets_per_proc + 1)));
58 // The processes will be grouped along their length for collective communications along
59 // subcomms.
60 sim->my_color = 0;
61 }
62 else
63 {
64 sim->m_simulation_config.forceValueOverwrite(
65 "number_of_facets", std::to_string(sim->min_number_facets_per_proc));
66 sim->m_simulation_config.forceValueOverwrite(
67 "global_starting_facet_number",
68 std::to_string(sim->number_of_larger_procs * (sim->min_number_facets_per_proc + 1)
69 + (sim->my_rank - sim->number_of_larger_procs)
70 * sim->min_number_facets_per_proc));
71 // The processes will be grouped along their length for collective communications along
72 // sub-comms.
73 sim->my_color = 1;
74 }
75 // Skip creation of sub- and intercomm if not necessary
76 if (sim->other_color_exists == 0)
77 {
78 sim->sub_size = -1;
79 sim->my_sub_rank = -1;
80 sim->remote_leader = -1;
81 sim->my_inter_rank = -1;
82 sim->sub_comm = MPI_COMM_NULL;
83 sim->inter_comm = MPI_COMM_NULL;
84 return;
85 }
86 // Creation of the sub-communicators
87 MPI_Comm_split(MPI_COMM_WORLD, sim->my_color, 0, &sim->sub_comm);
88 MPI_Comm_size(sim->sub_comm, &sim->sub_size);
89 MPI_Comm_rank(sim->sub_comm, &sim->my_sub_rank);
90
91 // Leader designation for the creation of the inter-communicator.
92 // Leader is always process 0 in the other sub-comm.
93 if (sim->my_color == 0)
94 {
95 sim->remote_leader = sim->sub_size;
96 }
97 else
98 {
99 sim->remote_leader = 0;
100 }
101
102 // Creation of inter-communicator
103 if (sim->world_size > 1)
104 {
105 MPI_Intercomm_create(sim->sub_comm, 0, MPI_COMM_WORLD, sim->remote_leader, 0,
106 &sim->inter_comm);
107 MPI_Comm_rank(sim->inter_comm, &sim->my_inter_rank);
108 }
109}
110
111#endif // MPI_PRESENT
112
113#endif // MPI_DOMAIN_DECOMPOSITION_H
This error class inherits from std::exception and marks faulty parameter or CL inputs....
Definition IniParser.h:71
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:37