Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/perfNgpFieldStateRotation.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 #include <stk_util/stk_config.h>
37 #include <stk_util/parallel/Parallel.hpp>
38 #include <stk_mesh/base/MetaData.hpp>
39 #include <stk_mesh/base/MeshBuilder.hpp>
40 #include <stk_mesh/base/BulkData.hpp>
41 #include <stk_mesh/base/NgpFieldBLAS.hpp>
42 #include <stk_mesh/base/Field.hpp>
43 #include <stk_mesh/base/Entity.hpp>
44 #include <stk_io/FillMesh.hpp>
45 #include <stk_unit_test_utils/timer.hpp>
46
47 namespace
48 {
49
50 TEST(StkNgpField, multiStateRotation)
51 {
52 stk::ParallelMachine comm = stk::parallel_machine_world();
53 if (stk::parallel_machine_size(comm) > 1) { GTEST_SKIP(); }
54
55 const unsigned NUM_RUNS = 5;
56 const unsigned NUM_ITERS = 3000;
57 std::string meshSpec = "generated:80x80x80";
58
59 std::cout << "Using mesh-spec: " << meshSpec << std::endl;
60
61 stk::unit_test_util::BatchTimer batchTimer(comm);
62
63 batchTimer.initialize_batch_timer();
64
65 std::unique_ptr<stk::mesh::BulkData> bulkPtr = stk::mesh::MeshBuilder(comm)
66 .set_aura_option(stk::mesh::BulkData::NO_AUTO_AURA)
67 .set_spatial_dimension(3)
68 .create();
69
70 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
71 const int numFieldStates = 3;
72 stk::mesh::Field<double>& tensorField1 = meta.declare_field<double>(stk::topology::ELEM_RANK, "tensorField1", numFieldStates);
73 stk::mesh::Field<double>& tensorField2 = meta.declare_field<double>(stk::topology::ELEM_RANK, "tensorField2", numFieldStates);
74 stk::mesh::Field<double>& vectorField1 = meta.declare_field<double>(stk::topology::ELEM_RANK, "vectorField1", numFieldStates);
75 stk::mesh::Field<double>& vectorField2 = meta.declare_field<double>(stk::topology::ELEM_RANK, "vectorField2", numFieldStates);
76 stk::mesh::put_field_on_mesh(tensorField1, meta.universal_part(), 9, nullptr);
77 stk::mesh::put_field_on_mesh(tensorField2, meta.universal_part(), 9, nullptr);
78 stk::mesh::put_field_on_mesh(vectorField1, meta.universal_part(), 3, nullptr);
79 stk::mesh::put_field_on_mesh(vectorField2, meta.universal_part(), 3, nullptr);
80
81 stk::io::fill_mesh(meshSpec, *bulkPtr);
82
83 Kokkos::Profiling::pushRegion("get_updated_ngp_mesh");
84 stk::mesh::NgpMesh& ngpMesh = stk::mesh::get_updated_ngp_mesh(*bulkPtr);
85 EXPECT_FALSE(ngpMesh.need_sync_to_host());
86 Kokkos::Profiling::popRegion();
87
88 Kokkos::Profiling::pushRegion("initialize fields");
89 stk::ngp::ExecSpace execSpace;
90 constexpr double initValue1 = 1.14;
91 constexpr double initValue2 = 3.14;
92 for(int s=0; s<numFieldStates; ++s) {
93 const stk::mesh::FieldState state = static_cast<stk::mesh::FieldState>(s);
94 stk::mesh::Field<double>& tensorField1_state = tensorField1.field_of_state(state);
95 stk::mesh::Field<double>& tensorField2_state = tensorField2.field_of_state(state);
96 stk::mesh::Field<double>& vectorField1_state = vectorField1.field_of_state(state);
97 stk::mesh::Field<double>& vectorField2_state = vectorField2.field_of_state(state);
98 stk::mesh::field_fill(initValue1, tensorField1_state, execSpace);
99 stk::mesh::field_fill(initValue2, tensorField2_state, execSpace);
100 stk::mesh::field_fill(initValue1, vectorField1_state, execSpace);
101 stk::mesh::field_fill(initValue2, vectorField2_state, execSpace);
102 }
103 Kokkos::Profiling::popRegion();
104
105 Kokkos::Profiling::pushRegion("multiStateRotation test");
106
107 for (unsigned j = 0; j < NUM_RUNS; j++) {
108
109 batchTimer.start_batch_timer();
110
111 for(unsigned i=0; i<NUM_ITERS; ++i) {
112 Kokkos::Profiling::pushRegion("field_copy");
113 if (i%2==0) {
114 stk::mesh::field_copy(tensorField1, tensorField2, execSpace);
115 stk::mesh::field_copy(vectorField1, vectorField2, execSpace);
116 }
117 else {
118 stk::mesh::field_copy(tensorField2, tensorField1, execSpace);
119 stk::mesh::field_copy(vectorField2, vectorField1, execSpace);
120 }
121 Kokkos::Profiling::popRegion();
122
123 Kokkos::Profiling::pushRegion("update_field_data_states");
124 const bool rotateNgpFieldViews = true;
125 bulkPtr->update_field_data_states(rotateNgpFieldViews);
126 Kokkos::Profiling::popRegion();
127 }
128
129 batchTimer.stop_batch_timer();
130 }
131
132 Kokkos::Profiling::popRegion();
133 batchTimer.print_batch_timing(NUM_ITERS);
134 }
135
136 }