Debian Codegraph @

packages/stk/stk_performance_tests/stk_mesh/perfEntityCommDatabase.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/parallel/Parallel.hpp>
37 #include <stk_util/util/MemoryTracking.hpp>
38 #include <stk_util/environment/perf_util.hpp>
39 #include <stk_mesh/base/BulkData.hpp>
40 #include <stk_mesh/base/EntityCommDatabase.hpp>
41 #include <stk_unit_test_utils/timer.hpp>
42 #include <cstdlib>
43
44 TEST(EntityCommDatabase, TimingInsertErase )
45 {
46 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { GTEST_SKIP(); }
47
48 std::cout << "HWM at startup: "<<stk::get_max_hwm_across_procs(MPI_COMM_WORLD)<<std::endl;
49
50 const int arbitrarySeed = 42121;
51 std::srand(arbitrarySeed);
52
53 const stk::mesh::EntityId minId = 1;
54 const stk::mesh::EntityId maxId = 75000;
55
56 auto randomId = [&](){ return minId + std::rand()%(maxId-minId); };
57
58 size_t curMemStart = 0, hwm = 0;
59 stk::get_memory_usage(curMemStart, hwm);
60 std::cout<<"Start cur-mem: "<<curMemStart<<std::endl;
61
62 #ifndef NDEBUG
63 const unsigned numIters = 100000;
64 #else
65 const unsigned numIters = 8000000;
66 #endif
67 const unsigned NUM_RUNS = 5;
68
69 stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD);
70 batchTimer.initialize_batch_timer();
71
72 for (unsigned j = 0; j < NUM_RUNS; j++) {
73 batchTimer.start_batch_timer();
74
75 stk::mesh::EntityCommDatabase ecd;
76
77 const int owner = 1;
78 const int sharer = 2;
79 for(unsigned i=0; i<numIters; ++i) {
80 stk::mesh::EntityKey key(stk::topology::NODE_RANK, randomId());
81 ecd.insert(key, stk::mesh::EntityCommInfo(stk::mesh::BulkData::SHARED, sharer), owner);
82
83 stk::mesh::EntityKey rmKey(stk::topology::NODE_RANK, randomId());
84 ecd.erase(rmKey, stk::mesh::EntityCommInfo(stk::mesh::BulkData::SHARED, sharer));
85 }
86
87 size_t curMemEnd = 0;
88 stk::get_memory_usage(curMemEnd, hwm);
89 size_t curMemUsed = curMemEnd - curMemStart;
90 std::cout << "EntityCommDatabase Memory Usage: " << stk::human_bytes(curMemUsed) << std::endl;
91 std::cout << "EntityCommDatabase (nkeys="<<ecd.num_comm_keys()<<") uses approx "<<(curMemUsed/ecd.num_comm_keys())<<" bytes per key"<<std::endl;
92
93 batchTimer.stop_batch_timer();
94 }
95
96 batchTimer.print_batch_timing(numIters);
97 }
98