Debian Codegraph @

packages/seacas/libraries/ioss/src/main/cgns_decomp.C

raw
1 // Copyright(C) 1999-2025 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 // Make asserts active even in non-debug build
8 #undef NDEBUG
9
10 #include "Ionit_Initializer.h"
11 #include "Ioss_DatabaseIO.h"
12 #include "Ioss_DecompositionUtils.h"
13 #include "Ioss_GetLongOpt.h"
14 #include "Ioss_IOFactory.h"
15 #include "Ioss_Property.h"
16 #include "Ioss_Region.h"
17 #include "Ioss_SmartAssert.h"
18 #include "Ioss_Utils.h"
19 #include "Ioss_ZoneConnectivity.h"
20 #include "cgns/Iocgns_StructuredZoneData.h"
21 #include "cgns/Iocgns_Utils.h"
22 #include <array>
23 #include <cmath>
24 #include <cstdio>
25 #include <cstdlib>
26 #include <fmt/core.h>
27 #include <iostream>
28 #include <map>
29 #include <numeric>
30 #include <set>
31 #include <stdint.h>
32 #include <string>
33 #include <vector>
34
35 #include "Ioss_DBUsage.h"
36 #include "Ioss_ParallelUtils.h"
37 #include "Ioss_PropertyManager.h"
38 #include "Ioss_ScopeGuard.h"
39 #include "Ioss_StructuredBlock.h"
40
41 #include <fmt/color.h>
42 #include <fmt/format.h>
43
44 namespace {
45 class Interface
46 {
47 public:
48 bool parse_options(int argc, char **argv)
49 {
50 int option_index = options_.parse(argc, argv);
51 if (option_index < 1) {
52 return false;
53 }
54
55 if (options_.retrieve("help") != nullptr) {
56 options_.usage(std::cerr);
57 exit(EXIT_SUCCESS);
58 }
59
60 verbose = options_.retrieve("verbose") != nullptr;
61
62 if (options_.retrieve("output") != nullptr) {
63 const std::string temp = options_.retrieve("output");
64 histogram = temp.find('h') != std::string::npos;
65 work_per_processor = temp.find('w') != std::string::npos;
66 zone_proc_assignment = temp.find('z') != std::string::npos;
67 verbose = temp.find('v') != std::string::npos || verbose;
68 communication_map = temp.find('c') != std::string::npos;
69 }
70
71 if (options_.retrieve("version") != nullptr) {
72 fmt::print(stderr, "Version: {}\n", version);
73 exit(0);
74 }
75
76 {
77 const char *temp = options_.retrieve("processors");
78 if (temp != nullptr) {
79 proc_count = std::stoi(temp);
80 }
81 else {
82 fmt::print(
83 stderr,
84 "\nERROR: Processor count must be specified with '-processors $<val>' option.\n");
85 options_.usage(std::cerr);
86 exit(EXIT_FAILURE);
87 }
88 }
89
90 {
91 const char *temp = options_.retrieve("ordinal");
92 if (temp != nullptr) {
93 // See if ordinal contains digits or letters...
94 std::string stemp{temp};
95 bool all_dig = stemp.find_first_not_of("0123456789") == std::string::npos;
96 if (all_dig) {
97 ordinal = std::stoi(stemp);
98 switch (ordinal) {
99 case 0: // i
100 ordinal = Iocgns::Ordinal::I;
101 break;
102 case 1: // j
103 ordinal = Iocgns::Ordinal::J;
104 break;
105 case 2: // k
106 ordinal = Iocgns::Ordinal::K;
107 break;
108 case 3: // ij
109 ordinal = Iocgns::Ordinal::I | Iocgns::Ordinal::J;
110 break;
111 case 4: // ik
112 ordinal = Iocgns::Ordinal::I | Iocgns::Ordinal::K;
113 break;
114 case 5: // jk
115 ordinal = Iocgns::Ordinal::J | Iocgns::Ordinal::K;
116 break;
117 default:
118 fmt::print(stderr,
119 "\nERROR: Invalid ordinal ('{}') specified. Must be between 0 and 5.\n",
120 stemp);
121 options_.usage(std::cerr);
122 exit(EXIT_FAILURE);
123 }
124 }
125 else {
126 for (char &st : stemp) {
127 if (st == 'i' || st == 'I') {
128 ordinal |= Iocgns::Ordinal::I;
129 }
130 else if (st == 'j' || st == 'J') {
131 ordinal |= Iocgns::Ordinal::J;
132 }
133 else if (st == 'k' || st == 'K') {
134 ordinal |= Iocgns::Ordinal::K;
135 }
136 else {
137 fmt::print(
138 stderr,
139 "\nERROR: Invalid ordinal ('{}') specified. Must be 'i', 'j', or 'k'.\n", st);
140 options_.usage(std::cerr);
141 exit(EXIT_FAILURE);
142 }
143 }
144 }
145 }
146 }
147
148 {
149 const char *temp = options_.retrieve("line_decomposition");
150 if (temp != nullptr) {
151 line_decomposition = temp;
152 }
153 }
154
155 {
156 const char *temp = options_.retrieve("db_type");
157 if (temp != nullptr) {
158 filetype = temp;
159 }
160 }
161
162 {
163 const char *temp = options_.retrieve("load_balance");
164 if (temp != nullptr) {
165 load_balance = std::stod(temp);
166 }
167 }
168
169 if (option_index < argc) {
170 filename = argv[option_index];
171 }
172 else {
173 fmt::print(stderr, "\nERROR: Filename missing.\n");
174 options_.usage(std::cout);
175 return false;
176 }
177
178 return true;
179 }
180
181 explicit Interface(std::string app_version) : version(std::move(app_version))
182 {
183 options_.usage("[options] input_file");
184 options_.enroll("help", Ioss::GetLongOption::OptType::NoValue, "Print this summary and exit",
185 nullptr);
186 options_.enroll("processors", Ioss::GetLongOption::OptType::MandatoryValue,
187 "Number of processors.", nullptr);
188 options_.enroll("ordinal", Ioss::GetLongOption::OptType::MandatoryValue,
189 "Ordinal not to split 0(i), 1(j), 2(k), 3(ij), 4(ik), or 5(jk).", nullptr);
190 options_.enroll("line_decomposition", Ioss::GetLongOption::OptType::MandatoryValue,
191 "list of 1 or more BC (Family) names.\n"
192 "\t\tFor all structured zones which this BC touches, the ordinal of the face "
193 "(i,j,k) will\n"
194 "\t\tbe set such that a parallel decomposition will not split the zone along "
195 "this ordinal.",
196 nullptr);
197 options_.enroll("load_balance", Ioss::GetLongOption::OptType::MandatoryValue,
198 "Max ratio of processor work to average. [default 1.4]", nullptr);
199 options_.enroll("verbose", Ioss::GetLongOption::OptType::NoValue,
200 "Print additional decomposition information", nullptr);
201 options_.enroll("db_type", Ioss::GetLongOption::OptType::MandatoryValue,
202 "Database Type: gen_struc or cgns. Default is cgns.", nullptr);
203 options_.enroll("output", Ioss::GetLongOption::OptType::MandatoryValue,
204 "What is printed: z=zone-proc assignment, h=histogram, w=work-per-processor, "
205 "c=comm map, v=verbose.",
206 "zhwc");
207 options_.enroll("version", Ioss::GetLongOption::OptType::NoValue, "Print version and exit",
208 nullptr);
209 }
210 Ioss::GetLongOption options_;
211 int proc_count{0};
212 int ordinal{0};
213 double load_balance{1.4};
214 std::string filename{};
215 std::string filetype{"cgns"};
216 std::string line_decomposition{};
217 std::string version{};
218 bool verbose{false};
219 bool histogram{true};
220 bool work_per_processor{true};
221 bool zone_proc_assignment{true};
222 bool communication_map{true};
223 };
224 } // namespace
225 namespace {
226 std::string codename;
227 std::string version = "0.97";
228
229 void cleanup(std::vector<Iocgns::StructuredZoneData *> &zones)
230 {
231 for (auto &zone : zones) {
232 delete zone;
233 zone = nullptr;
234 }
235 }
236
237 double surface_ratio(const Iocgns::StructuredZoneData *zone)
238 {
239 size_t surf =
240 (zone->m_ordinal[0] * zone->m_ordinal[1] + zone->m_ordinal[0] * zone->m_ordinal[2] +
241 zone->m_ordinal[1] * zone->m_ordinal[2]) *
242 static_cast<size_t>(2);
243 size_t vol = zone->cell_count();
244
245 // If a 'perfect' cube, then would be pl=cbrt(vol) on a side and surf would be 6*pl*pl
246 // Calculate 'perfect' surf / actual surf...
247 double pl = std::cbrt(vol);
248 double psurf = 6.0 * pl * pl;
249 return double(surf) / psurf;
250 }
251
252 int64_t generate_guid(size_t id, int rank, int proc_count)
253 {
254 static size_t lpow2 = 0;
255 static int procs = -1;
256 if (procs != proc_count) {
257 lpow2 = Ioss::Utils::log_power_2(proc_count);
258 procs = proc_count;
259 }
260 SMART_ASSERT(rank >= 0);
261 return (id << lpow2) + rank;
262 }
263
264 void update_zgc_data(std::vector<Iocgns::StructuredZoneData *> &zones, int proc_count)
265 {
266 for (auto &zone : zones) {
267 if (zone->is_active()) {
268 zone->resolve_zgc_split_donor(zones);
269 }
270 }
271
272 for (auto &zone : zones) {
273 if (zone->is_active()) {
274 zone->update_zgc_processor(zones);
275 }
276 }
277
278 // Set GUID on all zgc instances...
279 for (auto &zone : zones) {
280 if (zone->is_active()) {
281 for (auto &zgc : zone->m_zoneConnectivity) {
282 zgc.m_ownerGUID = generate_guid(zgc.m_ownerZone, zgc.m_ownerProcessor, proc_count);
283 zgc.m_donorGUID = generate_guid(zgc.m_donorZone, zgc.m_donorProcessor, proc_count);
284 }
285 }
286 }
287 }
288
289 void validate_decomposition(std::vector<Iocgns::StructuredZoneData *> &zones)
290 {
291
292 // Each active zone must be on a processor
293 for (const auto &zone : zones) {
294 if (zone->is_active()) {
295 SMART_ASSERT(zone->m_proc >= 0)(zone->m_proc);
296 }
297 }
298
299 // A processor cannot have more than one zone with the same adam zone
300 std::set<std::pair<int, int>> proc_adam_map;
301 for (const auto &zone : zones) {
302 if (zone->is_active()) {
303 auto success = proc_adam_map.insert(std::make_pair(zone->m_adam->m_zone, zone->m_proc));
304 SMART_ASSERT(success.second);
305 }
306 }
307
308 // Zone Grid Connectivity instances can't connect to themselves...
309 for (auto &zone : zones) {
310 if (zone->is_active()) {
311 for (const auto &zgc : zone->m_zoneConnectivity) {
312 if (zgc.is_active()) {
313 SMART_ASSERT(zgc.m_ownerZone != zgc.m_donorZone)(zgc.m_ownerZone)(zgc.m_donorZone);
314 SMART_ASSERT(zgc.m_ownerGUID != zgc.m_donorGUID)(zgc.m_ownerGUID)(zgc.m_donorGUID);
315 }
316 }
317 }
318 }
319
320 // In Iocgns::Utils::common_write_metadata, there is code to make
321 // sure that the zgc.m_connectionName is unique for all zgc instances on
322 // a zone / processor pair (if !parallel_io which is file-per-processor)
323 // The uniquification appends a letter from 'A' to 'Z' to the name
324 // If the name is still not unique, repeats process with 'AA' to 'ZZ'
325 // Make sure that there are not more than 26 + 26*26 + 1 instances of the same
326 // name on a zone to ensure that this works...
327 for (auto &zone : zones) {
328 if (zone->is_active()) {
329 std::map<std::string, int> zgc_map;
330 for (const auto &zgc : zone->m_zoneConnectivity) {
331 if (zgc.is_active() && !zgc.is_from_decomp()) {
332 zgc_map[zgc.m_connectionName]++;
333 }
334 }
335 for (const auto &kk : zgc_map) {
336 SMART_ASSERT(kk.second < 26 * 26 + 26 + 1)(kk.second);
337 }
338 }
339 } //
340
341 // Zone Grid Connectivity from_decomp instances must be symmetric...
342 // The GUID encodes the id and the processor,
343 std::map<std::pair<size_t, size_t>, int> is_symm;
344 for (auto &zone : zones) {
345 if (zone->is_active()) {
346 for (const auto &zgc : zone->m_zoneConnectivity) {
347 if (zgc.is_active() && zgc.is_from_decomp()) {
348 is_symm[std::make_pair(std::min(zgc.m_ownerGUID, zgc.m_donorGUID),
349 std::max(zgc.m_ownerGUID, zgc.m_donorGUID))]++;
350 }
351 }
352 }
353 }
354 // Iterate `is_symm` and make sure all entries == 2
355 for (const auto &item : is_symm) {
356 SMART_ASSERT(item.second == 2);
357 }
358 }
359
360 bool validate_symmetric_communications(std::vector<Iocgns::StructuredZoneData *> &zones)
361 {
362 std::set<std::pair<std::pair<std::string, int>, std::pair<std::string, int>>> comms;
363 for (const auto &adam_zone : zones) {
364 if (adam_zone->m_parent == nullptr) {
365 // Iterate children (or self) of the adam_zone.
366 for (const auto &zone : zones) {
367 if (zone->is_active() && zone->m_adam == adam_zone) {
368 for (auto &zgc : zone->m_zoneConnectivity) {
369 if (zgc.is_active()) {
370 int p1 = zgc.m_ownerProcessor;
371 int p2 = zgc.m_donorProcessor;
372 comms.emplace(std::make_pair(adam_zone->m_name, p1),
373 std::make_pair(zgc.m_donorName, p2));
374 }
375 }
376 }
377 }
378 }
379 }
380
381 // Now iterate map and for each key->value, make sure value->key is in map...
382 bool valid = true;
383 for (const auto &key_value : comms) {
384 const auto &key = key_value.first;
385 const auto &value = key_value.second;
386 auto search = comms.find(std::make_pair(value, key));
387 if (search == comms.end()) {
388 valid = false;
389 fmt::print(stderr, fg(fmt::color::red),
390 "ERROR: Could not find matching ZGC for {}, proc {} -> {}, proc {}\n", key.first,
391 key.second, value.first, value.second);
392 }
393 }
394 return valid;
395 }
396
397 void output_communications(std::vector<Iocgns::StructuredZoneData *> &zones, int proc_count)
398 {
399 fmt::print("Communication Map: [] is from decomposition; () is from zone-to-zone; omits "
400 "on-proc communication.\n");
401 for (const auto &adam_zone : zones) {
402 if (adam_zone->m_parent == nullptr) {
403 std::vector<std::pair<int, int>> comms;
404
405 // Iterate children (or self) of the adam_zone.
406 for (const auto &zone : zones) {
407 if (zone->is_active() && zone->m_adam == adam_zone) {
408 for (auto &zgc : zone->m_zoneConnectivity) {
409 if (zgc.is_active()) {
410 int p1 = zgc.m_ownerProcessor;
411 int p2 = zgc.m_donorProcessor;
412 if (p1 != p2) {
413 int pmin = std::min(p1, p2);
414 int pmax = std::max(p1, p2);
415 if (zgc.is_from_decomp()) {
416 comms.emplace_back(pmin, -pmax);
417 }
418 else {
419 comms.emplace_back(pmin, pmax);
420 }
421 }
422 }
423 }
424 }
425 }
426
427 Ioss::Utils::uniquify(comms);
428
429 int pw = Ioss::Utils::number_width(proc_count, false);
430 // Two tabs at beginning ~16 spaces. Each entry is "[pw->pw] " which is 6+2pw
431 int npl = (Ioss::Utils::term_width() - 16) / (6 + 2 * pw);
432 npl = npl < 1 ? 1 : npl;
433 int line = 0;
434
435 fmt::print("\tZone '{}' ({} inter-processor communications):\n\t\t", adam_zone->m_name,
436 comms.size());
437 for (const auto &proc : comms) {
438 if (proc.second < 0) {
439 // From decomposition
440 fmt::print(fg(fmt::color::yellow), "[{:{}}->{:{}}] ", proc.first, pw, -proc.second,
441 pw);
442 }
443 else {
444 // Zone to Zone
445 fmt::print("({:{}}->{:{}}) ", proc.first, pw, proc.second, pw);
446 }
447 if (++line >= npl) {
448 fmt::print("\n\t\t");
449 line = 0;
450 }
451 }
452 fmt::print("\n");
453 if (line > 0) {
454 fmt::print("\n");
455 }
456 }
457 }
458 }
459
460 void describe_decomposition(std::vector<Iocgns::StructuredZoneData *> &zones,
461 size_t orig_zone_count, const Interface &interFace)
462 {
463 size_t proc_count = interFace.proc_count;
464 bool verbose = interFace.verbose;
465
466 // ========================================================================
467 // Output information about decomposition...
468 double total_work = std::accumulate(zones.begin(), zones.end(), 0.0,
469 [](double a, Iocgns::StructuredZoneData *b) {
470 return a + (b->m_parent == nullptr ? b->work() : 0);
471 });
472
473 // Get some information just to make output look better. Not part of actual decomposition.
474 size_t proc_width = Ioss::Utils::number_width(proc_count, false);
475 size_t work_width = Ioss::Utils::number_width((size_t)total_work, true);
476
477 // Find maximum ordinal to get width... (makes output look better)
478 int max_ordinal = 0;
479 for (const auto &zone : zones) {
480 if (zone->is_active()) {
481 max_ordinal =
482 std::max({max_ordinal, zone->m_ordinal[0], zone->m_ordinal[1], zone->m_ordinal[2]});
483 }
484 }
485 size_t ord_width = Ioss::Utils::number_width(max_ordinal, false);
486 double avg_work = total_work / (double)proc_count;
487
488 // Print work/processor map...
489 fmt::print("\nDecomposing {} zones over {} processors; Total work = {}; Average = "
490 "{} (goal)\n",
491 fmt::group_digits(orig_zone_count), fmt::group_digits(proc_count),
492 fmt::group_digits((size_t)total_work), fmt::group_digits((size_t)avg_work));
493
494 // Get max name length for all zones...
495 size_t name_len = 0;
496 for (const auto &zone : zones) {
497 if (zone->is_active()) {
498 auto len = zone->m_name.length();
499 name_len = std::max(name_len, len);
500 }
501 }
502
503 if (interFace.zone_proc_assignment) {
504 // Output Zone->Processor assignment info
505 fmt::print("\n");
506 for (const auto &adam_zone : zones) {
507 if (adam_zone->m_parent == nullptr) {
508 if (adam_zone->m_child1 == nullptr) {
509 // Unsplit...
510 fmt::print("\tZone: {:{}}\t Proc: {:{}}\tOrd: {:^12} Work: {:{}} (unsplit)\n",
511 adam_zone->m_name, name_len, adam_zone->m_proc, proc_width,
512 fmt::format("{1:{0}} x {2:{0}} x {3:{0}}", ord_width,
513 adam_zone->m_ordinal[0], adam_zone->m_ordinal[1],
514 adam_zone->m_ordinal[2]),
515 fmt::group_digits(adam_zone->work()), work_width);
516 }
517 else {
518 fmt::print("\tZone: {:{}} is decomposed. \tOrd: {:^12} Work: {:{}}\n",
519 adam_zone->m_name, name_len,
520 fmt::format("{1:{0}} x {2:{0}} x {3:{0}}", ord_width,
521 adam_zone->m_ordinal[0], adam_zone->m_ordinal[1],
522 adam_zone->m_ordinal[2]),
523 fmt::group_digits(adam_zone->work()), work_width);
524 for (const auto &zone : zones) {
525 if (zone->is_active() && zone->m_adam == adam_zone) {
526 fmt::print("\t {:{}}\t Proc: {:{}}\tOrd: {:^12} Work: {:{}} SurfExp: "
527 "{:0.3}\n",
528 zone->m_name, name_len, zone->m_proc, proc_width,
529 fmt::format("{1:{0}} x {2:{0}} x {3:{0}}", ord_width, zone->m_ordinal[0],
530 zone->m_ordinal[1], zone->m_ordinal[2]),
531 fmt::group_digits(zone->work()), work_width, surface_ratio(zone));
532 }
533 }
534 }
535 }
536 }
537 }
538
539 // Output Processor Work information
540 std::vector<size_t> proc_work(proc_count);
541 for (const auto &zone : zones) {
542 if (zone->is_active()) {
543 proc_work[zone->m_proc] += zone->work();
544 }
545 }
546
547 auto avg_median = Ioss::DecompUtils::output_decomposition_statistics(proc_work);
548
549 if (verbose) {
550 for (size_t i = 0; i < proc_work.size(); i++) {
551 for (const auto &zone : zones) {
552 if ((size_t)zone->m_proc == i) {
553 auto pct = int(100.0 * (double)zone->work() / proc_work[i] + 0.5);
554 fmt::print("\t {:{}} {:{}}\t{:3}%\t{:^12}\n", zone->m_name, name_len,
555 fmt::group_digits(zone->work()), work_width, pct,
556 fmt::format("{1:{0}} x {2:{0}} x {3:{0}}", ord_width, zone->m_ordinal[0],
557 zone->m_ordinal[1], zone->m_ordinal[2]));
558 }
559 }
560 fmt::print("\n");
561 }
562 }
563 fmt::print("\n");
564
565 // Output Histogram...
566 if (interFace.histogram) {
567 Ioss::DecompUtils::output_histogram(proc_work, avg_median.first, avg_median.second);
568 }
569
570 // Communication Information (proc X communicates with proc Z)
571 if (interFace.communication_map) {
572 output_communications(zones, proc_count);
573 }
574
575 // Calculate "nodal inflation" -- number of new surface nodes created...
576 auto nodal_work = std::accumulate(zones.begin(), zones.end(), (size_t)0,
577 [](size_t a, Iocgns::StructuredZoneData *b) {
578 return a + (b->m_parent == nullptr ? b->node_count() : 0);
579 });
580
581 if (nodal_work > 0) {
582 auto new_nodal_work = std::accumulate(zones.begin(), zones.end(), (size_t)0,
583 [](size_t a, Iocgns::StructuredZoneData *b) {
584 return a + (b->is_active() ? b->node_count() : 0);
585 });
586
587 auto delta = new_nodal_work - nodal_work;
588 fmt::print("Nodal Inflation:\n\tOriginal Node Count = {}, Decomposed Node Count = {}, "
589 "Created = {}, Ratio = {:.2f}\n\n",
590 fmt::group_digits(nodal_work), fmt::group_digits(new_nodal_work),
591 fmt::group_digits(delta), (double)new_nodal_work / nodal_work);
592 }
593 }
594 } // namespace
595
596 int main(int argc, char *argv[])
597 {
598 #ifdef SEACAS_HAVE_MPI
599 MPI_Init(&argc, &argv);
600 ON_BLOCK_EXIT(MPI_Finalize);
601 #endif
602
603 Ioss::Utils::set_all_streams(std::cout);
604
605 Interface interFace(version);
606 bool success = interFace.parse_options(argc, argv);
607 if (!success) {
608 exit(EXIT_FAILURE);
609 }
610
611 std::string in_type = interFace.filetype;
612
613 codename = argv[0];
614 size_t ind = codename.find_last_of('/', codename.size());
615 if (ind != std::string::npos) {
616 codename = codename.substr(ind + 1, codename.size());
617 }
618
619 Ioss::Init::Initializer io;
620
621 Ioss::PropertyManager properties{};
622 Ioss::DatabaseIO *dbi = Ioss::IOFactory::create(in_type, interFace.filename, Ioss::READ_RESTART,
623 Ioss::ParallelUtils::comm_world(), properties);
624 if (dbi == nullptr || !dbi->ok()) {
625 fmt::print(stderr, "\nERROR: Could not open database '{}' of type '{}'\n", interFace.filename,
626 in_type);
627 std::exit(EXIT_FAILURE);
628 }
629
630 // NOTE: 'region' owns 'db' pointer at this time...
631 Ioss::Region region(dbi, "region_1");
632
633 // Get the structured blocks...
634 const auto &blocks = region.get_structured_blocks();
635 if (blocks.empty()) {
636 fmt::print(stderr, "\nERROR: There are no structured blocks on the mesh.\n");
637 return EXIT_FAILURE;
638 }
639
640 unsigned int line_ordinal = interFace.ordinal;
641 std::vector<Iocgns::StructuredZoneData *> zones;
642 for (auto &iblock : blocks) {
643 size_t ni = iblock->get_property("ni").get_int();
644 size_t nj = iblock->get_property("nj").get_int();
645 size_t nk = iblock->get_property("nk").get_int();
646 size_t zone = iblock->get_property("zone").get_int();
647
648 zones.push_back(new Iocgns::StructuredZoneData(iblock->name(), zone, ni, nj, nk));
649 if (line_ordinal > 0) {
650 zones.back()->m_lineOrdinal = line_ordinal;
651 }
652 zones.back()->m_zoneConnectivity = iblock->m_zoneConnectivity;
653 }
654
655 if (in_type == "cgns") {
656 Iocgns::Utils::set_line_decomposition(dbi->get_file_pointer(), interFace.line_decomposition,
657 zones, 0, interFace.verbose);
658 for (const auto &z : zones) {
659 if (z->m_lineOrdinal == 7) {
660 fmt::print(
661 "WARNING: Zone {} with work {} will not be decomposed due to line ordinal setting.\n",
662 z->m_name, fmt::group_digits(z->work()));
663 }
664 }
665 }
666
667 region.output_summary(std::cout, false);
668
669 size_t orig_zone_count = zones.size();
670
671 double begin = Ioss::Utils::timer();
672 Iocgns::Utils::decompose_model(zones, interFace.proc_count, 0, interFace.load_balance,
673 interFace.verbose);
674 double end1 = Ioss::Utils::timer();
675
676 update_zgc_data(zones, interFace.proc_count);
677 double end2 = Ioss::Utils::timer();
678
679 describe_decomposition(zones, orig_zone_count, interFace);
680
681 auto valid = validate_symmetric_communications(zones);
682 if (!valid) {
683 fmt::print(stderr, fg(fmt::color::red),
684 "\nERROR: Zone Grid Communication interfaces are not symmetric. There is an error "
685 "in the decomposition.\n");
686 }
687
688 validate_decomposition(zones);
689
690 cleanup(zones);
691 fmt::print(stderr,
692 "\nTotal Execution Time = {:.5} seconds to decompose for {} processors. (decomp: "
693 "{:.5}, resolve_zgc: {:.5})\n",
694 end2 - begin, fmt::group_digits(interFace.proc_count), end1 - begin, end2 - end1);
695 if (valid) {
696 exit(EXIT_SUCCESS);
697 }
698 else {
699 exit(EXIT_FAILURE);
700 }
701 }