19 bool cycle_allowance_flag,
21 :
SPDS(omega, grid, verbose)
24 <<
" Building sweep ordering for Omega = "
31 std::vector<std::set<std::pair<int, double>>> cell_successors(num_loc_cells);
32 std::set<int> location_successors;
33 std::set<int> location_dependencies;
36 location_dependencies,
43 for (
auto v : location_successors)
46 for (
auto v : location_dependencies)
53 for (
int c = 0; c < num_loc_cells; ++c)
57 for (
int c = 0; c < num_loc_cells; c++)
58 for (
auto& successor : cell_successors[c])
59 local_DG.
AddEdge(c, successor.first, successor.second);
65 if (cycle_allowance_flag)
72 for (
auto& edge_to_remove : edges_to_remove)
75 edge_to_remove.second);
82 <<
" Generating topological sorting for local sweep ordering";
85 for (
auto v : so_temp)
91 <<
"Topological sorting for local sweep-ordering failed. "
92 <<
"Cyclic dependencies detected. Cycles need to be allowed"
93 <<
" by calling application.";
104 <<
" Communicating sweep dependencies.";
107 std::vector<std::vector<int>> global_dependencies;
108 global_dependencies.resize(
Chi::mpi.process_count);
119 <<
" Done computing sweep ordering.\n\n";
126 const std::vector<std::vector<int>>& global_dependencies,
127 bool cycle_allowance_flag)
130 std::vector<std::pair<int, int>> edges_to_remove;
131 std::vector<int> raw_edges_to_remove;
138 <<
" Building Task Dependency Graphs.";
146 for (
int dep = 0; dep < global_dependencies[loc].size(); dep++)
147 TDG.
AddEdge(global_dependencies[loc][dep], loc);
150 if (cycle_allowance_flag)
153 <<
" Removing intra-cellset cycles.";
155 for (
const auto& [v0, v1] : edges_to_remove_temp)
156 edges_to_remove.emplace_back(v0, v1);
160 raw_edges_to_remove.resize(edges_to_remove.size() * 2, 0);
162 for (
const auto& edge : edges_to_remove)
164 raw_edges_to_remove[i++] = edge.first;
165 raw_edges_to_remove[i++] = edge.second;
170 int edge_buffer_size = 0;
173 edge_buffer_size =
static_cast<int>(raw_edges_to_remove.size());
175 MPI_Bcast(&edge_buffer_size,
183 raw_edges_to_remove.resize(edge_buffer_size, -1);
185 MPI_Bcast(raw_edges_to_remove.data(),
194 edges_to_remove.resize(edge_buffer_size / 2, std::pair<int, int>(0, 0));
196 for (
auto& edge : edges_to_remove)
198 edge.first = raw_edges_to_remove[i++];
199 edge.second = raw_edges_to_remove[i++];
204 for (
auto& edge_to_remove : edges_to_remove)
206 int rlocI = edge_to_remove.first;
207 int locI = edge_to_remove.second;
213 auto dependent_location = std::find(
214 location_dependencies_.begin(), location_dependencies_.end(), rlocI);
215 location_dependencies_.erase(dependent_location);
216 delayed_location_dependencies_.push_back(rlocI);
220 delayed_location_successors_.push_back(locI);
224 std::vector<int> glob_linear_sweep_order;
228 <<
" - Generating topological sort.";
230 for (
auto v : so_temp)
231 glob_linear_sweep_order.emplace_back(v);
233 if (glob_linear_sweep_order.empty())
236 <<
"Topological sorting for global sweep-ordering failed. "
237 <<
"Cyclic dependencies detected. Cycles need to be allowed"
238 <<
" by calling application.";
244 int topsort_buffer_size = 0;
247 topsort_buffer_size = glob_linear_sweep_order.size();
249 MPI_Bcast(&topsort_buffer_size,
257 glob_linear_sweep_order.resize(topsort_buffer_size, -1);
259 MPI_Bcast(glob_linear_sweep_order.data(),
269 std::vector<int> glob_order_mapping(
Chi::mpi.process_count, -1);
273 int loc = glob_linear_sweep_order[k];
274 glob_order_mapping[loc] = k;
279 <<
" Determining sweep order ranks.";
281 std::vector<int> glob_sweep_order_rank(
Chi::mpi.process_count, -1);
283 int abs_max_rank = 0;
286 int loc = glob_linear_sweep_order[k];
287 if (global_dependencies[loc].empty()) glob_sweep_order_rank[k] = 0;
291 for (
auto dep_loc : global_dependencies[loc])
293 if (dep_loc < 0)
continue;
294 int dep_mapped_index = glob_order_mapping[dep_loc];
296 if (glob_sweep_order_rank[dep_mapped_index] > max_rank)
297 max_rank = glob_sweep_order_rank[dep_mapped_index];
299 glob_sweep_order_rank[k] = max_rank + 1;
300 if ((max_rank + 1) > abs_max_rank) abs_max_rank = max_rank + 1;
306 <<
" Generating TDG structure.";
307 for (
int r = 0; r <= abs_max_rank; r++)
313 if (glob_sweep_order_rank[k] == r)
314 new_stdg.
item_id.push_back(glob_linear_sweep_order[k]);
316 global_sweep_planes_.push_back(new_stdg);
static chi::Timer program_timer
static void Exit(int error_code)
static chi::MPI_Info & mpi
LogStream LogAllVerbose2()
std::vector< size_t > GenerateTopologicalSort()
std::vector< std::pair< size_t, size_t > > RemoveCyclicDependencies()
void AddVertex(size_t id, void *context=nullptr)
void RemoveEdge(size_t from, size_t to)
bool AddEdge(size_t from, size_t to, double weight=1.0)
const MPI_Comm & comm
MPI communicator.
const int & process_count
Total number of processes.
std::string GetTimeString() const
LocalCellHandler local_cells
void BuildTaskDependencyGraph(const std::vector< std::vector< int > > &global_dependencies, bool cycle_allowance_flag)
SPDS_AdamsAdamsHawkins(const chi_mesh::Vector3 &omega, const chi_mesh::MeshContinuum &grid, bool cycle_allowance_flag, bool verbose)
std::vector< int > location_dependencies_
std::vector< int > location_successors_
std::vector< std::pair< int, int > > local_cyclic_dependencies_
void PrintedGhostedGraph() const
void PopulateCellRelationships(const chi_mesh::Vector3 &omega, std::set< int > &location_dependencies, std::set< int > &location_successors, std::vector< std::set< std::pair< int, double > > > &cell_successors)
void CommunicateLocationDependencies(const std::vector< int > &location_dependencies, std::vector< std::vector< int > > &global_dependencies)
std::string PrintS() const
std::vector< int > item_id
std::vector< int > item_id