Debian Codegraph @

packages/stk/stk_performance_tests/stk_search/SurfaceToSurface.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 <gtest/gtest.h>
36
37 #include <stk_mesh/base/MetaData.hpp>
38 #include <stk_mesh/base/BulkData.hpp>
39 #include <stk_mesh/base/MeshBuilder.hpp>
40 #include <stk_util/parallel/Parallel.hpp>
41 #include <stk_io/FillMesh.hpp>
42 #include <stk_search/LocalCoarseSearch.hpp>
43 #include <stk_search/CoarseSearch.hpp>
44 #include <stk_unit_test_utils/Search_UnitTestUtils.hpp>
45 #include <stk_unit_test_utils/MeshUtilsForBoundingVolumes.hpp>
46 #include <stk_unit_test_utils/timer.hpp>
47 #include "stk_search/SearchMethod.hpp"
48
49 namespace {
50
51 std::string get_parallel_filename(const std::string& baseName, MPI_Comm comm)
52 {
53 const int nProcs = stk::parallel_machine_size(comm);
54 const int pRank = stk::parallel_machine_rank(comm);
55
56 return baseName + "_" + std::to_string(nProcs) + "." + std::to_string(pRank);
57 }
58
59 template <typename BoxVectorType>
60 void sequentially_number_all_boxes(BoxVectorType & boxVector, MPI_Comm comm)
61 {
62 const int nProcs = stk::parallel_machine_size(comm);
63 const int pRank = stk::parallel_machine_rank(comm);
64 std::vector<unsigned long> allNumBoxes(nProcs, 0);
65 const unsigned long localNumBoxes = boxVector.size();
66
67 MPI_Allgather(&localNumBoxes, 1, MPI_UNSIGNED_LONG, allNumBoxes.data(), 1, MPI_UNSIGNED_LONG, comm);
68
69 unsigned long id = 0;
70 for (int proc = 0; proc < pRank; ++proc) {
71 id += allNumBoxes[proc];
72 }
73
74 for (auto & [box, ident] : boxVector) {
75 ident.set_proc(pRank);
76 ident.set_id(id++);
77 }
78 }
79
80 template <typename BoxVectorType>
81 BoxVectorType read_boxes_from_file(const std::string& baseName, MPI_Comm comm)
82 {
83 const std::string fileName = get_parallel_filename(baseName, comm);
84 std::ifstream infile(fileName);
85 STK_ThrowRequireMsg(infile.good(), "Unable to open file " + fileName);
86
87 BoxVectorType boxVector;
88 std::string line;
89 while (std::getline(infile, line)) {
90 if (line.size() == 0) continue;
91 if (line[0] == '#') continue;
92 std::istringstream iss(line);
93 boxVector.emplace_back();
94 auto & [box, ident] = boxVector.back();
95 iss >> box;
96 }
97
98 sequentially_number_all_boxes(boxVector, comm);
99
100 return boxVector;
101 }
102
103 template<typename BoxVectorType>
104 void run_imported_surface_to_surface_test(const std::string& boxFileBaseName,
105 const int numIterations,
106 stk::search::SearchMethod searchMethod,
107 bool enforceSearchResultSymmetry = true)
108 {
109 MPI_Comm comm = MPI_COMM_WORLD;
110 const unsigned NUM_RUNS = 5;
111 stk::unit_test_util::BatchTimer batchTimer(comm);
112 batchTimer.initialize_batch_timer();
113
114 BoxVectorType diceBoxes = read_boxes_from_file<BoxVectorType>(boxFileBaseName + ".txt_dice", comm);
115 BoxVectorType toolBoxes = read_boxes_from_file<BoxVectorType>(boxFileBaseName + ".txt_tool", comm);
116
117 for (unsigned run = 0; run < NUM_RUNS; ++run) {
118
119 batchTimer.start_batch_timer();
120 for (int i = 0; i < numIterations; ++i) {
121 SearchResults searchResults;
122 stk::search::coarse_search(diceBoxes, toolBoxes, searchMethod, comm, searchResults, enforceSearchResultSymmetry);
123 }
124 batchTimer.stop_batch_timer();
125 }
126
127 batchTimer.print_batch_timing(numIterations);
128 }
129
130 template<typename BoxIdentProcType>
131 void run_imported_surface_to_surface_test_with_views(const std::string& boxFileBaseName,
132 const int numIterations,
133 stk::search::SearchMethod searchMethod,
134 bool enforceSearchResultSymmetry = true)
135 {
136 using BoxType = typename BoxIdentProcType::box_type;
137 using IdentProcType = typename BoxIdentProcType::ident_proc_type;
138 using BoxVectorType = typename std::vector<std::pair<BoxType, IdentProcType>>;
139 using ExecSpace = Kokkos::DefaultExecutionSpace;
140
141 MPI_Comm comm = MPI_COMM_WORLD;
142 const unsigned NUM_RUNS = 5;
143 stk::unit_test_util::BatchTimer batchTimer(comm);
144 batchTimer.initialize_batch_timer();
145
146 BoxVectorType diceBoxesVector = read_boxes_from_file<BoxVectorType>(boxFileBaseName + ".txt_dice", comm);
147 BoxVectorType toolBoxesVector = read_boxes_from_file<BoxVectorType>(boxFileBaseName + ".txt_tool", comm);
148
149 Kokkos::View<BoxIdentProcType *, ExecSpace> diceBoxes("diceBoxes", diceBoxesVector.size());
150 Kokkos::View<BoxIdentProcType *, ExecSpace> toolBoxes("toolBoxes", toolBoxesVector.size());
151 auto diceBoxesHost = Kokkos::create_mirror_view(diceBoxes);
152 auto toolBoxesHost = Kokkos::create_mirror_view(toolBoxes);
153
154 for (unsigned i = 0; i < diceBoxesVector.size(); i++) {
155 auto boxIdentProcPair = diceBoxesVector[i];
156 BoxIdentProcType domainBoxIdentProc{boxIdentProcPair.first, boxIdentProcPair.second};
157 diceBoxesHost(i) = domainBoxIdentProc;
158 }
159
160 for (unsigned i = 0; i < toolBoxesVector.size(); i++) {
161 auto boxIdentProcPair = toolBoxesVector[i];
162 BoxIdentProcType rangeBoxIdentProc{boxIdentProcPair.first, boxIdentProcPair.second};
163 toolBoxesHost(i) = rangeBoxIdentProc;
164 }
165
166 Kokkos::deep_copy(diceBoxes, diceBoxesHost);
167 Kokkos::deep_copy(toolBoxes, toolBoxesHost);
168
169 for (unsigned run = 0; run < NUM_RUNS; ++run) {
170 batchTimer.start_batch_timer();
171 for (int i = 0; i < numIterations; ++i) {
172 Kokkos::View<IdentProcIntersection*, ExecSpace> searchResults;
173 stk::search::coarse_search(diceBoxes, toolBoxes, searchMethod, comm, searchResults,
174 ExecSpace{}, enforceSearchResultSymmetry);
175 }
176 batchTimer.stop_batch_timer();
177 }
178
179 batchTimer.print_batch_timing(numIterations);
180 }
181
182 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_KDTREE)
183 {
184 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
185 if (boxFileBaseName == "none-specified") GTEST_SKIP();
186 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
187
188 const int numIterations = 4;
189 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
190 }
191
192 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_MORTON_LBVH)
193 {
194 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
195 if (boxFileBaseName == "none-specified") GTEST_SKIP();
196 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
197
198 const int numIterations = 4;
199 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
200 }
201
202 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_ARBORX)
203 {
204 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
205 if (boxFileBaseName == "none-specified") GTEST_SKIP();
206 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
207
208 const int numIterations = 4;
209 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
210 }
211
212 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_with_views_MORTON_LBVH)
213 {
214 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
215 if (boxFileBaseName == "none-specified") GTEST_SKIP();
216 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
217
218 const int numIterations = 4;
219 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
220 }
221
222 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_with_views_ARBORX)
223 {
224 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
225 if (boxFileBaseName == "none-specified") GTEST_SKIP();
226 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
227
228 const int numIterations = 4;
229 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::ARBORX);
230 }
231
232
233 TEST(StkSearch_SurfaceToSurface, newtonCradle_floatBox_KDTREE)
234 {
235 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
236 if (boxFileBaseName == "none-specified") GTEST_SKIP();
237 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 16) GTEST_SKIP();
238
239 const int numIterations = 2000;
240 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
241 }
242
243 TEST(StkSearch_SurfaceToSurface, newtonCradle_floatBox_MORTON_LBVH)
244 {
245 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
246 if (boxFileBaseName == "none-specified") GTEST_SKIP();
247 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 16) GTEST_SKIP();
248
249 const int numIterations = 2000;
250 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
251 }
252
253 TEST(StkSearch_SurfaceToSurface, newtonCradle_floatBox_ARBORX)
254 {
255 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
256 if (boxFileBaseName == "none-specified") GTEST_SKIP();
257 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 16) GTEST_SKIP();
258
259 const int numIterations = 2000;
260 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
261 }
262
263 TEST(StkSearch_SurfaceToSurface, newtonCradle_floatBox_with_views_MORTON_LBVH)
264 {
265 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
266 if (boxFileBaseName == "none-specified") GTEST_SKIP();
267 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 16) GTEST_SKIP();
268
269 const int numIterations = 2000;
270 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
271 }
272
273 TEST(StkSearch_SurfaceToSurface, newtonCradle_floatBox_with_views_ARBORX)
274 {
275 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
276 if (boxFileBaseName == "none-specified") GTEST_SKIP();
277 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 16) GTEST_SKIP();
278
279 const int numIterations = 2000;
280 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::ARBORX);
281 }
282
283
284 TEST(StkSearch_SurfaceToSurface, b61NoseCrush_floatBox_KDTREE)
285 {
286 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
287 if (boxFileBaseName == "none-specified") GTEST_SKIP();
288 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
289
290 const int numIterations = 200;
291 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
292 }
293
294 TEST(StkSearch_SurfaceToSurface, b61NoseCrush_floatBox_MORTON_LBVH)
295 {
296 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
297 if (boxFileBaseName == "none-specified") GTEST_SKIP();
298 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
299
300 const int numIterations = 200;
301 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
302 }
303
304 TEST(StkSearch_SurfaceToSurface, b61NoseCrush_floatBox_ARBORX)
305 {
306 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
307 if (boxFileBaseName == "none-specified") GTEST_SKIP();
308 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
309
310 const int numIterations = 200;
311 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
312 }
313
314 TEST(StkSearch_SurfaceToSurface, b61NoseCrush_floatBox_with_views_MORTON_LBVH)
315 {
316 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
317 if (boxFileBaseName == "none-specified") GTEST_SKIP();
318 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
319
320 const int numIterations = 200;
321 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
322 }
323
324 TEST(StkSearch_SurfaceToSurface, b61NoseCrush_floatBox_with_views_ARBORX)
325 {
326 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
327 if (boxFileBaseName == "none-specified") GTEST_SKIP();
328 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
329
330 const int numIterations = 200;
331 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::ARBORX);
332 }
333
334
335 TEST(StkSearch_SurfaceToSurface, coneCrush_floatBox_KDTREE)
336 {
337 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
338 if (boxFileBaseName == "none-specified") GTEST_SKIP();
339 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
340
341 const int numIterations = 200;
342 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
343 }
344
345 TEST(StkSearch_SurfaceToSurface, coneCrush_floatBox_MORTON_LBVH)
346 {
347 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
348 if (boxFileBaseName == "none-specified") GTEST_SKIP();
349 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
350
351 const int numIterations = 200;
352 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
353 }
354
355 TEST(StkSearch_SurfaceToSurface, coneCrush_floatBox_ARBORX)
356 {
357 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
358 if (boxFileBaseName == "none-specified") GTEST_SKIP();
359 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
360
361 const int numIterations = 200;
362 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
363 }
364
365 TEST(StkSearch_SurfaceToSurface, coneCrush_floatBox_with_views_MORTON_LBVH)
366 {
367 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
368 if (boxFileBaseName == "none-specified") GTEST_SKIP();
369 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
370
371 const int numIterations = 200;
372 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
373 }
374
375 TEST(StkSearch_SurfaceToSurface, coneCrush_floatBox_with_views_ARBORX)
376 {
377 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
378 if (boxFileBaseName == "none-specified") GTEST_SKIP();
379 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
380
381 const int numIterations = 200;
382 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::ARBORX);
383 }
384
385
386 TEST(StkSearch_SurfaceToSurface, jenga_floatBox_KDTREE)
387 {
388 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
389 if (boxFileBaseName == "none-specified") GTEST_SKIP();
390 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
391
392 const int numIterations = 500;
393 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
394 }
395
396 TEST(StkSearch_SurfaceToSurface, jenga_floatBox_MORTON_LBVH)
397 {
398 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
399 if (boxFileBaseName == "none-specified") GTEST_SKIP();
400 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
401
402 const int numIterations = 500;
403 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
404 }
405
406 TEST(StkSearch_SurfaceToSurface, jenga_floatBox_ARBORX)
407 {
408 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
409 if (boxFileBaseName == "none-specified") GTEST_SKIP();
410 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
411
412 const int numIterations = 500;
413 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
414 }
415
416 TEST(StkSearch_SurfaceToSurface, jenga_floatBox_with_views_MORTON_LBVH)
417 {
418 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
419 if (boxFileBaseName == "none-specified") GTEST_SKIP();
420 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
421
422 const int numIterations = 500;
423 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
424 }
425
426 TEST(StkSearch_SurfaceToSurface, jenga_floatBox_with_views_ARBORX)
427 {
428 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
429 if (boxFileBaseName == "none-specified") GTEST_SKIP();
430 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 32) GTEST_SKIP();
431
432 const int numIterations = 500;
433 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::ARBORX);
434 }
435
436
437 TEST(StkSearch_SurfaceToSurface, tractorTrailerCrash_floatBox_KDTREE)
438 {
439 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
440 if (boxFileBaseName == "none-specified") GTEST_SKIP();
441 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 128) GTEST_SKIP();
442
443 const int numIterations = 20;
444 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
445 }
446
447 TEST(StkSearch_SurfaceToSurface, tractorTrailerCrash_floatBox_MORTON_LBVH)
448 {
449 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
450 if (boxFileBaseName == "none-specified") GTEST_SKIP();
451 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 128) GTEST_SKIP();
452
453 const int numIterations = 20;
454 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
455 }
456
457 TEST(StkSearch_SurfaceToSurface, tractorTrailerCrash_floatBox_ARBORX)
458 {
459 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
460 if (boxFileBaseName == "none-specified") GTEST_SKIP();
461 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 128) GTEST_SKIP();
462
463 const int numIterations = 20;
464 run_imported_surface_to_surface_test<FloatBoxIdentProcVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
465 }
466
467 TEST(StkSearch_SurfaceToSurface, tractorTrailerCrash_floatBox_with_views_MORTON_LBVH)
468 {
469 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
470 if (boxFileBaseName == "none-specified") GTEST_SKIP();
471 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 128) GTEST_SKIP();
472
473 const int numIterations = 20;
474 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
475 }
476
477 TEST(StkSearch_SurfaceToSurface, tractorTrailerCrash_floatBox_with_views_ARBORX)
478 {
479 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
480 if (boxFileBaseName == "none-specified") GTEST_SKIP();
481 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 128) GTEST_SKIP();
482
483 const int numIterations = 20;
484 run_imported_surface_to_surface_test_with_views<FloatBoxIdentProc>(boxFileBaseName, numIterations, stk::search::ARBORX);
485 }
486
487 template <typename BoxVectorType>
488 BoxVectorType read_local_boxes_from_file_and_number(const std::string& baseName)
489 {
490 const std::string fileName = baseName + "_1.0";
491 std::ifstream infile(fileName);
492 STK_ThrowRequireMsg(infile.good(), "Unable to open file " + fileName);
493
494 BoxVectorType boxVector;
495 std::string line;
496 while (std::getline(infile, line)) {
497 if (line.size() == 0) continue;
498 if (line[0] == '#') continue;
499 std::istringstream iss(line);
500 boxVector.emplace_back();
501 auto & [box, ident] = boxVector.back();
502 iss >> box;
503 }
504
505 unsigned long id = 0;
506 for (auto & boxIdent : boxVector) {
507 boxIdent.second = id;
508 id++;
509 }
510
511 return boxVector;
512 }
513
514 template <typename BoxVectorType>
515 BoxVectorType read_local_boxes_from_file_and_number(const std::string& baseName, MPI_Comm comm)
516 {
517 const std::string fileName = get_parallel_filename(baseName, comm);
518 std::ifstream infile(fileName);
519 STK_ThrowRequireMsg(infile.good(), "Unable to open file " + fileName);
520
521 BoxVectorType boxVector;
522 std::string line;
523 while (std::getline(infile, line)) {
524 if (line.size() == 0) continue;
525 if (line[0] == '#') continue;
526 std::istringstream iss(line);
527 boxVector.emplace_back();
528 auto & [box, ident] = boxVector.back();
529 iss >> box;
530 }
531
532 unsigned long id = 0;
533 for (auto & boxIdent : boxVector) {
534 boxIdent.second = id;
535 id++;
536 }
537
538 return boxVector;
539 }
540
541 template<typename BoxVectorType>
542 void run_imported_surface_to_surface_test_local(const std::string& boxFileBaseName,
543 const int numIterations,
544 stk::search::SearchMethod searchMethod)
545 {
546 MPI_Comm comm = MPI_COMM_WORLD;
547 const unsigned NUM_RUNS = 5;
548 stk::unit_test_util::BatchTimer batchTimer(comm);
549 batchTimer.initialize_batch_timer();
550
551 BoxVectorType diceBoxes = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_dice");
552 BoxVectorType toolBoxes = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_tool");
553
554 for (unsigned run = 0; run < NUM_RUNS; ++run) {
555
556 batchTimer.start_batch_timer();
557 for (int i = 0; i < numIterations; ++i) {
558 LocalSearchResults searchResults;
559 stk::search::local_coarse_search(diceBoxes, toolBoxes, searchMethod, searchResults);
560 }
561 batchTimer.stop_batch_timer();
562 }
563
564 batchTimer.print_batch_timing(numIterations);
565 }
566
567 template<typename BoxIdentType>
568 void run_imported_surface_to_surface_test_local_with_views(const std::string& boxFileBaseName,
569 const int numIterations,
570 stk::search::SearchMethod searchMethod)
571 {
572 using BoxType = typename BoxIdentType::box_type;
573 using IdentType = typename BoxIdentType::second_type;
574 using BoxVectorType = typename std::vector<std::pair<BoxType, IdentType>>;
575 using ExecSpace = Kokkos::DefaultExecutionSpace;
576
577 MPI_Comm comm = MPI_COMM_WORLD;
578 const unsigned NUM_RUNS = 5;
579 stk::unit_test_util::BatchTimer batchTimer(comm);
580 batchTimer.initialize_batch_timer();
581
582 BoxVectorType diceBoxesVector = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_dice");
583 BoxVectorType toolBoxesVector = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_tool");
584
585 Kokkos::View<BoxIdentType *, ExecSpace> diceBoxes("diceBoxes", diceBoxesVector.size());
586 Kokkos::View<BoxIdentType *, ExecSpace> toolBoxes("toolBoxes", toolBoxesVector.size());
587 auto diceBoxesHost = Kokkos::create_mirror_view(diceBoxes);
588 auto toolBoxesHost = Kokkos::create_mirror_view(toolBoxes);
589
590 for (unsigned i = 0; i < diceBoxesVector.size(); i++) {
591 auto boxIdentPair = diceBoxesVector[i];
592 BoxIdentType domainBoxIdent{boxIdentPair.first, boxIdentPair.second};
593 diceBoxesHost(i) = domainBoxIdent;
594 }
595
596 for (unsigned i = 0; i < toolBoxesVector.size(); i++) {
597 auto boxIdentPair = toolBoxesVector[i];
598 BoxIdentType rangeBoxIdent{boxIdentPair.first, boxIdentPair.second};
599 toolBoxesHost(i) = rangeBoxIdent;
600 }
601
602 Kokkos::deep_copy(diceBoxes, diceBoxesHost);
603 Kokkos::deep_copy(toolBoxes, toolBoxesHost);
604
605 for (unsigned run = 0; run < NUM_RUNS; ++run) {
606
607 batchTimer.start_batch_timer();
608 for (int i = 0; i < numIterations; ++i) {
609 Kokkos::View<IdentIntersection*, ExecSpace> searchResults;
610 stk::search::local_coarse_search(diceBoxes, toolBoxes, searchMethod, searchResults, ExecSpace{});
611 }
612 batchTimer.stop_batch_timer();
613 }
614
615 batchTimer.print_batch_timing(numIterations);
616 }
617
618 template<typename BoxIdentType>
619 void run_imported_surface_to_surface_test_pll_local_with_views(const std::string& boxFileBaseName,
620 const int numIterations,
621 stk::search::SearchMethod searchMethod)
622 {
623 using BoxType = typename BoxIdentType::box_type;
624 using IdentType = typename BoxIdentType::second_type;
625 using BoxVectorType = typename std::vector<std::pair<BoxType, IdentType>>;
626 using ExecSpace = Kokkos::DefaultExecutionSpace;
627
628 MPI_Comm comm = MPI_COMM_WORLD;
629 const unsigned NUM_RUNS = 5;
630 stk::unit_test_util::BatchTimer batchTimer(comm);
631 batchTimer.initialize_batch_timer();
632
633 BoxVectorType diceBoxesVector = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_dice", comm);
634 BoxVectorType toolBoxesVector = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_tool", comm);
635
636 Kokkos::View<BoxIdentType *, ExecSpace> diceBoxes("diceBoxes", diceBoxesVector.size());
637 Kokkos::View<BoxIdentType *, ExecSpace> toolBoxes("diceBoxes", toolBoxesVector.size());
638 auto diceBoxesHost = Kokkos::create_mirror_view(diceBoxes);
639 auto toolBoxesHost = Kokkos::create_mirror_view(toolBoxes);
640
641 for (unsigned i = 0; i < diceBoxesVector.size(); i++) {
642 auto boxIdentPair = diceBoxesVector[i];
643 BoxIdentType domainBoxIdent{boxIdentPair.first, boxIdentPair.second};
644 diceBoxesHost(i) = domainBoxIdent;
645 }
646
647 for (unsigned i = 0; i < toolBoxesVector.size(); i++) {
648 auto boxIdentPair = toolBoxesVector[i];
649 BoxIdentType rangeBoxIdent{boxIdentPair.first, boxIdentPair.second};
650 toolBoxesHost(i) = rangeBoxIdent;
651 }
652
653 Kokkos::deep_copy(diceBoxes, diceBoxesHost);
654 Kokkos::deep_copy(toolBoxes, toolBoxesHost);
655
656 std::shared_ptr<stk::search::SearchData> searchData;
657 for (unsigned run = 0; run < NUM_RUNS; ++run) {
658
659 batchTimer.start_batch_timer();
660 for (int i = 0; i < numIterations; ++i) {
661 Kokkos::View<IdentIntersection*, ExecSpace> searchResults;
662 constexpr bool sortResults = false;
663 searchData = stk::search::local_coarse_search(diceBoxes, toolBoxes, searchMethod, searchResults, ExecSpace{}, sortResults, searchData);
664 }
665 batchTimer.stop_batch_timer();
666 }
667
668 batchTimer.print_batch_timing(numIterations);
669 }
670
671 using MemSpace = stk::ngp::ExecSpace::memory_space;
672
673 template<typename BoxIdentType>
674 void run_imported_surface_to_surface_test_local_with_views_rawArborX(const std::string& boxFileBaseName,
675 const int numIterations,
676 stk::search::SearchMethod /*searchMethod*/)
677 {
678 using BoxType = typename BoxIdentType::box_type;
679 using IdentType = typename BoxIdentType::second_type;
680 using BoxVectorType = typename std::vector<std::pair<BoxType, IdentType>>;
681 using ExecSpace = Kokkos::DefaultExecutionSpace;
682
683 MPI_Comm comm = MPI_COMM_WORLD;
684 const unsigned NUM_RUNS = 5;
685 stk::unit_test_util::BatchTimer batchTimer(comm);
686 batchTimer.initialize_batch_timer();
687
688 BoxVectorType diceBoxesVector = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_dice", comm);
689 BoxVectorType toolBoxesVector = read_local_boxes_from_file_and_number<BoxVectorType>(boxFileBaseName + ".txt_tool", comm);
690
691 Kokkos::View<ArborX::Box *, MemSpace> diceBoxes("diceBoxes", diceBoxesVector.size());
692 Kokkos::View<ArborX::Box *, MemSpace> toolBoxes("diceBoxes", toolBoxesVector.size());
693 auto diceBoxesHost = Kokkos::create_mirror_view(diceBoxes);
694 auto toolBoxesHost = Kokkos::create_mirror_view(toolBoxes);
695
696 for (unsigned i = 0; i < diceBoxesVector.size(); i++) {
697 auto boxIdentPair = diceBoxesVector[i];
698 auto stkMinCorner = boxIdentPair.first.min_corner();
699 auto stkMaxCorner = boxIdentPair.first.max_corner();
700 ArborX::Point min_point(stkMinCorner[0], stkMinCorner[1], stkMinCorner[2]);
701 ArborX::Point max_point(stkMaxCorner[0], stkMaxCorner[1], stkMaxCorner[2]);
702 diceBoxesHost(i) = {min_point, max_point};
703 }
704
705 for (unsigned i = 0; i < toolBoxesVector.size(); i++) {
706 auto boxIdentPair = toolBoxesVector[i];
707 auto stkMinCorner = boxIdentPair.first.min_corner();
708 auto stkMaxCorner = boxIdentPair.first.max_corner();
709 ArborX::Point min_point(stkMinCorner[0], stkMinCorner[1], stkMinCorner[2]);
710 ArborX::Point max_point(stkMaxCorner[0], stkMaxCorner[1], stkMaxCorner[2]);
711 toolBoxesHost(i) = {min_point, max_point};
712 }
713
714 Kokkos::deep_copy(diceBoxes, diceBoxesHost);
715 Kokkos::deep_copy(toolBoxes, toolBoxesHost);
716
717 for (unsigned run = 0; run < NUM_RUNS; ++run) {
718 batchTimer.start_batch_timer();
719 ExecSpace execSpace{};
720 for (int iter = 0; iter < numIterations; ++iter) {
721 Kokkos::Profiling::pushRegion("Raw ArborX");
722 Kokkos::View<int *, MemSpace> indices("ArborX::indices", 0);
723 Kokkos::View<int *, MemSpace> offsets("ArborX::offsets", 0);
724
725 ArborX::BVH<MemSpace> bvh{execSpace, toolBoxes};
726 const int numQueries = diceBoxes.extent(0);
727 Kokkos::View<ArborX::Intersects<ArborX::Box> *, MemSpace> queries(Kokkos::ViewAllocateWithoutInitializing("queries"), numQueries);
728
729 Kokkos::parallel_for("setup_queries", Kokkos::RangePolicy<ExecSpace>(0, numQueries),
730 KOKKOS_LAMBDA(int i) { queries(i) = ArborX::intersects(diceBoxes(i)); });
731 Kokkos::fence();
732 bvh.query(execSpace, queries, indices, offsets);
733 Kokkos::Profiling::popRegion();
734 }
735 batchTimer.stop_batch_timer();
736 }
737
738 batchTimer.print_batch_timing(numIterations);
739 }
740
741 TEST(StkSearch_SurfaceToSurface, a001_intent_strong_link_floatBox_local_with_views_rawARBORX)
742 {
743 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
744 if (boxFileBaseName == "none-specified") GTEST_SKIP();
745 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 40) GTEST_SKIP();
746
747 const int numIterations = 20;
748 run_imported_surface_to_surface_test_local_with_views_rawArborX<FloatBoxIdent>(boxFileBaseName, numIterations, stk::search::ARBORX);
749 }
750
751 TEST(StkSearch_SurfaceToSurface, a001_intent_strong_link_floatBox_local_with_views_ARBORX)
752 {
753 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
754 if (boxFileBaseName == "none-specified") GTEST_SKIP();
755 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 40) GTEST_SKIP();
756
757 const int numIterations = 20;
758 run_imported_surface_to_surface_test_pll_local_with_views<FloatBoxIdent>(boxFileBaseName, numIterations, stk::search::ARBORX);
759 }
760
761 TEST(StkSearch_SurfaceToSurface, a001_intent_strong_link_floatBox_local_with_views_MORTON_LBVH)
762 {
763 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
764 if (boxFileBaseName == "none-specified") GTEST_SKIP();
765 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 40) GTEST_SKIP();
766
767 const int numIterations = 20;
768 run_imported_surface_to_surface_test_pll_local_with_views<FloatBoxIdent>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
769 }
770
771 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_local_KDTREE)
772 {
773 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
774 if (boxFileBaseName == "none-specified") GTEST_SKIP();
775 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
776
777 const int numIterations = 4;
778 run_imported_surface_to_surface_test_local<FloatBoxIdentVector>(boxFileBaseName, numIterations, stk::search::KDTREE);
779 }
780
781 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_local_MORTON_LBVH)
782 {
783 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
784 if (boxFileBaseName == "none-specified") GTEST_SKIP();
785 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
786
787 const int numIterations = 4;
788 run_imported_surface_to_surface_test_local<FloatBoxIdentVector>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
789 }
790
791 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_local_ARBORX)
792 {
793 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
794 if (boxFileBaseName == "none-specified") GTEST_SKIP();
795 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
796
797 const int numIterations = 4;
798 run_imported_surface_to_surface_test_local<FloatBoxIdentVector>(boxFileBaseName, numIterations, stk::search::ARBORX);
799 }
800
801 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_local_with_views_MORTON_LBVH)
802 {
803 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
804 if (boxFileBaseName == "none-specified") GTEST_SKIP();
805 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
806
807 const int numIterations = 4;
808 run_imported_surface_to_surface_test_local_with_views<FloatBoxIdent>(boxFileBaseName, numIterations, stk::search::MORTON_LBVH);
809 }
810
811 TEST(StkSearch_SurfaceToSurface, ecsl_floatBox_local_with_views_ARBORX)
812 {
813 std::string boxFileBaseName = stk::unit_test_util::get_option("-m", "none-specified");
814 if (boxFileBaseName == "none-specified") GTEST_SKIP();
815 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) GTEST_SKIP();
816
817 const int numIterations = 4;
818 run_imported_surface_to_surface_test_local_with_views<FloatBoxIdent>(boxFileBaseName, numIterations, stk::search::ARBORX);
819 }
820
821 } // namespace
822