| 1 |
/* |
| 2 |
* Copyright(C) 1999-2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
#include "el_check_monot.h" // for check_monot |
| 9 |
#include "exodusII.h" // for ex_inquire, ex_opts, etc |
| 10 |
#include "fmt/ostream.h" |
| 11 |
#include "globals.h" // for ELEM_COMM_MAP, etc |
| 12 |
#include "nem_spread.h" // for NemSpread, etc |
| 13 |
#include "pe_common.h" // for PEX_MAX |
| 14 |
#include "rf_allo.h" // for array_alloc, safe_free |
| 15 |
#include "rf_io_const.h" // for Debug_Flag, Exo_LB_File |
| 16 |
#include "rf_util.h" // for print_line |
| 17 |
#include "sort_utils.h" // for gds_qsort |
| 18 |
#include "vector_data.h" |
| 19 |
#include <array> |
| 20 |
#include <cassert> |
| 21 |
#include <cstddef> // for size_t |
| 22 |
#include <cstdio> // for stderr, etc |
| 23 |
#include <cstdlib> // for exit |
| 24 |
#include <string> |
| 25 |
|
| 26 |
char **qa_record_ptr, **inf_record_ptr; |
| 27 |
int num_inf_rec = 0, num_qa_rec = 0, length_qa = 0; |
| 28 |
|
| 29 |
/**************************************************************************** |
| 30 |
**************************************************************************** |
| 31 |
**************************************************************************** |
| 32 |
* This function reads load-balance information for salsa on a parallel |
| 33 |
* computer. |
| 34 |
* |
| 35 |
* Author: Gary L. Hennigan (1421) |
| 36 |
*--------------------------------------------------------------------------- |
| 37 |
* Revision History. |
| 38 |
* |
| 39 |
* Gary Hennigan: |
| 40 |
* 08 November 1993 - Modified scalar version to write information out |
| 41 |
* to the parallel disk array once processed. |
| 42 |
**************************************************************************** |
| 43 |
**************************************************************************** |
| 44 |
****************************************************************************/ |
| 45 |
template void NemSpread<float, int>::load_lb_info(); |
| 46 |
template void NemSpread<double, int>::load_lb_info(); |
| 47 |
template void NemSpread<float, int64_t>::load_lb_info(); |
| 48 |
template void NemSpread<double, int64_t>::load_lb_info(); |
| 49 |
|
| 50 |
template <typename T, typename INT> void NemSpread<T, INT>::load_lb_info() |
| 51 |
|
| 52 |
/* |
| 53 |
* load_lb_info: |
| 54 |
* |
| 55 |
* This function reads and distributes the load balance information. |
| 56 |
* This information is defined as the following scalars, which are specific |
| 57 |
* to each processor: |
| 58 |
* |
| 59 |
* Num_Internal_Nodes |
| 60 |
* Num_Border_Nodes |
| 61 |
* Num_External_Nodes |
| 62 |
* globals.Num_Internal_Elems |
| 63 |
* globals.Num_Border_Elems |
| 64 |
* |
| 65 |
* and the following vectors, also specific to each processor: |
| 66 |
* |
| 67 |
* globals.GNodes [Num_Internal_Nodes+Num_Border_Nodes+Num_External_Nodes] |
| 68 |
* globals.GElems [globals.Num_Internal_Elems+globals.Num_Border_Elems] |
| 69 |
* |
| 70 |
* For the 1 processor case, this routine fills in appropriate values |
| 71 |
* for these quantities. |
| 72 |
*/ |
| 73 |
{ |
| 74 |
|
| 75 |
int lb_exoid = 0; |
| 76 |
INT cmap_max_size = 0; |
| 77 |
char Title[MAX_LINE_LENGTH + 1]; |
| 78 |
float version; |
| 79 |
|
| 80 |
int cpu_ws = 0; |
| 81 |
|
| 82 |
/******************************** START EXECUTION ****************************/ |
| 83 |
if (Debug_Flag != 0) { |
| 84 |
fmt::print("\nStart to read in and distribute the load balance info\n"); |
| 85 |
} |
| 86 |
|
| 87 |
/* Open the Load Balance exoII file for reading */ |
| 88 |
|
| 89 |
fmt::print("EXODUS II load-balance file: {}\n", Exo_LB_File); |
| 90 |
cpu_ws = io_ws; |
| 91 |
int mode = EX_READ | int64api; |
| 92 |
int iio_ws = 0; // Don't interfere with exodus files; this is the nemesis file. |
| 93 |
if ((lb_exoid = ex_open(Exo_LB_File.c_str(), mode, &cpu_ws, &iio_ws, &version)) == -1) { |
| 94 |
fmt::print(stderr, "[{}] ERROR: Could not open lb file, {}\n", __func__, Exo_LB_File); |
| 95 |
exit(1); |
| 96 |
} |
| 97 |
|
| 98 |
/* Read information about the processor configuration */ |
| 99 |
read_proc_init(lb_exoid, Proc_Info, Proc_Ids); |
| 100 |
|
| 101 |
/* Allocate space for the counts */ |
| 102 |
globals.Num_Internal_Nodes.resize(Proc_Info[2]); |
| 103 |
globals.Num_Border_Nodes.resize(Proc_Info[2]); |
| 104 |
globals.Num_External_Nodes.resize(Proc_Info[2]); |
| 105 |
globals.Num_Internal_Elems.resize(Proc_Info[2]); |
| 106 |
globals.Num_Border_Elems.resize(Proc_Info[2]); |
| 107 |
globals.Num_N_Comm_Maps.resize(Proc_Info[2]); |
| 108 |
globals.Num_E_Comm_Maps.resize(Proc_Info[2]); |
| 109 |
|
| 110 |
/* Allocate space for each processor entity */ |
| 111 |
globals.GNodes.resize(Proc_Info[2]); |
| 112 |
globals.GElems.resize(Proc_Info[2]); |
| 113 |
globals.Elem_Map.resize(Proc_Info[2]); |
| 114 |
|
| 115 |
/* Allocate contiguous space for the pointer vectors on all processors */ |
| 116 |
std::vector<INT> Int_Space(1); |
| 117 |
std::vector<INT> Int_Node_Num(Proc_Info[0]); |
| 118 |
std::vector<INT> Bor_Node_Num(Proc_Info[0]); |
| 119 |
std::vector<INT> Ext_Node_Num(Proc_Info[0]); |
| 120 |
std::vector<INT> Int_Elem_Num(Proc_Info[0]); |
| 121 |
std::vector<INT> Bor_Elem_Num(Proc_Info[0]); |
| 122 |
std::vector<INT> Node_Comm_Num(Proc_Info[0]); |
| 123 |
std::vector<INT> Elem_Comm_Num(Proc_Info[0]); |
| 124 |
|
| 125 |
/* Read the initial information contained in the load balance file */ |
| 126 |
read_lb_init(lb_exoid, Int_Space, Int_Node_Num, Bor_Node_Num, Ext_Node_Num, Int_Elem_Num, |
| 127 |
Bor_Elem_Num, Node_Comm_Num, Elem_Comm_Num, Title); |
| 128 |
|
| 129 |
/* Allocate memory for the communication map arrays */ |
| 130 |
globals.N_Comm_Map.resize(Proc_Info[2]); |
| 131 |
globals.E_Comm_Map.resize(Proc_Info[2]); |
| 132 |
|
| 133 |
for (int iproc = 0; iproc < Proc_Info[2]; iproc++) { |
| 134 |
|
| 135 |
/* |
| 136 |
* Error check: |
| 137 |
* Currently a maximum of one nodal communication map and one |
| 138 |
* elemental communication map is supported. |
| 139 |
*/ |
| 140 |
if (globals.Num_N_Comm_Maps[iproc] > 1 || globals.Num_E_Comm_Maps[iproc] > 1) { |
| 141 |
fmt::print(stderr, |
| 142 |
"[{}] ERROR. Only 1 nodal and elemental comm map " |
| 143 |
"is supported\n", |
| 144 |
__func__); |
| 145 |
exit(1); |
| 146 |
} |
| 147 |
else { |
| 148 |
/* Always allocate at least one and initialize the counts to 0 */ |
| 149 |
globals.N_Comm_Map[iproc].node_cnt = 0; |
| 150 |
globals.E_Comm_Map[iproc].elem_cnt = 0; |
| 151 |
} |
| 152 |
} /* End "for (int iproc=0; iproc <Proc_Info[2]; iproc++)" */ |
| 153 |
|
| 154 |
/* Set up each processor for the communication map parameters */ |
| 155 |
read_cmap_params(lb_exoid, globals.E_Comm_Map, globals.N_Comm_Map, &cmap_max_size); |
| 156 |
|
| 157 |
/* |
| 158 |
* loop through the processors, one at a time, to read |
| 159 |
* their load balance information |
| 160 |
* |
| 161 |
* NOTE: From here on there are no provisions for multiple nodal |
| 162 |
* or elemental communication maps. |
| 163 |
*/ |
| 164 |
|
| 165 |
for (int iproc = 0; iproc < Proc_Info[0]; iproc++) { |
| 166 |
|
| 167 |
/* Get the node map for processor "iproc" */ |
| 168 |
size_t itotal_nodes = globals.Num_Internal_Nodes[iproc] + globals.Num_Border_Nodes[iproc] + |
| 169 |
globals.Num_External_Nodes[iproc]; |
| 170 |
globals.GNodes[iproc].resize(itotal_nodes); |
| 171 |
if (ex_get_processor_node_maps( |
| 172 |
lb_exoid, &globals.GNodes[iproc][0], &globals.GNodes[iproc][Int_Node_Num[iproc]], |
| 173 |
&globals.GNodes[iproc][Int_Node_Num[iproc] + Bor_Node_Num[iproc]], iproc) < 0) { |
| 174 |
fmt::print(stderr, "[{}] ERROR, failed to get node map for Proc {}!\n", __func__, iproc); |
| 175 |
exit(1); |
| 176 |
} |
| 177 |
|
| 178 |
/* Get the element map for processor number "iproc" */ |
| 179 |
size_t itotal_elems = globals.Num_Internal_Elems[iproc] + globals.Num_Border_Elems[iproc]; |
| 180 |
globals.GElems[iproc].resize(itotal_elems); |
| 181 |
globals.Elem_Map[iproc].resize(itotal_elems); |
| 182 |
|
| 183 |
if (ex_get_processor_elem_maps(lb_exoid, &globals.GElems[iproc][0], |
| 184 |
&globals.GElems[iproc][Int_Elem_Num[iproc]], iproc) < 0) { |
| 185 |
fmt::print(stderr, "[{}] ERROR, failed to get element map for Proc {}!\n", __func__, iproc); |
| 186 |
exit(1); |
| 187 |
} |
| 188 |
globals.Elem_Map[iproc] = globals.GElems[iproc]; |
| 189 |
|
| 190 |
if (Node_Comm_Num[iproc] > 0) { |
| 191 |
globals.N_Comm_Map[iproc].node_ids.resize(globals.N_Comm_Map[iproc].node_cnt); |
| 192 |
globals.N_Comm_Map[iproc].proc_ids.resize(globals.N_Comm_Map[iproc].node_cnt); |
| 193 |
|
| 194 |
if (ex_get_node_cmap(lb_exoid, globals.N_Comm_Map[iproc].map_id, |
| 195 |
Data(globals.N_Comm_Map[iproc].node_ids), |
| 196 |
Data(globals.N_Comm_Map[iproc].proc_ids), iproc) < 0) { |
| 197 |
/* |
| 198 |
* If there are disconnected mesh pieces, then it is |
| 199 |
* possible that there is no communication between the |
| 200 |
* pieces and there will be no communication maps. Normally |
| 201 |
* this is a problem, so output a warning, but don't abort. |
| 202 |
*/ |
| 203 |
fmt::print(stderr, "[{}] WARNING. Failed to get nodal comm map for Proc {}!\n", __func__, |
| 204 |
iproc); |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
if (Elem_Comm_Num[iproc] > 0) { |
| 209 |
globals.E_Comm_Map[iproc].elem_ids.resize(globals.E_Comm_Map[iproc].elem_cnt); |
| 210 |
globals.E_Comm_Map[iproc].side_ids.resize(globals.E_Comm_Map[iproc].elem_cnt); |
| 211 |
globals.E_Comm_Map[iproc].proc_ids.resize(globals.E_Comm_Map[iproc].elem_cnt); |
| 212 |
|
| 213 |
if (ex_get_elem_cmap(lb_exoid, globals.E_Comm_Map[iproc].map_id, |
| 214 |
Data(globals.E_Comm_Map[iproc].elem_ids), |
| 215 |
Data(globals.E_Comm_Map[iproc].side_ids), |
| 216 |
Data(globals.E_Comm_Map[iproc].proc_ids), iproc) < 0) { |
| 217 |
fmt::print(stderr, "[{}] ERROR. Failed to get elemental comm map for Proc {}!\n", __func__, |
| 218 |
iproc); |
| 219 |
exit(1); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
/* |
| 224 |
* Communicate load balance information to the correct processor |
| 225 |
* - if iproc = Proc_Ids[*] then process the data instead. |
| 226 |
*/ |
| 227 |
assert(Proc_Ids[iproc] == iproc); |
| 228 |
|
| 229 |
/* |
| 230 |
* Sort the local element numbers in ascending global element numbers. |
| 231 |
* This means that globals.GElems will be monotonic. |
| 232 |
*/ |
| 233 |
gds_qsort(Data(globals.GElems[iproc]), globals.Num_Internal_Elems[iproc]); |
| 234 |
gds_qsort(Data(globals.Elem_Map[iproc]), globals.Num_Internal_Elems[iproc]); |
| 235 |
|
| 236 |
/* Check that globals.GNodes is monotonic, from i = 0 to Num_Internal_Nodes */ |
| 237 |
#ifdef DEBUG |
| 238 |
assert(check_monot(&globals.GNodes[iproc], globals.Num_Internal_Nodes[iproc])); |
| 239 |
|
| 240 |
/* |
| 241 |
* Check that globals.GNodes is monotonic, from i = Num_Internal_Nodes to |
| 242 |
* (Num_Internal_Nodes + Num_Border_Nodes) |
| 243 |
*/ |
| 244 |
assert(check_monot(&(globals.GNodes[iproc][globals.Num_Internal_Nodes[iproc]]), |
| 245 |
globals.Num_Border_Nodes[iproc])); |
| 246 |
#endif |
| 247 |
} |
| 248 |
|
| 249 |
/* Close the load balance file - we are finished with it */ |
| 250 |
if (ex_close(lb_exoid) == -1) { |
| 251 |
fmt::print(stderr, "[{}] ERROR: Error in closing load balance file\n", __func__); |
| 252 |
exit(1); |
| 253 |
} |
| 254 |
|
| 255 |
/************************* Cleanup and Printout Phase ***********************/ |
| 256 |
|
| 257 |
if (num_qa_rec > 0) { |
| 258 |
for (int i = 0; i < length_qa; i++) { |
| 259 |
safe_free(reinterpret_cast<void **>(&(qa_record_ptr[i]))); |
| 260 |
} |
| 261 |
safe_free(reinterpret_cast<void **>(&qa_record_ptr)); |
| 262 |
} |
| 263 |
|
| 264 |
if (num_inf_rec > 0) { |
| 265 |
for (int i = 0; i < num_inf_rec; i++) { |
| 266 |
safe_free(reinterpret_cast<void **>(&(inf_record_ptr[i]))); |
| 267 |
} |
| 268 |
safe_free(reinterpret_cast<void **>(&inf_record_ptr)); |
| 269 |
} |
| 270 |
|
| 271 |
for (int iproc = 0; iproc < Proc_Info[2]; iproc++) { |
| 272 |
if (globals.Num_Internal_Nodes[iproc] == 0 && globals.Num_Border_Nodes[iproc] == 0 && |
| 273 |
globals.Num_External_Nodes[iproc] == 0) { |
| 274 |
fmt::print(stderr, "\n[{}] WARNING, Processor {} has no nodes!\n", __func__, iproc); |
| 275 |
} |
| 276 |
if (globals.Num_Internal_Elems[iproc] == 0 && globals.Num_Border_Elems[iproc] == 0) { |
| 277 |
fmt::print(stderr, "\n[{}] WARNING, Processor {} has no elements!\n", __func__, iproc); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
/*========================================================================*/ |
| 282 |
|
| 283 |
if (Debug_Flag != 0) { |
| 284 |
fmt::print("\nFinished distributing load balance info\n"); |
| 285 |
} |
| 286 |
|
| 287 |
/* Output Detailed timing information for the program */ |
| 288 |
/* |
| 289 |
* Print out a Large table of Load Balance Information if the debug_flag |
| 290 |
* setting is large enough |
| 291 |
*/ |
| 292 |
|
| 293 |
if (Debug_Flag >= 7) { |
| 294 |
fmt::print("\n\n"); |
| 295 |
print_line("=", 79); |
| 296 |
for (int iproc = 0; iproc < Proc_Info[2]; iproc++) { |
| 297 |
fmt::print("\n\t***For Processor {}***\n", Proc_Ids[iproc]); |
| 298 |
fmt::print("\tInternal nodes owned by the current processor\n\t"); |
| 299 |
for (INT i = 0; i < globals.Num_Internal_Nodes[iproc]; i++) { |
| 300 |
fmt::print(" {}", globals.GNodes[iproc][i]); |
| 301 |
} |
| 302 |
|
| 303 |
fmt::print("\n"); |
| 304 |
|
| 305 |
fmt::print("\tBorder nodes owned by the current processor\n\t"); |
| 306 |
for (INT i = 0; i < globals.Num_Border_Nodes[iproc]; i++) { |
| 307 |
fmt::print(" {}", globals.GNodes[iproc][i + globals.Num_Internal_Nodes[iproc]]); |
| 308 |
} |
| 309 |
|
| 310 |
fmt::print("\n"); |
| 311 |
|
| 312 |
if (globals.Num_External_Nodes[iproc] > 0) { |
| 313 |
fmt::print("\tExternal nodes needed by the current processor\n\t"); |
| 314 |
for (INT i = 0; i < globals.Num_External_Nodes[iproc]; i++) { |
| 315 |
fmt::print(" {}", globals.GNodes[iproc][i + globals.Num_Internal_Nodes[iproc] + |
| 316 |
globals.Num_Border_Nodes[iproc]]); |
| 317 |
} |
| 318 |
|
| 319 |
fmt::print("\n"); |
| 320 |
} |
| 321 |
|
| 322 |
fmt::print("\tInternal elements owned by the current processor\n\t"); |
| 323 |
for (INT i = 0; i < globals.Num_Internal_Elems[iproc]; i++) { |
| 324 |
fmt::print(" {}", globals.GElems[iproc][i]); |
| 325 |
} |
| 326 |
|
| 327 |
fmt::print("\n"); |
| 328 |
|
| 329 |
if (globals.Num_Border_Elems[iproc] > 0) { |
| 330 |
fmt::print("\tBorder elements owned by the current processor\n\t"); |
| 331 |
for (INT i = 0; i < globals.Num_Border_Elems[iproc]; i++) { |
| 332 |
fmt::print(" {}", globals.GElems[iproc][i + globals.Num_Internal_Elems[iproc]]); |
| 333 |
} |
| 334 |
|
| 335 |
fmt::print("\n"); |
| 336 |
} |
| 337 |
|
| 338 |
if (globals.Num_N_Comm_Maps[iproc] > 0) { |
| 339 |
fmt::print("\tNodal Comm Map for the current processor\n"); |
| 340 |
fmt::print("\t\tnode IDs:"); |
| 341 |
for (size_t i = 0; i < globals.N_Comm_Map[iproc].node_cnt; i++) { |
| 342 |
fmt::print(" {}", globals.N_Comm_Map[iproc].node_ids[i]); |
| 343 |
} |
| 344 |
fmt::print("\n\t\tproc IDs:"); |
| 345 |
for (size_t i = 0; i < globals.N_Comm_Map[iproc].node_cnt; i++) { |
| 346 |
fmt::print(" {}", globals.N_Comm_Map[iproc].proc_ids[i]); |
| 347 |
} |
| 348 |
|
| 349 |
fmt::print("\n"); |
| 350 |
} |
| 351 |
|
| 352 |
if (globals.Num_E_Comm_Maps[iproc] > 0) { |
| 353 |
fmt::print("\tElemental Comm Map for the current processor\n"); |
| 354 |
fmt::print("\t\telement IDs:"); |
| 355 |
for (size_t i = 0; i < globals.E_Comm_Map[iproc].elem_cnt; i++) { |
| 356 |
fmt::print(" {}", globals.E_Comm_Map[iproc].elem_ids[i]); |
| 357 |
} |
| 358 |
fmt::print("\n\t\tside IDs:"); |
| 359 |
for (size_t i = 0; i < globals.E_Comm_Map[iproc].elem_cnt; i++) { |
| 360 |
fmt::print(" {}", globals.E_Comm_Map[iproc].side_ids[i]); |
| 361 |
} |
| 362 |
fmt::print("\n\t\tproc IDs:"); |
| 363 |
for (size_t i = 0; i < globals.E_Comm_Map[iproc].elem_cnt; i++) { |
| 364 |
fmt::print(" {}", globals.E_Comm_Map[iproc].proc_ids[i]); |
| 365 |
} |
| 366 |
|
| 367 |
fmt::print("\n"); |
| 368 |
} |
| 369 |
} |
| 370 |
fmt::print("\n"); |
| 371 |
print_line("=", 79); |
| 372 |
} |
| 373 |
|
| 374 |
} /* END of routine load_lb_info () ******************************************/ |
| 375 |
/*****************************************************************************/ |
| 376 |
/*****************************************************************************/ |
| 377 |
|
| 378 |
template <typename T, typename INT> |
| 379 |
void NemSpread<T, INT>::read_proc_init(int lb_exoid, std::array<int, 6> &proc_info, |
| 380 |
std::vector<int> &proc_ids) |
| 381 |
|
| 382 |
/*---------------------------------------------------------------------------- |
| 383 |
* read_proc_init: |
| 384 |
* |
| 385 |
* This function reads information about the processor configuration |
| 386 |
* which the load balance was generated for and makes assignments for each |
| 387 |
* processor. |
| 388 |
*---------------------------------------------------------------------------- |
| 389 |
* Variable Glossary (after return): |
| 390 |
* |
| 391 |
* proc_info[0] = # procs, from load balance file |
| 392 |
* proc_info[1] = # procs for, from load balance file |
| 393 |
* proc_info[2] = # procs this processor is responsible for |
| 394 |
* proc_info[3] = # of extra procs |
| 395 |
* |
| 396 |
*/ |
| 397 |
{ |
| 398 |
char ftype[2]; |
| 399 |
if (ex_get_init_info(lb_exoid, &proc_info[0], &proc_info[1], ftype) < 0) { |
| 400 |
fmt::print(stderr, "[{}] ERROR, could not get init info!\n", __func__); |
| 401 |
exit(1); |
| 402 |
} |
| 403 |
|
| 404 |
/* Calculate which processor is responsible for what */ |
| 405 |
proc_info[2] = proc_info[0]; |
| 406 |
proc_ids.resize(proc_info[2]); |
| 407 |
|
| 408 |
for (int i1 = 0; i1 < proc_info[2]; i1++) { |
| 409 |
proc_ids[i1] = i1; |
| 410 |
} |
| 411 |
} /* End of read_proc_init() *************************************************/ |
| 412 |
/*****************************************************************************/ |
| 413 |
/*****************************************************************************/ |
| 414 |
/*****************************************************************************/ |
| 415 |
|
| 416 |
template <typename T, typename INT> |
| 417 |
void NemSpread<T, INT>::read_lb_init(int lb_exoid, std::vector<INT> &Int_Space, |
| 418 |
std::vector<INT> &Int_Node_Num, std::vector<INT> &Bor_Node_Num, |
| 419 |
std::vector<INT> &Ext_Node_Num, std::vector<INT> &Int_Elem_Num, |
| 420 |
std::vector<INT> &Bor_Elem_Num, |
| 421 |
std::vector<INT> &Node_Comm_Num, |
| 422 |
std::vector<INT> &Elem_Comm_Num, char * /*Title*/) |
| 423 |
|
| 424 |
/* |
| 425 |
* read_lb_init: |
| 426 |
* |
| 427 |
* This function reads the initial information contained in the |
| 428 |
* load balance file |
| 429 |
* |
| 430 |
* |
| 431 |
*/ |
| 432 |
{ |
| 433 |
/*********************BEGIN EXECUTABLE STATEMENTS****************************/ |
| 434 |
|
| 435 |
/* Read Set-up information from the load-balance file on Proc 0 */ |
| 436 |
|
| 437 |
/* |
| 438 |
* If debugging is not on go ahead and report errors from init. This |
| 439 |
* will show version mismatch information by default. |
| 440 |
*/ |
| 441 |
int old_opt = 0; |
| 442 |
if (Debug_Flag == 0) { |
| 443 |
old_opt = ex_opts(EX_VERBOSE); |
| 444 |
} |
| 445 |
|
| 446 |
/* Read the title of the LB File and about the size of the mesh */ |
| 447 |
INT num_nodes; |
| 448 |
INT num_elem; |
| 449 |
INT num_elem_blk; |
| 450 |
INT num_node_sets; |
| 451 |
INT num_side_sets; |
| 452 |
int error = ex_get_init_global(lb_exoid, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, |
| 453 |
&num_side_sets); |
| 454 |
|
| 455 |
check_exodus_error(error, "ex_get_init"); |
| 456 |
|
| 457 |
if (Debug_Flag == 0) { |
| 458 |
ex_opts(old_opt); |
| 459 |
} |
| 460 |
|
| 461 |
#ifdef DEBUG |
| 462 |
if (Debug_Flag >= 2) { |
| 463 |
fmt::print("---------------------------------------------------------\n" |
| 464 |
"\t\tLoad balance file global information\n" |
| 465 |
"---------------------------------------------------------\n" |
| 466 |
"\tNumber of nodes: {}\n" |
| 467 |
"\tNumber of elements: {}\n" |
| 468 |
"\tNumber of element blocks: {}\n" |
| 469 |
"---------------------------------------------------------\n", |
| 470 |
fmt::group_digits(num_nodes), fmt::group_digits(num_elem), |
| 471 |
fmt::group_digits(num_elem_blk)); |
| 472 |
} |
| 473 |
#endif |
| 474 |
|
| 475 |
/* Cross-check the load balance file info against the mesh info */ |
| 476 |
if (((size_t)num_nodes != globals.Num_Node) || ((size_t)num_elem != globals.Num_Elem) || |
| 477 |
(num_elem_blk != globals.Num_Elem_Blk)) { |
| 478 |
fmt::print(stderr, "[{}] ERROR: Problem dimensions in the LB File don't match with those \ |
| 479 |
in mesh file", |
| 480 |
__func__); |
| 481 |
exit(1); |
| 482 |
} |
| 483 |
|
| 484 |
/* Read the QA Records */ |
| 485 |
num_qa_rec = ex_inquire_int(lb_exoid, EX_INQ_QA); |
| 486 |
if (num_qa_rec > 0) { |
| 487 |
length_qa = 4 * num_qa_rec; |
| 488 |
qa_record_ptr = |
| 489 |
reinterpret_cast<char **>(array_alloc(__FILE__, __LINE__, 1, length_qa, sizeof(char *))); |
| 490 |
for (int i = 0; i < length_qa; i++) { |
| 491 |
qa_record_ptr[i] = reinterpret_cast<char *>( |
| 492 |
array_alloc(__FILE__, __LINE__, 1, (MAX_STR_LENGTH + 1), sizeof(char))); |
| 493 |
} |
| 494 |
error = ex_get_qa(lb_exoid, reinterpret_cast<char *(*)[4]>(&qa_record_ptr[0])); |
| 495 |
check_exodus_error(error, "ex_get_qa"); |
| 496 |
} |
| 497 |
|
| 498 |
/* Read the Info Records */ |
| 499 |
num_inf_rec = ex_inquire_int(lb_exoid, EX_INQ_INFO); |
| 500 |
if (num_inf_rec > 0) { |
| 501 |
inf_record_ptr = |
| 502 |
reinterpret_cast<char **>(array_alloc(__FILE__, __LINE__, 1, num_inf_rec, sizeof(char *))); |
| 503 |
for (int i = 0; i < num_inf_rec; i++) { |
| 504 |
inf_record_ptr[i] = reinterpret_cast<char *>( |
| 505 |
array_alloc(__FILE__, __LINE__, 1, (MAX_LINE_LENGTH + 2), sizeof(char))); |
| 506 |
} |
| 507 |
error = ex_get_info(lb_exoid, inf_record_ptr); |
| 508 |
check_exodus_error(error, "ex_get_info"); |
| 509 |
} |
| 510 |
|
| 511 |
Int_Space[0] = 0; |
| 512 |
|
| 513 |
for (int i = 0; i < Proc_Info[0]; i++) { |
| 514 |
|
| 515 |
if (ex_get_loadbal_param(lb_exoid, &Int_Node_Num[i], &Bor_Node_Num[i], &Ext_Node_Num[i], |
| 516 |
&Int_Elem_Num[i], &Bor_Elem_Num[i], &Node_Comm_Num[i], |
| 517 |
&Elem_Comm_Num[i], i) < 0) { |
| 518 |
fmt::print(stderr, "[{}] ERROR, could not get load balance params!\n", __func__); |
| 519 |
exit(1); |
| 520 |
} |
| 521 |
|
| 522 |
#ifdef DEBUG |
| 523 |
if (Debug_Flag >= 5) { |
| 524 |
if (i == 0) { |
| 525 |
fmt::print("--------------------------------------------------------\n" |
| 526 |
"\t\tLoad balance parameters as read by Processor 0\n" |
| 527 |
"--------------------------------------------------------\n"); |
| 528 |
} |
| 529 |
fmt::print("Read on processor 0 for processor {}\n" |
| 530 |
"\tNumber internal nodes: {}\n" |
| 531 |
"\tNumber border nodes: {}\n" |
| 532 |
"\tNumber external nodes: {}\n" |
| 533 |
"\tNumber internal elements: {}\n" |
| 534 |
"\tNumber border elements: {}\n" |
| 535 |
"\tNumber of nodal comm maps: {}\n" |
| 536 |
"\tNumber of elemental comm maps: {}\n" |
| 537 |
"--------------------------------------------------------\n", |
| 538 |
fmt::group_digits(i), fmt::group_digits(Int_Node_Num[i]), |
| 539 |
fmt::group_digits(Bor_Node_Num[i]), fmt::group_digits(Ext_Node_Num[i]), |
| 540 |
fmt::group_digits(Int_Elem_Num[i]), fmt::group_digits(Bor_Elem_Num[i]), |
| 541 |
fmt::group_digits(Node_Comm_Num[i]), fmt::group_digits(Elem_Comm_Num[i])); |
| 542 |
} |
| 543 |
#endif /* DEBUG */ |
| 544 |
|
| 545 |
Int_Space[0] = PEX_MAX(Int_Space[0], Int_Node_Num[i] + Bor_Node_Num[i] + Ext_Node_Num[i] + |
| 546 |
Int_Elem_Num[i] + Bor_Elem_Num[i]); |
| 547 |
} |
| 548 |
|
| 549 |
/* Each processor extracts the information that it needs */ |
| 550 |
for (int i = 0; i < Proc_Info[2]; i++) { |
| 551 |
globals.Num_Internal_Nodes[i] = Int_Node_Num[i]; |
| 552 |
globals.Num_Border_Nodes[i] = Bor_Node_Num[i]; |
| 553 |
globals.Num_External_Nodes[i] = Ext_Node_Num[i]; |
| 554 |
globals.Num_Internal_Elems[i] = Int_Elem_Num[i]; |
| 555 |
globals.Num_Border_Elems[i] = Bor_Elem_Num[i]; |
| 556 |
globals.Num_N_Comm_Maps[i] = Node_Comm_Num[i]; |
| 557 |
globals.Num_E_Comm_Maps[i] = Elem_Comm_Num[i]; |
| 558 |
} |
| 559 |
|
| 560 |
/* |
| 561 |
* Print Out a Summary of the Load Balance Information, as distributed |
| 562 |
* across the processors, for the appropriate value of Debug_Flag |
| 563 |
*/ |
| 564 |
if (Debug_Flag >= 3) { |
| 565 |
print_line("=", 79); |
| 566 |
fmt::print("\n\t\tTABLE OF LOAD BALANCE STATISTICS\n\n"); |
| 567 |
fmt::print("{}{}\n", "globals. Int_Nodes Bor_Nodes Ext_Nodes", |
| 568 |
" Int_Elems Bor_Elems N_Comm_Maps E_Comm_Maps"); |
| 569 |
print_line("-", 79); |
| 570 |
fmt::print("\n"); |
| 571 |
for (int i = 0; i < Proc_Info[2]; i++) { |
| 572 |
fmt::print("{:6d} {:6d} {:6d} {:6d} {:6d} {:6d} {:6d} {:6d}\n", Proc_Ids[i], |
| 573 |
globals.Num_Internal_Nodes[i], globals.Num_Border_Nodes[i], |
| 574 |
globals.Num_External_Nodes[i], globals.Num_Internal_Elems[i], |
| 575 |
globals.Num_Border_Elems[i], globals.Num_N_Comm_Maps[i], |
| 576 |
globals.Num_E_Comm_Maps[i]); |
| 577 |
} |
| 578 |
print_line("=", 79); |
| 579 |
fmt::print("\n\n"); |
| 580 |
} |
| 581 |
|
| 582 |
} /* END of read_lb_init () **************************************************/ |
| 583 |
/*****************************************************************************/ |
| 584 |
/*****************************************************************************/ |
| 585 |
/*****************************************************************************/ |
| 586 |
|
| 587 |
template <typename T, typename INT> |
| 588 |
void NemSpread<T, INT>::read_cmap_params(int lb_exoid, std::vector<ELEM_COMM_MAP<INT>> &E_Comm_Map, |
| 589 |
std::vector<NODE_COMM_MAP<INT>> &N_Comm_Map, |
| 590 |
INT *cmap_max_size) |
| 591 |
{ |
| 592 |
for (int iproc = 0; iproc < Proc_Info[0]; iproc++) { |
| 593 |
|
| 594 |
std::array<INT, 1> node_cm_ids{0}; |
| 595 |
std::array<INT, 1> node_cm_cnts{0}; |
| 596 |
std::array<INT, 1> elem_cm_ids{0}; |
| 597 |
std::array<INT, 1> elem_cm_cnts{0}; |
| 598 |
|
| 599 |
/* Read the communication map IDs for processor "iproc" */ |
| 600 |
if (ex_get_cmap_params(lb_exoid, Data(node_cm_ids), Data(node_cm_cnts), Data(elem_cm_ids), |
| 601 |
Data(elem_cm_cnts), iproc) < 0) { |
| 602 |
fmt::print(stderr, "[{}] ERROR, unable to read communication map params\n", __func__); |
| 603 |
exit(1); |
| 604 |
} |
| 605 |
|
| 606 |
N_Comm_Map[iproc].map_id = node_cm_ids[0]; |
| 607 |
N_Comm_Map[iproc].node_cnt = node_cm_cnts[0]; |
| 608 |
E_Comm_Map[iproc].map_id = elem_cm_ids[0]; |
| 609 |
E_Comm_Map[iproc].elem_cnt = elem_cm_cnts[0]; |
| 610 |
|
| 611 |
INT psum = 2 * node_cm_cnts[0] + 3 * elem_cm_cnts[0]; |
| 612 |
*cmap_max_size = std::max(*cmap_max_size, psum); |
| 613 |
} |
| 614 |
|
| 615 |
if (Debug_Flag >= 4) { |
| 616 |
print_line("=", 79); |
| 617 |
fmt::print("\t\tCOMMUNICATION MAP INFORMATION\n"); |
| 618 |
fmt::print("\t\t largest cmap = {} integers\n", *cmap_max_size); |
| 619 |
print_line("=", 79); |
| 620 |
|
| 621 |
int bprnt_n = 0; |
| 622 |
int bprnt_e = 0; |
| 623 |
|
| 624 |
for (int i1 = 0; i1 < Proc_Info[2]; i1++) { |
| 625 |
if (globals.Num_N_Comm_Maps[i1] > 0) { |
| 626 |
bprnt_n = 1; |
| 627 |
} |
| 628 |
if (globals.Num_E_Comm_Maps[i1] > 0) { |
| 629 |
bprnt_e = 1; |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
if (bprnt_n > 0) { |
| 634 |
fmt::print("\tFor Proc\tNode Map ID\tNode Count\n"); |
| 635 |
fmt::print("\t------------------------------------------------\n"); |
| 636 |
for (int iproc = 0; iproc < Proc_Info[2]; iproc++) { |
| 637 |
if (globals.Num_N_Comm_Maps[iproc] > 0) { |
| 638 |
fmt::print("\t {}\t\t {}\t\t {}\n", Proc_Ids[iproc], N_Comm_Map[iproc].map_id, |
| 639 |
N_Comm_Map[iproc].node_cnt); |
| 640 |
} |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
if (bprnt_e > 0) { |
| 645 |
fmt::print("\tFor Proc\tElem Map ID\tElem Count\n"); |
| 646 |
fmt::print("\t------------------------------------------------\n"); |
| 647 |
for (int iproc = 0; iproc < Proc_Info[2]; iproc++) { |
| 648 |
if (globals.Num_E_Comm_Maps[iproc] > 0) { |
| 649 |
fmt::print("\t {}\t\t {}\t\t {}\n", Proc_Ids[iproc], E_Comm_Map[iproc].map_id, |
| 650 |
E_Comm_Map[iproc].elem_cnt); |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
print_line("=", 79); |
| 656 |
} |
| 657 |
|
| 658 |
} /* End of read_cmap_params() ***********************************************/ |
| 659 |
/*****************************************************************************/ |
| 660 |
/*****************************************************************************/ |
| 661 |
/*****************************************************************************/ |