| 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_unit_test_utils/stk_mesh_fixtures/TetFixture.hpp" // for TetFixture |
| 44 |
#include <stk_mesh/base/BulkData.hpp> |
| 45 |
#include <stk_mesh/base/Comm.hpp> |
| 46 |
#include <stk_mesh/base/CreateFaces.hpp> |
| 47 |
|
| 48 |
namespace stk { |
| 49 |
namespace performance_tests { |
| 50 |
|
| 51 |
TEST(tet_faces, tet_faces) |
| 52 |
{ |
| 53 |
//vector of mesh-dimensions holds the number of elements in each dimension. |
| 54 |
//Hard-wired to 3. This test can run with spatial-dimension less than 3, |
| 55 |
//(if generated-mesh can do that) but not greater than 3. |
| 56 |
std::vector<int> mesh_dims(3); |
| 57 |
int proc = 0; |
| 58 |
MPI_Comm_rank(MPI_COMM_WORLD, &proc); |
| 59 |
int numprocs = 1; |
| 60 |
MPI_Comm_size(MPI_COMM_WORLD, &numprocs); |
| 61 |
|
| 62 |
#ifndef NDEBUG |
| 63 |
mesh_dims[0]=20; //num_elems_x |
| 64 |
mesh_dims[1]=20; //num_elems_y |
| 65 |
mesh_dims[2]=20; //num_elems_z |
| 66 |
#else |
| 67 |
mesh_dims[0]=50; //num_elems_x |
| 68 |
mesh_dims[1]=50; //num_elems_y |
| 69 |
mesh_dims[2]=50*numprocs; //num_elems_z |
| 70 |
#endif |
| 71 |
|
| 72 |
std::ostringstream oss; |
| 73 |
oss << mesh_dims[0] << "x" << mesh_dims[1] << "x" << mesh_dims[2]; |
| 74 |
|
| 75 |
double start_time = stk::cpu_time(); |
| 76 |
|
| 77 |
stk::mesh::fixtures::TetFixture fixture( MPI_COMM_WORLD, mesh_dims[0], mesh_dims[1], mesh_dims[2]); |
| 78 |
fixture.m_meta.commit(); |
| 79 |
fixture.generate_mesh(); |
| 80 |
|
| 81 |
double mesh_create_time = stk::cpu_time() - start_time; |
| 82 |
|
| 83 |
start_time = stk::cpu_time(); |
| 84 |
|
| 85 |
stk::mesh::create_faces(fixture.m_bulk_data); |
| 86 |
|
| 87 |
double create_faces_time = stk::cpu_time() - start_time; |
| 88 |
double total_time = mesh_create_time + create_faces_time; |
| 89 |
|
| 90 |
std::vector<size_t> mesh_counts; |
| 91 |
stk::mesh::comm_mesh_counts(fixture.m_bulk_data, mesh_counts); |
| 92 |
|
| 93 |
if (proc == 0) { |
| 94 |
std::cout<< "\nnum nodes: "<<mesh_counts[stk::topology::NODE_RANK]<<std::endl; |
| 95 |
std::cout<< "num edges: "<<mesh_counts[stk::topology::EDGE_RANK]<<std::endl; |
| 96 |
std::cout<< "num faces: "<<mesh_counts[stk::topology::FACE_RANK]<<std::endl; |
| 97 |
std::cout<< "num elems: "<<mesh_counts[stk::topology::ELEMENT_RANK]<<std::endl; |
| 98 |
} |
| 99 |
|
| 100 |
size_t now=0, hwm=0; |
| 101 |
stk::get_memory_usage(now,hwm); |
| 102 |
size_t global_hwm=0; |
| 103 |
MPI_Allreduce(&hwm, &global_hwm, 1, MPI_LONG_LONG, MPI_MAX, fixture.m_bulk_data.parallel()); |
| 104 |
|
| 105 |
if (proc == 0) { |
| 106 |
static const int NUM_TIMERS = 3; |
| 107 |
const double timers[NUM_TIMERS] = {mesh_create_time, create_faces_time, total_time}; |
| 108 |
const char* timer_names[NUM_TIMERS] = {"Create mesh", "Create faces", "Total time"}; |
| 109 |
|
| 110 |
stk::print_timers_and_memory(timer_names, timers, NUM_TIMERS); |
| 111 |
std::cout<<"Global HWM: "<<stk::human_bytes(global_hwm)<<std::endl; |
| 112 |
} |
| 113 |
|
| 114 |
stk::parallel_print_time_without_output_and_hwm(MPI_COMM_WORLD, total_time); |
| 115 |
} |
| 116 |
|
| 117 |
TEST(tet_faces, minimal_tet_faces) |
| 118 |
{ |
| 119 |
//vector of mesh-dimensions holds the number of elements in each dimension. |
| 120 |
//Hard-wired to 3. This test can run with spatial-dimension less than 3, |
| 121 |
//(if generated-mesh can do that) but not greater than 3. |
| 122 |
std::vector<int> mesh_dims(3); |
| 123 |
int proc = 0; |
| 124 |
MPI_Comm_rank(MPI_COMM_WORLD, &proc); |
| 125 |
int numprocs = 1; |
| 126 |
MPI_Comm_size(MPI_COMM_WORLD, &numprocs); |
| 127 |
|
| 128 |
#ifndef NDEBUG |
| 129 |
mesh_dims[0]=50; //num_elems_x |
| 130 |
mesh_dims[1]=50; //num_elems_y |
| 131 |
mesh_dims[2]=50; //num_elems_z |
| 132 |
#else |
| 133 |
mesh_dims[0]=100; //num_elems_x |
| 134 |
mesh_dims[1]=100; //num_elems_y |
| 135 |
mesh_dims[2]=100*numprocs; //num_elems_z |
| 136 |
#endif |
| 137 |
|
| 138 |
std::ostringstream oss; |
| 139 |
oss << mesh_dims[0] << "x" << mesh_dims[1] << "x" << mesh_dims[2]; |
| 140 |
|
| 141 |
double start_time = stk::cpu_time(); |
| 142 |
|
| 143 |
stk::mesh::fixtures::TetFixture fixture( MPI_COMM_WORLD, mesh_dims[0], mesh_dims[1], mesh_dims[2]); |
| 144 |
fixture.m_meta.commit(); |
| 145 |
fixture.generate_mesh(); |
| 146 |
|
| 147 |
double mesh_create_time = stk::cpu_time() - start_time; |
| 148 |
|
| 149 |
start_time = stk::cpu_time(); |
| 150 |
|
| 151 |
stk::mesh::create_faces(fixture.m_bulk_data); |
| 152 |
|
| 153 |
double create_faces_time = stk::cpu_time() - start_time; |
| 154 |
double total_time = mesh_create_time + create_faces_time; |
| 155 |
|
| 156 |
std::vector<size_t> mesh_counts; |
| 157 |
stk::mesh::comm_mesh_counts(fixture.m_bulk_data, mesh_counts); |
| 158 |
|
| 159 |
if (proc == 0) { |
| 160 |
std::cout<< "\nnum nodes: "<<mesh_counts[stk::topology::NODE_RANK]<<std::endl; |
| 161 |
std::cout<< "num edges: "<<mesh_counts[stk::topology::EDGE_RANK]<<std::endl; |
| 162 |
std::cout<< "num faces: "<<mesh_counts[stk::topology::FACE_RANK]<<std::endl; |
| 163 |
std::cout<< "num elems: "<<mesh_counts[stk::topology::ELEMENT_RANK]<<std::endl; |
| 164 |
} |
| 165 |
|
| 166 |
size_t now=0, hwm=0; |
| 167 |
stk::get_memory_usage(now,hwm); |
| 168 |
size_t global_hwm=0; |
| 169 |
MPI_Allreduce(&hwm, &global_hwm, 1, MPI_LONG_LONG, MPI_MAX, fixture.m_bulk_data.parallel()); |
| 170 |
|
| 171 |
if (proc == 0) { |
| 172 |
static const int NUM_TIMERS = 3; |
| 173 |
const double timers[NUM_TIMERS] = {mesh_create_time, create_faces_time, total_time}; |
| 174 |
const char* timer_names[NUM_TIMERS] = {"Create mesh", "Create faces", "Total time"}; |
| 175 |
|
| 176 |
stk::print_timers_and_memory(timer_names, timers, NUM_TIMERS); |
| 177 |
std::cout<<"Global HWM: "<<stk::human_bytes(global_hwm)<<std::endl; |
| 178 |
} |
| 179 |
|
| 180 |
stk::parallel_print_time_without_output_and_hwm(MPI_COMM_WORLD, total_time); |
| 181 |
} |
| 182 |
|
| 183 |
} //namespace performance_tests |
| 184 |
} //namespace stk |