| 1 |
#include "gtest/gtest.h" // for AssertHelper, EXPECT_EQ, etc |
| 2 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 3 |
#include <stk_mesh/base/FieldParallel.hpp> |
| 4 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 5 |
#include <stk_mesh/base/Comm.hpp> |
| 6 |
#include <stk_mesh/base/GetEntities.hpp> |
| 7 |
#include <stk_util/parallel/CommSparse.hpp> |
| 8 |
#include <stk_util/parallel/CommNeighbors.hpp> |
| 9 |
#include <stk_util/environment/WallTime.hpp> |
| 10 |
#include <stk_util/environment/perf_util.hpp> |
| 11 |
#include <stk_util/diag/Timer.hpp> |
| 12 |
#include <stk_util/diag/PrintTimer.hpp> |
| 13 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 14 |
#include <stk_unit_test_utils/getOption.h> |
| 15 |
#include <stk_balance/balance.hpp> |
| 16 |
#include <stk_balance/balanceUtils.hpp> |
| 17 |
#include <stk_io/FillMesh.hpp> |
| 18 |
|
| 19 |
struct Stats { |
| 20 |
int min; |
| 21 |
int max; |
| 22 |
float avg; |
| 23 |
}; |
| 24 |
|
| 25 |
void compute_stats(const stk::mesh::BulkData& mesh, std::vector<Stats>& stats) |
| 26 |
{ |
| 27 |
stk::mesh::Part& owned_part = mesh.mesh_meta_data().locally_owned_part(); |
| 28 |
stk::mesh::Part& shared_part = mesh.mesh_meta_data().globally_shared_part(); |
| 29 |
stk::mesh::Selector recv_aura = (!owned_part) & (!shared_part); |
| 30 |
|
| 31 |
int numElems = stk::mesh::count_selected_entities(owned_part, mesh.buckets(stk::topology::ELEM_RANK)); |
| 32 |
int numSharedNodes = stk::mesh::count_selected_entities(shared_part, mesh.buckets(stk::topology::NODE_RANK)); |
| 33 |
int recvAuraNodes = stk::mesh::count_selected_entities(recv_aura, mesh.buckets(stk::topology::NODE_RANK)); |
| 34 |
int numSharingProcs = mesh.all_sharing_procs(stk::topology::NODE_RANK).size(); |
| 35 |
|
| 36 |
int minSharedNodes = 0, maxSharedNodes = 0, minAuraNodes = 0, maxAuraNodes = 0, minSharingProcs = 0, maxSharingProcs = 0; |
| 37 |
int minElems = 0, maxElems = 0; |
| 38 |
|
| 39 |
stk::all_reduce_min(mesh.parallel(), &numElems, &minElems, 1); |
| 40 |
stk::all_reduce_max(mesh.parallel(), &numElems, &maxElems, 1); |
| 41 |
stk::all_reduce_min(mesh.parallel(), &numSharedNodes, &minSharedNodes, 1); |
| 42 |
stk::all_reduce_max(mesh.parallel(), &numSharedNodes, &maxSharedNodes, 1); |
| 43 |
stk::all_reduce_min(mesh.parallel(), &recvAuraNodes, &minAuraNodes, 1); |
| 44 |
stk::all_reduce_max(mesh.parallel(), &recvAuraNodes, &maxAuraNodes, 1); |
| 45 |
stk::all_reduce_min(mesh.parallel(), &numSharingProcs, &minSharingProcs, 1); |
| 46 |
stk::all_reduce_max(mesh.parallel(), &numSharingProcs, &maxSharingProcs, 1); |
| 47 |
|
| 48 |
float nsharedNodes = numSharedNodes, nauraNodes = recvAuraNodes, nsharingProcs = numSharingProcs; |
| 49 |
float nElems = numElems; |
| 50 |
float avgSharedNodes = 0, avgAuraNodes = 0, avgSharingProcs = 0; |
| 51 |
float avgElems = 0; |
| 52 |
|
| 53 |
stk::all_reduce_sum(mesh.parallel(), &nElems, &avgElems, 1); |
| 54 |
avgElems /= mesh.parallel_size(); |
| 55 |
stk::all_reduce_sum(mesh.parallel(), &nsharedNodes, &avgSharedNodes, 1); |
| 56 |
avgSharedNodes /= mesh.parallel_size(); |
| 57 |
stk::all_reduce_sum(mesh.parallel(), &nauraNodes, &avgAuraNodes, 1); |
| 58 |
avgAuraNodes /= mesh.parallel_size(); |
| 59 |
stk::all_reduce_sum(mesh.parallel(), &nsharingProcs, &avgSharingProcs, 1); |
| 60 |
avgSharingProcs /= mesh.parallel_size(); |
| 61 |
|
| 62 |
stats.resize(4); |
| 63 |
stats[0].min = minElems; |
| 64 |
stats[0].max = maxElems; |
| 65 |
stats[0].avg = avgElems; |
| 66 |
|
| 67 |
stats[1].min = minSharedNodes; |
| 68 |
stats[1].max = maxSharedNodes; |
| 69 |
stats[1].avg = avgSharedNodes; |
| 70 |
|
| 71 |
stats[2].min = minAuraNodes; |
| 72 |
stats[2].max = maxAuraNodes; |
| 73 |
stats[2].avg = avgAuraNodes; |
| 74 |
|
| 75 |
stats[3].min = minSharingProcs; |
| 76 |
stats[3].max = maxSharingProcs; |
| 77 |
stats[3].avg = avgSharingProcs; |
| 78 |
} |
| 79 |
|
| 80 |
void print_mesh_stats(const std::string& prefix, const std::vector<Stats>& stats) |
| 81 |
{ |
| 82 |
std::ostringstream os; |
| 83 |
os << prefix<<": Elements min/max/avg: " << stats[0].min<<" / "<<stats[0].max<<" / "<<stats[0].avg<<"\n"; |
| 84 |
os << prefix<<": SharedNodes min/max/avg: " << stats[1].min<<" / "<<stats[1].max<<" / "<<stats[1].avg<<"\n"; |
| 85 |
os << prefix<<": AuraNodes min/max/avg: " << stats[2].min<<" / "<<stats[2].max<<" / "<<stats[2].avg<<"\n"; |
| 86 |
os << prefix<<": SharingProcs min/max/avg: " << stats[3].min<<" / "<<stats[3].max<<" / "<<stats[3].avg<<"\n"; |
| 87 |
std::cerr<<os.str(); |
| 88 |
} |
| 89 |
|
| 90 |
void fill_small_mesh_with_big_ids(stk::mesh::BulkData& bulkData) |
| 91 |
{ |
| 92 |
int myProc = bulkData.parallel_rank(); |
| 93 |
int otherProc = 1-myProc; |
| 94 |
|
| 95 |
stk::mesh::Field<double>& coordField = bulkData.mesh_meta_data().declare_field<double>(stk::topology::NODE_RANK, "coordinates"); |
| 96 |
stk::mesh::put_field_on_mesh(coordField, bulkData.mesh_meta_data().universal_part(), 3, nullptr); |
| 97 |
bulkData.mesh_meta_data().set_coordinate_field(&coordField); |
| 98 |
|
| 99 |
stk::mesh::Part& hexPart = bulkData.mesh_meta_data().get_topology_root_part(stk::topology::HEX_8); |
| 100 |
|
| 101 |
bulkData.modification_begin(); |
| 102 |
|
| 103 |
const uint64_t B = 1000000000; |
| 104 |
|
| 105 |
if (myProc == 0) |
| 106 |
{ |
| 107 |
stk::mesh::EntityId elemId = 10*B; |
| 108 |
stk::mesh::EntityIdVector nodeIds{10*B, 20*B, 30*B, 40*B, 50*B, 60*B, 70*B, 80*B}; |
| 109 |
stk::mesh::declare_element(bulkData, hexPart, elemId, nodeIds); |
| 110 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 50*B), otherProc); |
| 111 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 60*B), otherProc); |
| 112 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 70*B), otherProc); |
| 113 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 80*B), otherProc); |
| 114 |
} |
| 115 |
else |
| 116 |
{ |
| 117 |
stk::mesh::EntityId elemId = 20*B; |
| 118 |
stk::mesh::EntityIdVector nodeIds{50*B, 60*B, 70*B, 80*B, 90*B, 100*B, 110*B, 120*B}; |
| 119 |
stk::mesh::declare_element(bulkData, hexPart, elemId, nodeIds); |
| 120 |
|
| 121 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 50*B), otherProc); |
| 122 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 60*B), otherProc); |
| 123 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 70*B), otherProc); |
| 124 |
bulkData.add_node_sharing(bulkData.get_entity(stk::topology::NODE_RANK, 80*B), otherProc); |
| 125 |
} |
| 126 |
|
| 127 |
bulkData.modification_end(); |
| 128 |
} |
| 129 |
|
| 130 |
class StkPerfComm : public stk::unit_test_util::MeshFixture |
| 131 |
{ |
| 132 |
typedef stk::mesh::Field<double> ScalarField; |
| 133 |
typedef stk::mesh::Field<double> VectorField; |
| 134 |
|
| 135 |
protected: |
| 136 |
StkPerfComm() : |
| 137 |
nodeFieldScalar(get_meta().declare_field<double>(stk::topology::NODE_RANK, "NodeFieldScalar")), |
| 138 |
nodeFieldVector(get_meta().declare_field<double>(stk::topology::NODE_RANK, "NodeFieldVector")), |
| 139 |
enabledTimerSet(CHILDMASK1), |
| 140 |
rootTimer(createRootTimer("totalTestRuntime", enabledTimerSet)), |
| 141 |
timerMeshCreate("Mesh create", CHILDMASK1, rootTimer), |
| 142 |
timerRebalance("Rebalance", CHILDMASK1, rootTimer), |
| 143 |
timerCommSparse("CommSparse", CHILDMASK1, rootTimer), |
| 144 |
timerCommSparseNeighbors("CommSparseNeighbors", CHILDMASK1, rootTimer), |
| 145 |
timerCommNeighbors("CommNeighbors", CHILDMASK1, rootTimer), |
| 146 |
duration(0.0), num_times(100) |
| 147 |
{ |
| 148 |
stk::mesh::put_field_on_mesh(nodeFieldScalar, get_meta().universal_part(), nullptr); |
| 149 |
stk::mesh::put_field_on_mesh(nodeFieldVector, get_meta().universal_part(), 3, nullptr); |
| 150 |
} |
| 151 |
|
| 152 |
~StkPerfComm() |
| 153 |
{ |
| 154 |
stk::diag::deleteRootTimer(rootTimer); |
| 155 |
} |
| 156 |
|
| 157 |
void run_comm_neighbors_performance_test() |
| 158 |
{ |
| 159 |
stk::parallel_machine_barrier(get_bulk().parallel()); |
| 160 |
for(int i=0; i<num_times; ++i) { |
| 161 |
set_initial_shared_values(); |
| 162 |
time_comm_neighbors(); |
| 163 |
} |
| 164 |
print_stats(); |
| 165 |
} |
| 166 |
|
| 167 |
void run_comm_sparse_performance_test() |
| 168 |
{ |
| 169 |
stk::parallel_machine_barrier(get_bulk().parallel()); |
| 170 |
for(int i=0; i<num_times; ++i) { |
| 171 |
set_initial_shared_values(); |
| 172 |
time_comm_sparse_votd(); |
| 173 |
} |
| 174 |
print_stats(); |
| 175 |
} |
| 176 |
|
| 177 |
void run_comm_sparse_setprocs_performance_test() |
| 178 |
{ |
| 179 |
stk::parallel_machine_barrier(get_bulk().parallel()); |
| 180 |
for(int i=0; i<num_times; ++i) { |
| 181 |
set_initial_shared_values(); |
| 182 |
time_comm_sparse_setprocs(); |
| 183 |
} |
| 184 |
print_stats(); |
| 185 |
} |
| 186 |
|
| 187 |
void unpack_and_check_entity_key(stk::CommBuffer& buf) { |
| 188 |
stk::mesh::EntityKey key; |
| 189 |
buf.unpack<stk::mesh::EntityKey>(key); |
| 190 |
expect_entity_shared_and_owned(key); |
| 191 |
} |
| 192 |
|
| 193 |
void unpack_and_check_entity_key(stk::CommBufferV& buf) { |
| 194 |
stk::mesh::EntityKey key; |
| 195 |
buf.unpack<stk::mesh::EntityKey>(key); |
| 196 |
expect_entity_shared_and_owned(key); |
| 197 |
} |
| 198 |
|
| 199 |
void expect_entity_shared_and_owned(stk::mesh::EntityKey key) { |
| 200 |
stk::mesh::Entity node = get_bulk().get_entity(key); |
| 201 |
EXPECT_TRUE(get_bulk().is_valid(node)); |
| 202 |
EXPECT_TRUE(get_bulk().bucket(node).shared()); |
| 203 |
EXPECT_TRUE(get_bulk().bucket(node).owned()); |
| 204 |
} |
| 205 |
|
| 206 |
void comm_sparse_votd() |
| 207 |
{ |
| 208 |
stk::mesh::Selector shared = get_meta().globally_shared_part(); |
| 209 |
stk::mesh::Selector owned = get_meta().locally_owned_part(); |
| 210 |
const stk::mesh::BucketVector& shared_not_owned = get_bulk().get_buckets(stk::topology::NODE_RANK, shared & !owned); |
| 211 |
stk::CommSparse commSparse(get_bulk().parallel()); |
| 212 |
|
| 213 |
for(int phase = 0; phase<2; ++phase) { |
| 214 |
for(const stk::mesh::Bucket* bptr : shared_not_owned) { |
| 215 |
const stk::mesh::Bucket& bkt = *bptr; |
| 216 |
for(size_t i=0; i<bkt.size(); ++i) { |
| 217 |
int owner = get_bulk().parallel_owner_rank(bkt[i]); |
| 218 |
stk::CommBuffer& buf = commSparse.send_buffer(owner); |
| 219 |
buf.pack<stk::mesh::EntityKey>(get_bulk().entity_key(bkt[i])); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
if (phase == 0) { |
| 224 |
commSparse.allocate_buffers(); |
| 225 |
} |
| 226 |
else { |
| 227 |
commSparse.communicate(); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
for(int p=0; p<get_bulk().parallel_size(); ++p) { |
| 232 |
stk::CommBuffer& buf = commSparse.recv_buffer(p); |
| 233 |
while(buf.remaining()) { |
| 234 |
unpack_and_check_entity_key(buf); |
| 235 |
} |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
void comm_sparse_setprocs() |
| 240 |
{ |
| 241 |
stk::mesh::Selector shared = get_meta().globally_shared_part(); |
| 242 |
stk::mesh::Selector owned = get_meta().locally_owned_part(); |
| 243 |
const stk::mesh::BucketVector& shared_not_owned = get_bulk().get_buckets(stk::topology::NODE_RANK, shared & !owned); |
| 244 |
const std::vector<int>& sharing_procs = get_bulk().all_sharing_procs(stk::topology::NODE_RANK); |
| 245 |
stk::CommSparse commSparse(get_bulk().parallel()); |
| 246 |
|
| 247 |
for(int phase = 0; phase<2; ++phase) { |
| 248 |
for(const stk::mesh::Bucket* bptr : shared_not_owned) { |
| 249 |
const stk::mesh::Bucket& bkt = *bptr; |
| 250 |
for(size_t i=0; i<bkt.size(); ++i) { |
| 251 |
int owner = get_bulk().parallel_owner_rank(bkt[i]); |
| 252 |
stk::CommBuffer& buf = commSparse.send_buffer(owner); |
| 253 |
buf.pack<stk::mesh::EntityKey>(get_bulk().entity_key(bkt[i])); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
if (phase == 0) { |
| 258 |
commSparse.allocate_buffers(sharing_procs, sharing_procs); |
| 259 |
} |
| 260 |
else { |
| 261 |
commSparse.communicate(); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
for(int p=0; p<get_bulk().parallel_size(); ++p) { |
| 266 |
stk::CommBuffer& buf = commSparse.recv_buffer(p); |
| 267 |
while(buf.remaining()) { |
| 268 |
unpack_and_check_entity_key(buf); |
| 269 |
} |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
void comm_neighbors() |
| 274 |
{ |
| 275 |
stk::mesh::Selector shared = get_meta().globally_shared_part(); |
| 276 |
stk::mesh::Selector owned = get_meta().locally_owned_part(); |
| 277 |
const stk::mesh::BucketVector& shared_not_owned = get_bulk().get_buckets(stk::topology::NODE_RANK, shared & !owned); |
| 278 |
const std::vector<int>& procs = get_bulk().all_sharing_procs(stk::topology::NODE_RANK); |
| 279 |
stk::CommNeighbors commNeighbors(get_bulk().parallel(), procs); |
| 280 |
for(int p : procs) { |
| 281 |
const stk::mesh::HostCommMapIndices sharedCommMap = get_bulk().volatile_fast_shared_comm_map<stk::ngp::MemSpace>(stk::topology::NODE_RANK, p); |
| 282 |
size_t numEntities = sharedCommMap.extent(0); |
| 283 |
commNeighbors.send_buffer(p).reserve(numEntities*sizeof(stk::mesh::EntityKey)); |
| 284 |
} |
| 285 |
|
| 286 |
for(const stk::mesh::Bucket* bptr : shared_not_owned) { |
| 287 |
const stk::mesh::Bucket& bkt = *bptr; |
| 288 |
for(size_t i=0; i<bkt.size(); ++i) { |
| 289 |
int owner = get_bulk().parallel_owner_rank(bkt[i]); |
| 290 |
stk::CommBufferV& buf = commNeighbors.send_buffer(owner); |
| 291 |
buf.pack<stk::mesh::EntityKey>(get_bulk().entity_key(bkt[i])); |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
commNeighbors.communicate(); |
| 296 |
|
| 297 |
for(int p : procs) { |
| 298 |
stk::CommBufferV& buf = commNeighbors.recv_buffer(p); |
| 299 |
while(buf.size_in_bytes() > 0) { |
| 300 |
unpack_and_check_entity_key(buf); |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
void time_comm_sparse_votd() |
| 306 |
{ |
| 307 |
stk::diag::TimeBlock timerStart(timerCommSparse, get_bulk().parallel()); |
| 308 |
rootTimer.start(); |
| 309 |
double startTime = stk::wall_time(); |
| 310 |
comm_sparse_votd(); |
| 311 |
duration += stk::wall_time() - startTime; |
| 312 |
} |
| 313 |
|
| 314 |
void time_comm_sparse_setprocs() |
| 315 |
{ |
| 316 |
stk::diag::TimeBlock timerStart(timerCommSparseNeighbors, get_bulk().parallel()); |
| 317 |
rootTimer.start(); |
| 318 |
double startTime = stk::wall_time(); |
| 319 |
comm_sparse_setprocs(); |
| 320 |
duration += stk::wall_time() - startTime; |
| 321 |
} |
| 322 |
|
| 323 |
void time_comm_neighbors() |
| 324 |
{ |
| 325 |
stk::diag::TimeBlock timerStart(timerCommNeighbors, get_bulk().parallel()); |
| 326 |
rootTimer.start(); |
| 327 |
double startTime = stk::wall_time(); |
| 328 |
comm_neighbors(); |
| 329 |
duration += stk::wall_time() - startTime; |
| 330 |
} |
| 331 |
|
| 332 |
void set_initial_shared_values() |
| 333 |
{ |
| 334 |
const stk::mesh::MetaData& meta = get_meta(); |
| 335 |
const stk::mesh::BucketVector& buckets = get_bulk().get_buckets(stk::topology::NODE_RANK, meta.globally_shared_part()); |
| 336 |
for(const stk::mesh::Bucket* bucket : buckets) { |
| 337 |
const stk::mesh::Bucket& bkt = *bucket; |
| 338 |
double* scalarFieldData = stk::mesh::field_data(nodeFieldScalar, bkt); |
| 339 |
double* vectorFieldData = stk::mesh::field_data(nodeFieldVector, bkt); |
| 340 |
for(size_t i=0; i<bkt.size(); ++i) { |
| 341 |
stk::mesh::EntityId id = get_bulk().identifier(bkt[i]); |
| 342 |
double value = id; |
| 343 |
scalarFieldData[i] = value; |
| 344 |
vectorFieldData[3*i+0] = value; |
| 345 |
vectorFieldData[3*i+1] = value; |
| 346 |
vectorFieldData[3*i+2] = value; |
| 347 |
} |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
void print_stats() |
| 352 |
{ |
| 353 |
if (stk::parallel_machine_rank(get_comm()) == 0) { |
| 354 |
std::cout << "Time: "<<duration<<std::endl; |
| 355 |
} |
| 356 |
print_output_for_pass_fail_test(); |
| 357 |
print_output_for_graph_generation(); |
| 358 |
} |
| 359 |
|
| 360 |
void print_output_for_graph_generation() |
| 361 |
{ |
| 362 |
std::ostringstream os; |
| 363 |
os << "forGraphs.log."<<get_bulk().parallel_size(); |
| 364 |
std::ofstream out(os.str()); |
| 365 |
bool printTimingsOnlySinceLastPrint = false; |
| 366 |
stk::diag::printTimersTable(out, rootTimer, stk::diag::METRICS_ALL, printTimingsOnlySinceLastPrint, get_comm()); |
| 367 |
stk::parallel_print_time_without_output_and_hwm(get_comm(), duration, std::cout); |
| 368 |
} |
| 369 |
|
| 370 |
void print_output_for_pass_fail_test() |
| 371 |
{ |
| 372 |
std::ofstream out("forPassFailScript.log"); |
| 373 |
double maxTime = stk::get_max_time_across_procs(duration, get_comm()); |
| 374 |
double maxHwmInMB = stk::get_max_hwm_across_procs(get_comm()) / (1024.0 * 1024.0); |
| 375 |
stk::print_stats_for_performance_compare(out, maxTime, maxHwmInMB, get_num_global_faces(), get_comm()); |
| 376 |
} |
| 377 |
|
| 378 |
size_t get_num_global_faces() |
| 379 |
{ |
| 380 |
std::vector<size_t> meshCounts; |
| 381 |
stk::mesh::comm_mesh_counts(get_bulk(), meshCounts); |
| 382 |
return meshCounts[stk::topology::FACE_RANK]; |
| 383 |
} |
| 384 |
|
| 385 |
void rebalance(stk::mesh::BulkData& mesh) |
| 386 |
{ |
| 387 |
stk::diag::TimeBlock timerStartSynchronizedAcrossProcessors(timerRebalance, get_bulk().parallel()); |
| 388 |
rootTimer.start(); |
| 389 |
stk::balance::GraphCreationSettingsForZoltan2 settings; |
| 390 |
stk::balance::balanceStkMesh(settings, mesh); |
| 391 |
} |
| 392 |
|
| 393 |
void generate_and_rebalance_mesh(const std::string& mesh_spec) |
| 394 |
{ |
| 395 |
{ |
| 396 |
stk::diag::TimeBlock timerStartSynchronizedAcrossProcessors(timerMeshCreate, get_comm()); |
| 397 |
rootTimer.start(); |
| 398 |
allocate_bulk(stk::mesh::BulkData::AUTO_AURA); |
| 399 |
stk::io::fill_mesh(mesh_spec, get_bulk()); |
| 400 |
} |
| 401 |
|
| 402 |
std::vector<Stats> stats; |
| 403 |
compute_stats(get_bulk(), stats); |
| 404 |
if (get_bulk().parallel_rank()==0) { |
| 405 |
print_mesh_stats("Before rebalance: ",stats); |
| 406 |
} |
| 407 |
// stk::unit_test_util::write_mesh_using_stk_io("before_rebal.e",get_bulk(), get_bulk().parallel()); |
| 408 |
|
| 409 |
rebalance(get_bulk()); |
| 410 |
|
| 411 |
compute_stats(get_bulk(), stats); |
| 412 |
if (get_bulk().parallel_rank()==0) { |
| 413 |
print_mesh_stats("After rebalance: ",stats); |
| 414 |
} |
| 415 |
// stk::unit_test_util::write_mesh_using_stk_io("after_rebal.e",get_bulk(), get_bulk().parallel()); |
| 416 |
} |
| 417 |
|
| 418 |
void generate_and_rebalance_small_mesh_with_big_ids() |
| 419 |
{ |
| 420 |
{ |
| 421 |
stk::diag::TimeBlock timerStartSynchronizedAcrossProcessors(timerMeshCreate, get_comm()); |
| 422 |
rootTimer.start(); |
| 423 |
allocate_bulk(stk::mesh::BulkData::AUTO_AURA); |
| 424 |
fill_small_mesh_with_big_ids(get_bulk()); |
| 425 |
} |
| 426 |
|
| 427 |
std::vector<Stats> stats; |
| 428 |
compute_stats(get_bulk(), stats); |
| 429 |
if (get_bulk().parallel_rank()==0) { |
| 430 |
print_mesh_stats("Before rebalance: ",stats); |
| 431 |
} |
| 432 |
// stk::unit_test_util::write_mesh_using_stk_io("before_rebal.e",get_bulk(), get_bulk().parallel()); |
| 433 |
|
| 434 |
rebalance(get_bulk()); |
| 435 |
|
| 436 |
compute_stats(get_bulk(), stats); |
| 437 |
if (get_bulk().parallel_rank()==0) { |
| 438 |
print_mesh_stats("After rebalance: ",stats); |
| 439 |
} |
| 440 |
// stk::unit_test_util::write_mesh_using_stk_io("after_rebal.e",get_bulk(), get_bulk().parallel()); |
| 441 |
} |
| 442 |
|
| 443 |
std::string get_mesh_spec() |
| 444 |
{ |
| 445 |
return stk::unit_test_util::get_option("-mesh", "NO_MESH_SPECIFIED"); |
| 446 |
} |
| 447 |
|
| 448 |
ScalarField& nodeFieldScalar; |
| 449 |
VectorField& nodeFieldVector; |
| 450 |
|
| 451 |
const int CHILDMASK1 = 1; |
| 452 |
stk::diag::TimerSet enabledTimerSet; |
| 453 |
stk::diag::Timer rootTimer; |
| 454 |
stk::diag::Timer timerMeshCreate; |
| 455 |
stk::diag::Timer timerRebalance; |
| 456 |
stk::diag::Timer timerCommSparse; |
| 457 |
stk::diag::Timer timerCommSparseNeighbors; |
| 458 |
stk::diag::Timer timerCommNeighbors; |
| 459 |
|
| 460 |
double duration; |
| 461 |
int num_times; |
| 462 |
}; |
| 463 |
|
| 464 |
TEST_F(StkPerfComm, generated_then_rebalance_comm_neighbors) |
| 465 |
{ |
| 466 |
std::string mesh_spec = get_mesh_spec(); |
| 467 |
if (mesh_spec != "NO_MESH_SPECIFIED") { |
| 468 |
generate_and_rebalance_mesh(mesh_spec); |
| 469 |
MPI_Pcontrol(1); |
| 470 |
run_comm_neighbors_performance_test(); |
| 471 |
} |
| 472 |
else { |
| 473 |
if (stk::parallel_machine_rank(get_comm()) == 0) { |
| 474 |
std::cout<<"No mesh specified, exiting."<<std::endl; |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
TEST_F(StkPerfComm, generated_then_rebalance_comm_sparse) |
| 480 |
{ |
| 481 |
std::string mesh_spec = get_mesh_spec(); |
| 482 |
if (mesh_spec != "NO_MESH_SPECIFIED") { |
| 483 |
generate_and_rebalance_mesh(mesh_spec); |
| 484 |
MPI_Pcontrol(1); |
| 485 |
run_comm_sparse_performance_test(); |
| 486 |
} |
| 487 |
else { |
| 488 |
if (stk::parallel_machine_rank(get_comm()) == 0) { |
| 489 |
std::cout<<"No mesh specified, exiting."<<std::endl; |
| 490 |
} |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
TEST_F(StkPerfComm, generated_then_rebalance_comm_sparse_setprocs) |
| 495 |
{ |
| 496 |
std::string mesh_spec = get_mesh_spec(); |
| 497 |
if (mesh_spec != "NO_MESH_SPECIFIED") { |
| 498 |
generate_and_rebalance_mesh(mesh_spec); |
| 499 |
MPI_Pcontrol(1); |
| 500 |
run_comm_sparse_setprocs_performance_test(); |
| 501 |
} |
| 502 |
else { |
| 503 |
if (stk::parallel_machine_rank(get_comm()) == 0) { |
| 504 |
std::cout<<"No mesh specified, exiting."<<std::endl; |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
TEST_F(StkPerfComm, generate_and_rebalance_small_mesh_big_ids) |
| 510 |
{ |
| 511 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) |
| 512 |
{ |
| 513 |
generate_and_rebalance_small_mesh_with_big_ids(); |
| 514 |
} |
| 515 |
else { |
| 516 |
if (stk::parallel_machine_rank(get_comm()) == 0) { |
| 517 |
std::cout<<"No mesh specified, exiting."<<std::endl; |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
|