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);
23 int number_of_facets{sim->m_simulation_config.getIntParameters("number_of_facets")};
24 sim->m_simulation_config.forceValueOverwrite("global_number_of_facets",
25 std::to_string(number_of_facets));
26
27 // The following distinction is needed for if the number of facets is not evenly divisable by
28 // the number of processes.
29 // Minimum number of of facets manages by each process (that's why its rounded off).
30 sim->min_number_facets_per_proc = number_of_facets / sim->world_size;
31 // Number of processes that need to manage min_number_facets_per_proc + 1 facet.
32 sim->number_of_larger_procs =
33 number_of_facets - sim->min_number_facets_per_proc * sim->world_size;
34
35 // Check if no color split needs to be done, if number_of_facets is integer divisible by
36 // world_size
37 sim->other_color_exists = sim->number_of_larger_procs > 0 ? 1 : 0;
38 // The first number_of_larger_procs processes get one extra facet, so that all facets are
39 // accounted for in the end.
40 if (sim->my_rank < sim->number_of_larger_procs)
41 {
42 sim->m_simulation_config.forceValueOverwrite(
43 "number_of_facets", std::to_string(sim->min_number_facets_per_proc + 1));
44 sim->m_simulation_config.forceValueOverwrite(
45 "global_starting_facet_number",
46 std::to_string(sim->my_rank * (sim->min_number_facets_per_proc + 1)));
47 // The processes will be grouped along their length for collective communications along
48 // subcomms.
49 sim->my_color = 0;
50 }
51 else
52 {
53 sim->m_simulation_config.forceValueOverwrite(
54 "number_of_facets", std::to_string(sim->min_number_facets_per_proc));
55 sim->m_simulation_config.forceValueOverwrite(
56 "global_starting_facet_number",
57 std::to_string(sim->number_of_larger_procs * (sim->min_number_facets_per_proc + 1)
58 + (sim->my_rank - sim->number_of_larger_procs)
59 * sim->min_number_facets_per_proc));
60 // The processes will be grouped along their length for collective communications along
61 // sub-comms.
62 sim->my_color = 1;
63 }
64 // Skip creation of sub- and intercomm if not necessary
65 if (sim->other_color_exists == 0)
66 {
67 sim->sub_size = -1;
68 sim->my_sub_rank = -1;
69 sim->remote_leader = -1;
70 sim->my_inter_rank = -1;
71 sim->sub_comm = MPI_COMM_NULL;
72 sim->inter_comm = MPI_COMM_NULL;
73 return;
74 }
75 // Creation of the sub-communicators
76 MPI_Comm_split(MPI_COMM_WORLD, sim->my_color, 0, &sim->sub_comm);
77 MPI_Comm_size(sim->sub_comm, &sim->sub_size);
78 MPI_Comm_rank(sim->sub_comm, &sim->my_sub_rank);
79
80 // Leader designation for the creation of the inter-communicator.
81 // Leader is always process 0 in the other sub-comm.
82 if (sim->my_color == 0)
83 {
84 sim->remote_leader = sim->sub_size;
85 }
86 else
87 {
88 sim->remote_leader = 0;
89 }
90
91 // Creation of inter-communicator
92 if (sim->world_size > 1)
93 {
94 MPI_Intercomm_create(sim->sub_comm, 0, MPI_COMM_WORLD, sim->remote_leader, 0,
95 &sim->inter_comm);
96 MPI_Comm_rank(sim->inter_comm, &sim->my_inter_rank);
97 }
98}
99
100#endif // MPI_PRESENT
101
102#endif // MPI_DOMAIN_DECOMPOSITION_H
Concrete implementation of a matrix class representing a Compressed Sparse Rows (CSR) matrix....
Definition CsrMatrix.h:35