Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/NgpMeshUpdate.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include <string>
36 #include <gtest/gtest.h>
37 #include <stk_mesh/base/NgpMesh.hpp>
38 #include <stk_mesh/base/BulkData.hpp>
39 #include <stk_mesh/base/GetNgpMesh.hpp>
40 #include <stk_util/environment/WallTime.hpp>
41 #include <stk_util/environment/perf_util.hpp>
42 #include <stk_util/parallel/ParallelReduce.hpp>
43 #include <stk_unit_test_utils/MeshFixture.hpp>
44 #include <stk_unit_test_utils/getOption.h>
45 #include <stk_unit_test_utils/timer.hpp>
46
47 class NgpMeshChangeElementPartMembership : public stk::unit_test_util::MeshFixture
48 {
49 public:
50 NgpMeshChangeElementPartMembership()
51 : stk::unit_test_util::MeshFixture(),
52 newPartName("block2")
53 { }
54
55 void setup_host_mesh(stk::mesh::BulkData::AutomaticAuraOption auraOption)
56 {
57 #ifdef NDEBUG
58 numElements = 750000;
59 setup_mesh("generated:300x250x10", auraOption);
60 #else
61 numElements = 10000;
62 setup_mesh("generated:10x10x100", auraOption);
63 #endif
64 get_meta().declare_part(newPartName);
65 }
66
67 void change_element_part_membership(int cycle)
68 {
69 get_bulk().modification_begin();
70 get_bulk().change_entity_parts<stk::mesh::ConstPartVector>(get_element(cycle), {get_part()});
71 get_bulk().modification_end();
72 stk::mesh::get_updated_ngp_mesh(get_bulk());
73 }
74
75 void batch_change_element_part_membership(int cycle)
76 {
77 Kokkos::Profiling::pushRegion("BulkData::batch_change_entity_parts");
78 get_bulk().batch_change_entity_parts(stk::mesh::EntityVector{get_element(cycle)},
79 stk::mesh::PartVector{get_part()}, {});
80 Kokkos::Profiling::popRegion();
81
82 Kokkos::Profiling::pushRegion("get_updated_ngp_mesh");
83 stk::mesh::get_updated_ngp_mesh(get_bulk());
84 Kokkos::Profiling::popRegion();
85 }
86
87 private:
88 stk::mesh::Entity get_element(int cycle)
89 {
90 stk::mesh::EntityId firstLocalElemId = get_parallel_rank()*numElements/2 + 1;
91 stk::mesh::EntityId elemId = firstLocalElemId + cycle;
92 stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, elemId);
93 return elem;
94 }
95
96 stk::mesh::Part* get_part()
97 {
98 return get_meta().get_part(newPartName);
99 }
100
101 std::string newPartName;
102 unsigned numElements;
103 };
104
105 class NgpMeshCreateEntity : public stk::unit_test_util::MeshFixture
106 {
107 public:
108 NgpMeshCreateEntity()
109 : stk::unit_test_util::MeshFixture(),
110 numElements(1000000)
111 { }
112
113 void setup_host_mesh()
114 {
115 setup_mesh("generated:100x100x100", stk::mesh::BulkData::NO_AUTO_AURA);
116 }
117
118 void create_entity(int cycle)
119 {
120 get_bulk().modification_begin();
121 get_bulk().declare_element(get_new_entity_id(cycle));
122 get_bulk().modification_end();
123 stk::mesh::get_updated_ngp_mesh(get_bulk());
124 }
125
126 private:
127 stk::mesh::EntityId get_new_entity_id(int cycle)
128 {
129 return numElements + cycle + 1;
130 }
131
132 int numElements;
133 };
134
135 class NgpMeshGhosting : public stk::unit_test_util::MeshFixture
136 {
137 public:
138 NgpMeshGhosting()
139 : stk::unit_test_util::MeshFixture(),
140 ghostingName("testGhosting")
141 { }
142
143 protected:
144 void setup_host_mesh(stk::mesh::BulkData::AutomaticAuraOption auraOption)
145 {
146 #ifdef NDEBUG
147 numElements = 1000000;
148 setup_mesh("generated:400x250x10", auraOption);
149 #else
150 numElements = 10000;
151 setup_mesh("generated:10x10x100", auraOption);
152 #endif
153 get_bulk().modification_begin();
154 ghosting = &get_bulk().create_ghosting(ghostingName);
155 get_bulk().modification_end();
156 }
157
158 void ghost_element(int cycle)
159 {
160 get_bulk().modification_begin();
161 get_bulk().change_ghosting(*ghosting, element_to_ghost(cycle));
162 get_bulk().modification_end();
163 stk::mesh::get_updated_ngp_mesh(get_bulk());
164 }
165
166 private:
167 stk::mesh::EntityProcVec element_to_ghost(int cycle)
168 {
169 stk::mesh::EntityId firstLocalElemId = get_parallel_rank()*numElements/2 + 1;
170 stk::mesh::EntityId elemId = firstLocalElemId + cycle;
171 stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, elemId);
172 int ghostRank = 1 - get_parallel_rank();
173 return {{elem, ghostRank}};
174 }
175
176 int numElements;
177 std::string ghostingName;
178 stk::mesh::Ghosting* ghosting;
179 };
180
181 TEST_F( NgpMeshChangeElementPartMembership, Timing )
182 {
183 if (get_parallel_size() != 1) { GTEST_SKIP(); }
184
185 const unsigned NUM_RUNS = 5;
186 const int NUM_ITERS = 200;
187
188 stk::unit_test_util::BatchTimer batchTimer(get_comm());
189 batchTimer.initialize_batch_timer();
190 for (unsigned j = 0; j < NUM_RUNS; j++) {
191 setup_host_mesh(stk::mesh::BulkData::NO_AUTO_AURA);
192 batchTimer.start_batch_timer();
193
194 for (int i = 0; i < NUM_ITERS; i++) {
195 change_element_part_membership(i);
196 }
197 batchTimer.stop_batch_timer();
198 reset_mesh();
199 }
200 batchTimer.print_batch_timing(NUM_ITERS);
201 }
202
203 TEST_F( NgpMeshChangeElementPartMembership, TimingWithAura )
204 {
205 if (get_parallel_size() != 2) { GTEST_SKIP(); }
206
207 const unsigned NUM_RUNS = 5;
208 const int NUM_ITERS = 50;
209
210 stk::parallel_machine_barrier(get_comm());
211
212 stk::unit_test_util::BatchTimer batchTimer(get_comm());
213 batchTimer.initialize_batch_timer();
214 for (unsigned j = 0; j < NUM_RUNS; j++) {
215 setup_host_mesh(stk::mesh::BulkData::AUTO_AURA);
216 batchTimer.start_batch_timer();
217
218 for (int i = 0; i < NUM_ITERS; i++) {
219 change_element_part_membership(i);
220 }
221 batchTimer.stop_batch_timer();
222 reset_mesh();
223 }
224 batchTimer.print_batch_timing(NUM_ITERS);
225 }
226
227 TEST_F( NgpMeshChangeElementPartMembership, TimingBatch )
228 {
229 if (get_parallel_size() != 1) { GTEST_SKIP(); }
230
231 const unsigned NUM_RUNS = 5;
232 const int NUM_ITERS = 200;
233
234 stk::unit_test_util::BatchTimer batchTimer(get_comm());
235 batchTimer.initialize_batch_timer();
236 for (unsigned j = 0; j < NUM_RUNS; j++) {
237 batchTimer.start_batch_timer();
238 setup_host_mesh(stk::mesh::BulkData::NO_AUTO_AURA);
239
240 Kokkos::Profiling::pushRegion("batch_change_element_part_membership");
241
242 for (int i = 0; i < NUM_ITERS; i++) {
243 batch_change_element_part_membership(i);
244 }
245
246 Kokkos::Profiling::popRegion();
247
248 batchTimer.stop_batch_timer();
249 reset_mesh();
250 }
251 batchTimer.print_batch_timing(NUM_ITERS);
252 }
253
254 TEST_F( NgpMeshCreateEntity, Timing )
255 {
256 if (get_parallel_size() != 1) return;
257
258 const unsigned NUM_RUNS = 5;
259 #ifdef STK_ENABLE_GPU
260 const int NUM_ITERS = 100;
261 #else
262 const int NUM_ITERS = 5000;
263 #endif
264 const int NUM_FAKE_ITERS = 5000;
265
266 stk::unit_test_util::BatchTimer batchTimer(get_comm());
267 batchTimer.initialize_batch_timer();
268 for (unsigned j = 0; j < NUM_RUNS; j++) {
269 setup_host_mesh();
270 batchTimer.start_batch_timer();
271
272 for (int i=0; i<NUM_ITERS; i++) {
273 create_entity(i);
274 }
275 batchTimer.stop_batch_timer();
276 reset_mesh();
277 }
278 batchTimer.print_batch_timing(NUM_FAKE_ITERS);
279 }
280
281 TEST_F( NgpMeshGhosting, Timing )
282 {
283 if (get_parallel_size() != 2) return;
284
285 std::string perfCheck = stk::unit_test_util::get_option("-perf_check", "PERF_CHECK");
286 #ifdef NDEBUG
287 const int NUM_INNER_ITERS = (perfCheck=="NO_PERF_CHECK" ? 1 : 100);
288 #else
289 const int NUM_INNER_ITERS = 1;
290 #endif
291
292 const unsigned NUM_RUNS = 5;
293 stk::unit_test_util::BatchTimer batchTimer(get_comm());
294 batchTimer.initialize_batch_timer();
295
296 for (unsigned j = 0; j < NUM_RUNS; j++) {
297 batchTimer.start_batch_timer();
298 setup_host_mesh(stk::mesh::BulkData::NO_AUTO_AURA);
299
300 for (int i = 0; i < NUM_INNER_ITERS; i++) {
301 ghost_element(i);
302 }
303
304 batchTimer.stop_batch_timer();
305 reset_mesh();
306 }
307 batchTimer.print_batch_timing(NUM_INNER_ITERS);
308 }
309
310 TEST_F( NgpMeshGhosting, TimingWithAura )
311 {
312 if (get_parallel_size() != 2) return;
313
314 #ifdef NDEBUG
315 const int NUM_INNER_ITERS = 50;
316 #else
317 const int NUM_INNER_ITERS = 1;
318 #endif
319
320 const unsigned NUM_RUNS = 5;
321 stk::unit_test_util::BatchTimer batchTimer(get_comm());
322 batchTimer.initialize_batch_timer();
323 for (unsigned j = 0; j < NUM_RUNS; j++) {
324 setup_host_mesh(stk::mesh::BulkData::AUTO_AURA);
325 batchTimer.start_batch_timer();
326
327 for (int i = 0; i < NUM_INNER_ITERS; i++) {
328 ghost_element(i);
329 }
330
331 batchTimer.stop_batch_timer();
332 reset_mesh();
333 }
334 batchTimer.print_batch_timing(NUM_INNER_ITERS);
335 }