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