Skip to content

Commit c0e7b55

Browse files
committed
require that inParts < PCU.Peers
- test/mbalanceEmpty.cc: add info to USAGE text about new requirement. - check for inParts >= PCU.Peers and throw. - print exceptions with nested printing function. - alter scope so that PCU.Self() can be used from exception printing code. - add retval to only write pcu::Finalize once. Signed-off-by: Aiden Woodruff <[email protected]>
1 parent 947383f commit c0e7b55

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

test/mbalanceEmpty.cc

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,30 @@
1111
#include <lionPrint.h>
1212
#include <pcu_util.h>
1313

14+
namespace {
15+
void print_exception(const std::exception& e, int level = 0);
16+
}
17+
1418
int main(int argc, char* argv[]) {
19+
int retval = 0;
1520
pcu::Init(&argc, &argv);
21+
{
22+
pcu::PCU PCU;
1623
try {
17-
pcu::PCU PCU;
1824
if (argc != 5) {
1925
if (PCU.Self() == 0)
20-
std::cerr << "USAGE: <model.dmg> <mesh.smb> <inParts> <outMesh.smb>"
26+
std::cerr << "USAGE: <model.dmg> <mesh.smb> <inParts> <outMesh.smb>\n"
27+
"\nwhere inParts < PCU.Peers()"
2128
<< std::endl;
2229
throw std::runtime_error("invalid arguments");
2330
}
2431
lion_set_verbosity(1);
2532
gmi_register_mesh();
2633
// load model and mesh
2734
int inParts = std::stoi(argv[3]);
35+
if (inParts >= PCU.Peers()) {
36+
throw std::runtime_error("inParts >= PCU.Peers()");
37+
}
2838
int group = PCU.Self() / inParts;
2939
auto loadPCU = PCU.Split(group, 0);
3040
gmi_model* model = gmi_load(argv[1]);
@@ -46,10 +56,31 @@ int main(int argc, char* argv[]) {
4656
// destroy mds
4757
m->destroyNative();
4858
apf::destroyMesh(m);
59+
} catch (const std::exception& e) {
60+
if (PCU.Self() == 0) {
61+
std::cerr << "ERROR: ";
62+
print_exception(e);
63+
}
64+
retval = 1;
4965
} catch (...) {
50-
pcu::Finalize();
51-
return 1;
66+
if (PCU.Self() == 0)
67+
std::cerr << "Unknown exception occurred." << std::endl;
68+
retval = 1;
5269
}
70+
} // PCU object scope
5371
pcu::Finalize();
54-
return 0;
72+
return retval;
5573
}
74+
75+
namespace {
76+
77+
void print_exception(const std::exception& e, int level) {
78+
std::cerr << std::string(level * 2, ' ') << e.what() << '\n';
79+
try {
80+
std::rethrow_if_nested(e);
81+
} catch (const std::exception& nestedE) {
82+
print_exception(nestedE, level + 1);
83+
} catch (...) {}
84+
}
85+
86+
} // namespace

0 commit comments

Comments
 (0)