Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/HexSTKfaces.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 <sstream>
36 #include <gtest/gtest.h>
37
38 #include <stk_util/environment/CPUTime.hpp>
39 #include <stk_util/environment/memory_util.hpp>
40 #include <stk_util/util/human_bytes.hpp>
41 #include <stk_util/environment/perf_util.hpp>
42
43 #include <stk_io/util/Gmesh_STKmesh_Fixture.hpp>
44 #include <stk_performance_tests/stk_mesh/calculate_centroid.hpp>
45
46 #include <stk_mesh/base/Relation.hpp>
47 #include <stk_mesh/base/Entity.hpp>
48 #include <stk_mesh/base/BulkData.hpp>
49 #include <stk_mesh/base/CreateFaces.hpp>
50 #include <stk_mesh/base/Comm.hpp>
51
52 namespace stk {
53 namespace performance_tests {
54
55 TEST(hex_faces, hex_faces)
56 {
57 //vector of mesh-dimensions holds the number of elements in each dimension.
58 //Hard-wired to 3. This test can run with spatial-dimension less than 3,
59 //(if generated-mesh can do that) but not greater than 3.
60 std::vector<int> mesh_dims(3);
61 int proc = 0;
62 MPI_Comm_rank(MPI_COMM_WORLD, &proc);
63 int numprocs = 1;
64 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
65
66 #ifndef NDEBUG
67 mesh_dims[0]=50; //num_elems_x
68 mesh_dims[1]=50; //num_elems_y
69 mesh_dims[2]=50; //num_elems_z
70 #else
71 mesh_dims[0]=75; //num_elems_x
72 mesh_dims[1]=75; //num_elems_y
73 mesh_dims[2]=75*numprocs; //num_elems_z
74 #endif
75
76 std::ostringstream oss;
77 oss << mesh_dims[0] << "x" << mesh_dims[1] << "x" << mesh_dims[2];
78
79 double start_time = stk::cpu_time();
80
81 size_t num_nodes = mesh_dims[0]+1;
82 num_nodes *= mesh_dims[1]+1;
83 num_nodes *= mesh_dims[2]+1;
84
85 //if num_nodes is greater than the int limit (2.1B) then we need to
86 //use the 64-bit api in the IO (which lies beneath the gmesh fixture).
87 bool use_64bit_IO_api = num_nodes > 2150000000;
88
89 stk::io::util::Gmesh_STKmesh_Fixture fixture(MPI_COMM_WORLD, oss.str(), use_64bit_IO_api);
90 fixture.commit();
91
92 double mesh_create_time = stk::cpu_time() - start_time;
93
94 start_time = stk::cpu_time();
95
96 stk::mesh::create_faces(fixture.getBulkData());
97
98 double create_faces_time = stk::cpu_time() - start_time;
99 double total_time = mesh_create_time + create_faces_time;
100
101 std::vector<size_t> mesh_counts;
102 stk::mesh::comm_mesh_counts(fixture.getBulkData(), mesh_counts);
103
104 if (proc == 0) {
105 std::cout<< "\nnum nodes: "<<mesh_counts[stk::topology::NODE_RANK]<<std::endl;
106 std::cout<< "num edges: "<<mesh_counts[stk::topology::EDGE_RANK]<<std::endl;
107 std::cout<< "num faces: "<<mesh_counts[stk::topology::FACE_RANK]<<std::endl;
108 std::cout<< "num elems: "<<mesh_counts[stk::topology::ELEMENT_RANK]<<std::endl;
109 }
110
111 size_t now=0, hwm=0;
112 stk::get_memory_usage(now,hwm);
113 size_t global_hwm=0;
114 MPI_Allreduce(&hwm, &global_hwm, 1, MPI_LONG_LONG, MPI_MAX, fixture.getBulkData().parallel());
115
116 if (proc == 0) {
117 static const int NUM_TIMERS = 3;
118 const double timers[NUM_TIMERS] = {mesh_create_time, create_faces_time, total_time};
119 const char* timer_names[NUM_TIMERS] = {"Create mesh", "Create faces", "Total time"};
120
121 stk::print_timers_and_memory(timer_names, timers, NUM_TIMERS);
122 std::cout<<"Global HWM: "<<stk::human_bytes(global_hwm)<<std::endl;
123 }
124
125 stk::parallel_print_time_without_output_and_hwm(MPI_COMM_WORLD, total_time);
126 }
127
128 TEST(hex_faces, minimal_hex_faces)
129 {
130 //vector of mesh-dimensions holds the number of elements in each dimension.
131 //Hard-wired to 3. This test can run with spatial-dimension less than 3,
132 //(if generated-mesh can do that) but not greater than 3.
133 std::vector<int> mesh_dims(3);
134 int proc = 0;
135 MPI_Comm_rank(MPI_COMM_WORLD, &proc);
136 int numprocs = 1;
137 MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
138
139 #ifndef NDEBUG
140 mesh_dims[0]=50; //num_elems_x
141 mesh_dims[1]=50; //num_elems_y
142 mesh_dims[2]=50; //num_elems_z
143 #else
144 mesh_dims[0]=100; //num_elems_x
145 mesh_dims[1]=100; //num_elems_y
146 mesh_dims[2]=100*numprocs; //num_elems_z
147 #endif
148
149 std::ostringstream oss;
150 oss << mesh_dims[0] << "x" << mesh_dims[1] << "x" << mesh_dims[2];
151
152 double start_time = stk::cpu_time();
153
154 size_t num_nodes = mesh_dims[0]+1;
155 num_nodes *= mesh_dims[1]+1;
156 num_nodes *= mesh_dims[2]+1;
157
158 //if num_nodes is greater than the int limit (2.1B) then we need to
159 //use the 64-bit api in the IO (which lies beneath the gmesh fixture).
160 bool use_64bit_IO_api = num_nodes > 2150000000;
161
162 stk::io::util::Gmesh_STKmesh_Fixture fixture(MPI_COMM_WORLD, oss.str(), use_64bit_IO_api);
163 fixture.commit();
164
165 double mesh_create_time = stk::cpu_time() - start_time;
166
167 start_time = stk::cpu_time();
168
169 stk::mesh::create_faces(fixture.getBulkData());
170
171 double create_faces_time = stk::cpu_time() - start_time;
172 double total_time = mesh_create_time + create_faces_time;
173
174 std::vector<size_t> mesh_counts;
175 stk::mesh::comm_mesh_counts(fixture.getBulkData(), mesh_counts);
176
177 if (proc == 0) {
178 std::cout<< "\nnum nodes: "<<mesh_counts[stk::topology::NODE_RANK]<<std::endl;
179 std::cout<< "num edges: "<<mesh_counts[stk::topology::EDGE_RANK]<<std::endl;
180 std::cout<< "num faces: "<<mesh_counts[stk::topology::FACE_RANK]<<std::endl;
181 std::cout<< "num elems: "<<mesh_counts[stk::topology::ELEMENT_RANK]<<std::endl;
182 }
183
184 size_t now=0, hwm=0;
185 stk::get_memory_usage(now,hwm);
186 size_t global_hwm=0;
187 MPI_Allreduce(&hwm, &global_hwm, 1, MPI_LONG_LONG, MPI_MAX, fixture.getBulkData().parallel());
188
189 if (proc == 0) {
190 static const int NUM_TIMERS = 3;
191 const double timers[NUM_TIMERS] = {mesh_create_time, create_faces_time, total_time};
192 const char* timer_names[NUM_TIMERS] = {"Create mesh", "Create faces", "Total time"};
193
194 stk::print_timers_and_memory(timer_names, timers, NUM_TIMERS);
195 std::cout<<"Global HWM: "<<stk::human_bytes(global_hwm)<<std::endl;
196 }
197
198 stk::parallel_print_time_without_output_and_hwm(MPI_COMM_WORLD, total_time);
199 }
200
201 } //namespace performance_tests
202 } //namespace stk