Debian Codegraph @

packages/seacas/libraries/ioss/src/exonull/Ioexnl_DecompositionData.C

raw
1 // Copyright(C) 1999-2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "Ioss_CodeTypes.h"
8 #include "exonull/Ioexnl_DecompositionData.h"
9 #if defined PARALLEL_AWARE_EXODUS
10 #include "Ioss_Field.h" // for Field, etc
11 #include "Ioss_Map.h" // for Map, MapContainer
12 #include "Ioss_PropertyManager.h" // for PropertyManager
13 #include "Ioss_Utils.h"
14 #include "exonull/Ioexnl_Utils.h"
15
16 #include <algorithm>
17 #include <climits>
18 #include <cstdlib>
19 #include <iterator>
20 #include <utility>
21
22 namespace Ioexnl {
23 template DecompositionData<int>::DecompositionData(const Ioss::PropertyManager &props,
24 Ioss_MPI_Comm communicator);
25 template DecompositionData<int64_t>::DecompositionData(const Ioss::PropertyManager &props,
26 Ioss_MPI_Comm communicator);
27
28 template <typename INT>
29 DecompositionData<INT>::DecompositionData(const Ioss::PropertyManager &props,
30 Ioss_MPI_Comm communicator)
31 : DecompositionDataBase(communicator), m_decomposition(props, communicator)
32 {
33 Ioss::ParallelUtils pu(comm_);
34 m_processor = pu.parallel_rank();
35 m_processorCount = pu.parallel_size();
36 }
37
38 template void DecompositionData<int>::create_implicit_global_map(
39 const std::vector<int> &owning_proc, std::vector<int64_t> &global_implicit_map,
40 Ioss::Map &node_map, int64_t *locally_owned_count, int64_t *processor_offset);
41 template void DecompositionData<int64_t>::create_implicit_global_map(
42 const std::vector<int> &owning_proc, std::vector<int64_t> &global_implicit_map,
43 Ioss::Map &node_map, int64_t *locally_owned_count, int64_t *processor_offset);
44
45 template <typename INT>
46 void DecompositionData<INT>::create_implicit_global_map(const std::vector<int> &owning_proc,
47 std::vector<int64_t> &global_implicit_map,
48 Ioss::Map &node_map,
49 int64_t *locally_owned_count,
50 int64_t *processor_offset)
51 {
52 m_decomposition.show_progress(__func__);
53 // Used on composed output database...
54 // If the node is locally owned, then its position is basically
55 // determined by removing all shared nodes from the list and
56 // then compressing the list. This location plus the proc_offset
57 // gives its location in the global-implicit file.
58 //
59 // If it is shared, then need to communicate with the owning
60 // processor to determine where that processor is putting it.
61 //
62 // First, iterate nodeOwningProcessor list and set the implicit
63 // map for all locally-owned nodes and also determine how many
64 // of my nodes are owned by which other processors.
65
66 global_implicit_map.resize(owning_proc.size());
67
68 std::vector<int64_t> snd_count(m_processorCount);
69 std::vector<int64_t> rcv_count(m_processorCount);
70
71 size_t position = 0;
72 for (size_t i = 0; i < global_implicit_map.size(); i++) {
73 snd_count[owning_proc[i]]++;
74 if (owning_proc[i] == m_processor) {
75 global_implicit_map[i] = position++;
76 }
77 }
78 snd_count[m_processor] = 0;
79
80 // The number of locally-owned nodes on this processor is 'position'
81 *locally_owned_count = position;
82
83 MPI_Allgather(locally_owned_count, 1, MPI_LONG_LONG_INT, Data(rcv_count), 1, MPI_LONG_LONG_INT,
84 comm_);
85 m_decomposition.show_progress("\tAllgather finished");
86
87 // Determine the offset of the nodes on this processor. The offset is the
88 // total number of locally-owned nodes on all processors prior to this processor.
89 *processor_offset = 0;
90 for (int i = 0; i < m_processor; i++) {
91 *processor_offset += rcv_count[i];
92 }
93
94 for (auto &i : global_implicit_map) {
95 i += *processor_offset + 1;
96 }
97
98 // Now, tell the other processors how many nodes I will be sending
99 // them (Nodes they own that I share with them)
100 MPI_Alltoall(Data(snd_count), 1, MPI_LONG_LONG_INT, Data(rcv_count), 1, MPI_LONG_LONG_INT,
101 comm_);
102 m_decomposition.show_progress("\tCommunication 1 finished");
103
104 std::vector<int64_t> snd_offset(snd_count);
105 Ioss::Utils::generate_index(snd_offset);
106 std::vector<int64_t> snd_list(*snd_offset.rbegin() + *snd_count.rbegin());
107
108 {
109 std::vector<int64_t> tmp_disp(snd_offset);
110 // Now create the list of nodes to send...
111 for (size_t i = 0; i < global_implicit_map.size(); i++) {
112 if (owning_proc[i] != m_processor) {
113 int64_t global_id = node_map.map()[i + 1];
114 snd_list[tmp_disp[owning_proc[i]]++] = global_id;
115 }
116 }
117 }
118
119 std::vector<int64_t> rcv_offset(rcv_count);
120 Ioss::Utils::generate_index(rcv_offset);
121 std::vector<int64_t> rcv_list(*rcv_offset.rbegin() + *rcv_count.rbegin());
122
123 Ioss::MY_Alltoallv(snd_list, snd_count, snd_offset, rcv_list, rcv_count, rcv_offset, comm_);
124 m_decomposition.show_progress("\tCommunication 2 finished");
125
126 // Iterate rcv_list and convert global ids to the global-implicit position...
127 for (auto &i : rcv_list) {
128 int64_t local_id = node_map.global_to_local(i) - 1;
129 int64_t rcv_position = global_implicit_map[local_id];
130 i = rcv_position;
131 }
132
133 // Send the data back now...
134 Ioss::MY_Alltoallv(rcv_list, rcv_count, rcv_offset, snd_list, snd_count, snd_offset, comm_);
135 m_decomposition.show_progress("\tCommunication 3 finished");
136
137 // Fill in the remaining portions of the global_implicit_map...
138 std::vector<int64_t> tmp_disp(snd_offset);
139 for (size_t i = 0; i < global_implicit_map.size(); i++) {
140 if (owning_proc[i] != m_processor) {
141 int64_t implicit = snd_list[tmp_disp[owning_proc[i]]++];
142 global_implicit_map[i] = implicit;
143 }
144 }
145 }
146 } // namespace Ioexnl
147 #else
148 IOSS_MAYBE_UNUSED const char ioss_exodus_decomposition_data_unused_symbol_dummy = '\0';
149 #endif