| 1 |
/* |
| 2 |
* Copyright(C) 1999-2025 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 "EP_SystemInterface.h" |
| 9 |
#include "EP_Version.h" // for qainfo |
| 10 |
#include "FileInfo.h" |
| 11 |
#include "GetLongOpt.h" // for GetLongOption, etc |
| 12 |
#include "SL_tokenize.h" // for tokenize |
| 13 |
#include <algorithm> // for sort, transform |
| 14 |
#include <cctype> // for tolower |
| 15 |
#include <copyright.h> |
| 16 |
#include <cstddef> // for size_t |
| 17 |
#include <cstdlib> // for strtol, abs, exit, strtoul, etc |
| 18 |
#include <cstring> // for strchr, strlen |
| 19 |
#include <fmt/ostream.h> |
| 20 |
#include <glob.h> |
| 21 |
#include <sstream> |
| 22 |
#include <stdexcept> |
| 23 |
#include <string> // for string, char_traits, etc |
| 24 |
#include <term_width.h> |
| 25 |
#include <unistd.h> |
| 26 |
#include <utility> // for pair, make_pair |
| 27 |
#include <vector> // for vector |
| 28 |
|
| 29 |
#if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || \ |
| 30 |
defined(__MINGW32__) || defined(_WIN64) || defined(__MINGW64__) |
| 31 |
#define __SUP_WINDOWS__ 1 |
| 32 |
#include <direct.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
#if !defined(__SUP_WINDOWS__) |
| 36 |
#include <dirent.h> |
| 37 |
#endif |
| 38 |
|
| 39 |
namespace { |
| 40 |
bool str_equal(const std::string &s1, const std::string &s2) |
| 41 |
{ |
| 42 |
return (s1.size() == s2.size()) && |
| 43 |
std::equal(s1.begin(), s1.end(), s2.begin(), |
| 44 |
[](char a, char b) { return std::tolower(a) == std::tolower(b); }); |
| 45 |
} |
| 46 |
|
| 47 |
void parse_variable_names(const char *tokens, Excn::StringIdVector *variable_list); |
| 48 |
std::string find_matching_file(const std::string &path, const std::string &basename); |
| 49 |
} // namespace |
| 50 |
|
| 51 |
Excn::SystemInterface::SystemInterface(int rank) : myRank_(rank) { enroll_options(); } |
| 52 |
|
| 53 |
bool Excn::SystemInterface::remove_file_per_rank_files() const |
| 54 |
{ |
| 55 |
if (removeFilePerRankFiles_) { |
| 56 |
if (partCount_ <= 0 && startPart_ == 0 && subcycle_ == -1 && cycle_ == -1) { |
| 57 |
return true; |
| 58 |
} |
| 59 |
else { |
| 60 |
fmt::print("\nNot removing the file-per-rank input files due to presence of " |
| 61 |
"start/part/subcycle options.\n\n"); |
| 62 |
return false; |
| 63 |
} |
| 64 |
} |
| 65 |
else { |
| 66 |
return false; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
void Excn::SystemInterface::enroll_options() |
| 71 |
{ |
| 72 |
options_.usage("[options] basename"); |
| 73 |
|
| 74 |
options_.enroll("help", GetLongOption::NoValue, "Print this summary and exit", nullptr); |
| 75 |
|
| 76 |
options_.enroll("version", GetLongOption::NoValue, "Print version and exit", nullptr, nullptr, |
| 77 |
true); |
| 78 |
|
| 79 |
options_.enroll("auto", GetLongOption::NoValue, |
| 80 |
"Automatically set Root, Proc, Ext from filename 'Root/basename.ext.#p.00'.", |
| 81 |
nullptr); |
| 82 |
options_.enroll("extension", GetLongOption::MandatoryValue, |
| 83 |
"Exodus database extension for the input files", "e"); |
| 84 |
|
| 85 |
options_.enroll("output_extension", GetLongOption::MandatoryValue, |
| 86 |
"Exodus database extension for the output file", nullptr); |
| 87 |
|
| 88 |
options_.enroll("processor_count", GetLongOption::MandatoryValue, "Number of processors", "1"); |
| 89 |
|
| 90 |
options_.enroll("current_directory", GetLongOption::MandatoryValue, "Current Directory", "."); |
| 91 |
|
| 92 |
options_.enroll("Root_directory", GetLongOption::MandatoryValue, "Root directory", nullptr); |
| 93 |
|
| 94 |
options_.enroll("Subdirectory", GetLongOption::MandatoryValue, |
| 95 |
"subdirectory containing input exodusII files", nullptr, nullptr, true); |
| 96 |
|
| 97 |
options_.enroll("subcycle", GetLongOption::OptionalValue, |
| 98 |
"Subcycle. Create $val subparts if $val is specified.\n" |
| 99 |
"\t\tOtherwise, create multiple parts each of size 'Part_count'.\n" |
| 100 |
"\t\tThe subparts can then be joined by a subsequent run of epu.\n" |
| 101 |
"\t\tUseful if the maximum number of open files is less\n" |
| 102 |
"\t\tthan the processor count.", |
| 103 |
nullptr, "0"); |
| 104 |
|
| 105 |
options_.enroll("join_subcycles", GetLongOption::NoValue, |
| 106 |
"If -subcycle is specified, then after the subcycle files are processed,\n" |
| 107 |
"\t\trun epu one more time and join the subcycle files into a single file.", |
| 108 |
nullptr); |
| 109 |
|
| 110 |
options_.enroll("Part_count", GetLongOption::MandatoryValue, |
| 111 |
"How many pieces (files) of the model should be joined.", "0"); |
| 112 |
|
| 113 |
options_.enroll("start_part", GetLongOption::MandatoryValue, "Start with piece {L} (file)", "0"); |
| 114 |
|
| 115 |
options_.enroll("cycle", GetLongOption::MandatoryValue, |
| 116 |
"Cycle number. If subcycle # is specified, then only execute\n" |
| 117 |
"\t\tcycle $val ($val < #). The cycle number is 0-based.", |
| 118 |
"-1"); |
| 119 |
|
| 120 |
options_.enroll("select_change_set", GetLongOption::MandatoryValue, |
| 121 |
"Specify the change set to be read from the input file(s).\n" |
| 122 |
"\t\tThe change_set number is 1-based.", |
| 123 |
"-1", nullptr, true); |
| 124 |
|
| 125 |
options_.enroll("keep_temporary", GetLongOption::NoValue, |
| 126 |
"If -join_subcycles is specified, then after joining the subcycle files,\n" |
| 127 |
"\t\tthey are automatically deleted unless -keep_temporary is specified.", |
| 128 |
nullptr); |
| 129 |
|
| 130 |
options_.enroll("remove_file_per_rank_files", GetLongOption::NoValue, |
| 131 |
"Remove the input file-per-rank files after they have successfully been joined.", |
| 132 |
nullptr); |
| 133 |
|
| 134 |
options_.enroll( |
| 135 |
"verify_valid_file", GetLongOption::NoValue, |
| 136 |
"Reopen the output file right after closing it to verify that the file is valid.\n" |
| 137 |
"\t\tThis tries to detect file corruption immediately instead of later.\n" |
| 138 |
"\t\t Mainly useful in large subcycle runs.", |
| 139 |
nullptr, nullptr, true); |
| 140 |
|
| 141 |
options_.enroll("map", GetLongOption::NoValue, |
| 142 |
"Map element ids to original order if possible [default]", nullptr); |
| 143 |
|
| 144 |
options_.enroll("nomap", GetLongOption::NoValue, "Do not map element ids to original order", |
| 145 |
nullptr, nullptr, true); |
| 146 |
|
| 147 |
options_.enroll("netcdf4", GetLongOption::NoValue, |
| 148 |
"Output database uses HDF5-based netcdf which allows for up to 2.1 billion " |
| 149 |
"nodes/elements", |
| 150 |
nullptr); |
| 151 |
|
| 152 |
options_.enroll("netcdf5", GetLongOption::NoValue, |
| 153 |
"Output database uses PnetCDF netcdf 5 format which allows for up to 2.1 billion " |
| 154 |
"nodes/elements", |
| 155 |
nullptr); |
| 156 |
|
| 157 |
options_.enroll("64", GetLongOption::NoValue, |
| 158 |
"The output database will be written in the 64-bit integer mode which allows\n" |
| 159 |
"\t\tfor more than 2.1 billion nodes/elements", |
| 160 |
nullptr, nullptr, true); |
| 161 |
|
| 162 |
options_.enroll( |
| 163 |
"zlib", GetLongOption::NoValue, |
| 164 |
"Use the Zlib / libz compression method if compression is enabled (default) [exodus only].", |
| 165 |
nullptr); |
| 166 |
|
| 167 |
options_.enroll("szip", GetLongOption::NoValue, |
| 168 |
"Use SZip compression. [exodus only, enables netcdf-4]", nullptr); |
| 169 |
|
| 170 |
options_.enroll("zstd", GetLongOption::NoValue, |
| 171 |
"Use Zstd compression. [exodus only, enables netcdf-4, experimental]", nullptr); |
| 172 |
|
| 173 |
options_.enroll("bzip2", GetLongOption::NoValue, |
| 174 |
"Use Bzip2 compression. [exodus only, enables netcdf-4, experimental]", nullptr); |
| 175 |
|
| 176 |
options_.enroll("compress", GetLongOption::MandatoryValue, |
| 177 |
"Specify the compression level to be used. Values depend on algorithm:\n" |
| 178 |
"\t\tzlib/bzip2: 0..9\t\tszip: even, 4..32\t\tzstd: -131072..22", |
| 179 |
nullptr); |
| 180 |
|
| 181 |
options_.enroll("quantize_nsd", GetLongOption::MandatoryValue, |
| 182 |
"Use the lossy quantize compression method.\n" |
| 183 |
"\t\tValue specifies number of digits to retain (1..15) [exodus only]", |
| 184 |
nullptr, nullptr, true); |
| 185 |
|
| 186 |
options_.enroll("append", GetLongOption::NoValue, |
| 187 |
"Append to database instead of opening a new database.\n" |
| 188 |
"\t\tTimestep transfer will start after last timestep on database", |
| 189 |
nullptr); |
| 190 |
|
| 191 |
options_.enroll("steps", GetLongOption::MandatoryValue, |
| 192 |
"Specify subset of timesteps to transfer to output file.\n" |
| 193 |
"\t\tFormat is beg:end:step. 1:10:2 --> 1,3,5,7,9\n" |
| 194 |
"\t\tIf the 'beg' or 'end' is < 0, then it is the \"-Nth\" step...\n" |
| 195 |
"\t\t-1 is \"first last\" or last, -3 is \"third last\"\n" |
| 196 |
"\t\tTo copy just the last 3 steps, do: `-steps -3:-1`\n" |
| 197 |
"\t\tEnter LAST for last step", |
| 198 |
"1:", nullptr, true); |
| 199 |
|
| 200 |
options_.enroll( |
| 201 |
"add_nodal_communication_map", GetLongOption::NoValue, |
| 202 |
"In subcycle mode, add the `nodal communication map` data to the output files.\n" |
| 203 |
"\t\tThe resulting files can then be used as input to a subsequent analysis (N to M)", |
| 204 |
nullptr); |
| 205 |
|
| 206 |
options_.enroll("add_processor_id", GetLongOption::NoValue, |
| 207 |
"Add element variable named 'processor_id' to the output file which shows the\n" |
| 208 |
"\t\tprocessor that an element was on in the decomposed mesh.\n" |
| 209 |
"\t\tCan be used by SLICE or auto-decomp to reproduce decomposition.", |
| 210 |
nullptr); |
| 211 |
|
| 212 |
options_.enroll("add_map_processor_id", GetLongOption::NoValue, |
| 213 |
"Add element map named 'processor_id' to the output file which shows the\n" |
| 214 |
"\t\tprocessor that an element was on in the decomposed mesh.\n" |
| 215 |
"\t\tCan be used by SLICE or auto-decomp to reproduce decomposition.", |
| 216 |
nullptr, nullptr, true); |
| 217 |
|
| 218 |
options_.enroll("gvar", GetLongOption::MandatoryValue, |
| 219 |
"Comma-separated list of global variables to be joined or ALL or NONE.", nullptr); |
| 220 |
|
| 221 |
options_.enroll("evar", GetLongOption::MandatoryValue, |
| 222 |
"Comma-separated list of element variables to be joined or ALL or NONE.\n" |
| 223 |
"\t\tVariables can be limited to certain blocks by appending a\n" |
| 224 |
"\t\tcolon followed by the block id. E.g. -evar sigxx:10:20", |
| 225 |
nullptr); |
| 226 |
|
| 227 |
options_.enroll("nvar", GetLongOption::MandatoryValue, |
| 228 |
"Comma-separated list of nodal variables to be joined or ALL or NONE.", nullptr); |
| 229 |
|
| 230 |
options_.enroll("nsetvar", GetLongOption::MandatoryValue, |
| 231 |
"Comma-separated list of nodeset variables to be joined or ALL or NONE.", |
| 232 |
nullptr); |
| 233 |
|
| 234 |
options_.enroll("ssetvar", GetLongOption::MandatoryValue, |
| 235 |
"Comma-separated list of sideset variables to be joined or ALL or NONE.", |
| 236 |
nullptr); |
| 237 |
|
| 238 |
options_.enroll("edblkvar", GetLongOption::MandatoryValue, |
| 239 |
"Comma-separated list of edgeblock variables to be joined or ALL or NONE.", |
| 240 |
nullptr); |
| 241 |
|
| 242 |
options_.enroll("fablkvar", GetLongOption::MandatoryValue, |
| 243 |
"Comma-separated list of faceblock variables to be joined or ALL or NONE.", |
| 244 |
nullptr, nullptr, true); |
| 245 |
|
| 246 |
options_.enroll("omit_nodesets", GetLongOption::NoValue, |
| 247 |
"Don't transfer nodesets to output file.", nullptr); |
| 248 |
|
| 249 |
options_.enroll("omit_sidesets", GetLongOption::NoValue, |
| 250 |
"Don't transfer sidesets to output file.", nullptr); |
| 251 |
|
| 252 |
options_.enroll("omit_edgeblocks", GetLongOption::NoValue, |
| 253 |
"Don't transfer edgeblocks to output file.", nullptr); |
| 254 |
|
| 255 |
options_.enroll("omit_faceblocks", GetLongOption::NoValue, |
| 256 |
"Don't transfer faceblocks to output file.", nullptr, nullptr, true); |
| 257 |
|
| 258 |
options_.enroll("debug", GetLongOption::MandatoryValue, |
| 259 |
"debug level (values are or'd)\n" |
| 260 |
"\t\t 1 = timing information.\n" |
| 261 |
"\t\t 2 = Check consistent nodal field values between processors.\n" |
| 262 |
"\t\t 4 = Verbose Element block information.\n" |
| 263 |
"\t\t 8 = Check consistent nodal coordinates between processors.\n" |
| 264 |
"\t\t 16 = Verbose Sideset information.\n" |
| 265 |
"\t\t 32 = Verbose Nodeset information.\n" |
| 266 |
"\t\t 64 = Verbose Edge block information.\n" |
| 267 |
"\t\t128 = Verbose Face block information.\n" |
| 268 |
"\t\t256 = put exodus library into verbose mode.\n" |
| 269 |
"\t\t512 = Check consistent global field values between processors.", |
| 270 |
"0"); |
| 271 |
|
| 272 |
options_.enroll("sum_shared_nodes", GetLongOption::NoValue, |
| 273 |
"[Rare, special case]\n" |
| 274 |
"\t\tThe nodal results data on all shared nodes (nodes on processor boundaries)\n" |
| 275 |
"\t\twill be the sum of the individual nodal results data on each shared node.\n" |
| 276 |
"\t\tThe default behavior assumes that the values are equal.", |
| 277 |
nullptr); |
| 278 |
|
| 279 |
options_.enroll( |
| 280 |
"output_shared_nodes", GetLongOption::NoValue, |
| 281 |
"[Debugging] Output list of shared nodes and the processors they are shared with.", nullptr); |
| 282 |
|
| 283 |
options_.enroll("width", GetLongOption::MandatoryValue, "Width of output screen, default = 80", |
| 284 |
nullptr); |
| 285 |
|
| 286 |
options_.enroll("max_open_files", GetLongOption::MandatoryValue, |
| 287 |
"For testing auto subcycle only. Sets file limit that triggers auto subcycling.", |
| 288 |
"0"); |
| 289 |
|
| 290 |
options_.enroll("large_model", GetLongOption::NoValue, "[deprecated; use netcdf4 instead]", |
| 291 |
nullptr); |
| 292 |
|
| 293 |
options_.enroll("copyright", GetLongOption::NoValue, "Show copyright and license data.", nullptr); |
| 294 |
} |
| 295 |
|
| 296 |
bool Excn::SystemInterface::parse_options(int argc, char **argv) |
| 297 |
{ |
| 298 |
// Get options from environment variable also... |
| 299 |
char *options = getenv("EPU_OPTIONS"); |
| 300 |
if (options != nullptr) { |
| 301 |
if (myRank_ == 0) { |
| 302 |
fmt::print( |
| 303 |
"\nThe following options were specified via the EPU_OPTIONS environment variable:\n" |
| 304 |
"\t{}\n\n", |
| 305 |
options); |
| 306 |
} |
| 307 |
options_.parse(options, GetLongOption::basename(*argv)); |
| 308 |
} |
| 309 |
|
| 310 |
int option_index = options_.parse(argc, argv); |
| 311 |
if (option_index < 1) { |
| 312 |
throw std::runtime_error("ERROR: (EPU) No arguments specified."); |
| 313 |
} |
| 314 |
|
| 315 |
if (options_.retrieve("help") != nullptr) { |
| 316 |
if (myRank_ == 0) { |
| 317 |
options_.usage(); |
| 318 |
fmt::print("\n\tCan also set options via EPU_OPTIONS environment variable.\n\n" |
| 319 |
"\tWrites: current_directory/basename.output_suf\n" |
| 320 |
"\tReads: root/sub/basename.suf.#p.0 to\n" |
| 321 |
"\t\troot/sub/basename.suf.#p.#p-1\n" |
| 322 |
"\n\t->->-> Send email to [email protected] for epu support.<-<-<-\n"); |
| 323 |
} |
| 324 |
return false; |
| 325 |
} |
| 326 |
|
| 327 |
if (options_.retrieve("version") != nullptr) { |
| 328 |
// Version is printed up front, just exit... |
| 329 |
return false; |
| 330 |
} |
| 331 |
|
| 332 |
inExtension_ = options_.get_option_value("extension", inExtension_); |
| 333 |
outExtension_ = options_.get_option_value("output_extension", outExtension_); |
| 334 |
processorCount_ = options_.get_option_value("processor_count", processorCount_); |
| 335 |
partCount_ = options_.get_option_value("Part_count", partCount_); |
| 336 |
startPart_ = options_.get_option_value("start_part", startPart_); |
| 337 |
maxOpenFiles_ = options_.get_option_value("max_open_files", maxOpenFiles_); |
| 338 |
cwd_ = options_.get_option_value("current_directory", cwd_); |
| 339 |
rootDirectory_ = options_.get_option_value("Root_directory", rootDirectory_); |
| 340 |
subDirectory_ = options_.get_option_value("Subdirectory", subDirectory_); |
| 341 |
debugLevel_ = options_.get_option_value("debug", debugLevel_); |
| 342 |
|
| 343 |
screenWidth_ = options_.get_option_value("width", term_width()); |
| 344 |
|
| 345 |
{ |
| 346 |
const char *temp = options_.retrieve("steps"); |
| 347 |
if (temp != nullptr) { |
| 348 |
parse_step_option(temp); |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
{ |
| 353 |
const char *temp = options_.retrieve("gvar"); |
| 354 |
parse_variable_names(temp, &globalVarNames_); |
| 355 |
} |
| 356 |
|
| 357 |
{ |
| 358 |
const char *temp = options_.retrieve("nvar"); |
| 359 |
parse_variable_names(temp, &nodeVarNames_); |
| 360 |
} |
| 361 |
|
| 362 |
{ |
| 363 |
const char *temp = options_.retrieve("evar"); |
| 364 |
parse_variable_names(temp, &elemVarNames_); |
| 365 |
} |
| 366 |
|
| 367 |
{ |
| 368 |
const char *temp = options_.retrieve("nsetvar"); |
| 369 |
parse_variable_names(temp, &nsetVarNames_); |
| 370 |
} |
| 371 |
|
| 372 |
{ |
| 373 |
const char *temp = options_.retrieve("ssetvar"); |
| 374 |
parse_variable_names(temp, &ssetVarNames_); |
| 375 |
} |
| 376 |
|
| 377 |
{ |
| 378 |
const char *temp = options_.retrieve("edblkvar"); |
| 379 |
parse_variable_names(temp, &edblkVarNames_); |
| 380 |
} |
| 381 |
|
| 382 |
{ |
| 383 |
const char *temp = options_.retrieve("fablkvar"); |
| 384 |
parse_variable_names(temp, &fablkVarNames_); |
| 385 |
} |
| 386 |
|
| 387 |
addProcessorIdField_ = options_.retrieve("add_processor_id") != nullptr; |
| 388 |
addProcessorIdMap_ = options_.retrieve("add_map_processor_id") != nullptr; |
| 389 |
addNodalCommunicationMap_ = options_.retrieve("add_nodal_communication_map") != nullptr; |
| 390 |
|
| 391 |
if (options_.retrieve("large_model") != nullptr) { |
| 392 |
useNetcdf4_ = true; |
| 393 |
fmt::print(stderr, |
| 394 |
"\nWARNING: the -large_model option is deprecated; please use -netcdf4 instead.\n"); |
| 395 |
} |
| 396 |
|
| 397 |
useNetcdf4_ = options_.retrieve("netcdf4") != nullptr; |
| 398 |
useNetcdf5_ = options_.retrieve("netcdf5") != nullptr; |
| 399 |
append_ = options_.retrieve("append") != nullptr; |
| 400 |
intIs64Bit_ = options_.retrieve("64") != nullptr; |
| 401 |
|
| 402 |
zlib_ = (options_.retrieve("zlib") != nullptr); |
| 403 |
szip_ = (options_.retrieve("szip") != nullptr); |
| 404 |
zstd_ = (options_.retrieve("zstd") != nullptr); |
| 405 |
bz2_ = (options_.retrieve("bzip2") != nullptr); |
| 406 |
|
| 407 |
if ((szip_ ? 1 : 0) + (zlib_ ? 1 : 0) + (zstd_ ? 1 : 0) + (bz2_ ? 1 : 0) > 1) { |
| 408 |
fmt::print(stderr, |
| 409 |
"ERROR: Only one of 'szip' or 'zlib' or 'zstd' or 'bzip2' can be specified.\n"); |
| 410 |
} |
| 411 |
|
| 412 |
{ |
| 413 |
const char *temp = options_.retrieve("compress"); |
| 414 |
if (temp != nullptr) { |
| 415 |
compressionLevel_ = std::strtol(temp, nullptr, 10); |
| 416 |
if (!szip_ && !zlib_ && !zstd_ && !bz2_) { |
| 417 |
zlib_ = true; |
| 418 |
} |
| 419 |
|
| 420 |
if (zlib_ || bz2_) { |
| 421 |
if (compressionLevel_ < 0 || compressionLevel_ > 9) { |
| 422 |
fmt::print(stderr, |
| 423 |
"ERROR: Bad compression level {}, valid value is between 0 and 9 inclusive " |
| 424 |
"for gzip/zlib compression.\n", |
| 425 |
compressionLevel_); |
| 426 |
return false; |
| 427 |
} |
| 428 |
} |
| 429 |
else if (szip_) { |
| 430 |
if (compressionLevel_ % 2 != 0) { |
| 431 |
fmt::print( |
| 432 |
stderr, |
| 433 |
"ERROR: Bad compression level {}. Must be an even value for szip compression.\n", |
| 434 |
compressionLevel_); |
| 435 |
return false; |
| 436 |
} |
| 437 |
if (compressionLevel_ < 4 || compressionLevel_ > 32) { |
| 438 |
fmt::print(stderr, |
| 439 |
"ERROR: Bad compression level {}, valid value is between 4 and 32 inclusive " |
| 440 |
"for szip compression.\n", |
| 441 |
compressionLevel_); |
| 442 |
return false; |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
{ |
| 449 |
const char *temp = options_.retrieve("quantize_nsd"); |
| 450 |
if (temp != nullptr) { |
| 451 |
quantizeNSD_ = std::strtol(temp, nullptr, 10); |
| 452 |
if (!szip_ && !zlib_ && !zstd_ && !bz2_) { |
| 453 |
zlib_ = true; |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
sumSharedNodes_ = options_.retrieve("sum_shared_nodes") != nullptr; |
| 459 |
append_ = options_.retrieve("append") != nullptr; |
| 460 |
|
| 461 |
subcycle_ = options_.get_option_value("subcycle", subcycle_); |
| 462 |
cycle_ = options_.get_option_value("cycle", cycle_); |
| 463 |
subcycleJoin_ = options_.retrieve("join_subcycles") != nullptr; |
| 464 |
keepTemporary_ = options_.retrieve("keep_temporary") != nullptr; |
| 465 |
removeFilePerRankFiles_ = options_.retrieve("remove_file_per_rank_files") != nullptr; |
| 466 |
selectedChangeSet_ = options_.get_option_value("select_change_set", selectedChangeSet_); |
| 467 |
verifyValidFile_ = options_.retrieve("verify_valid_file") != nullptr; |
| 468 |
|
| 469 |
if (options_.retrieve("map") != nullptr) { |
| 470 |
mapIds_ = true; |
| 471 |
} |
| 472 |
|
| 473 |
if (options_.retrieve("nomap") != nullptr) { |
| 474 |
mapIds_ = false; |
| 475 |
} |
| 476 |
|
| 477 |
omitNodesets_ = options_.retrieve("omit_nodesets") != nullptr; |
| 478 |
omitSidesets_ = options_.retrieve("omit_sidesets") != nullptr; |
| 479 |
omitEdgeBlocks_ = options_.retrieve("omit_edgeblocks") != nullptr; |
| 480 |
omitFaceBlocks_ = options_.retrieve("omit_faceblocks") != nullptr; |
| 481 |
outputSharedNodes_ = options_.retrieve("output_shared_nodes") != nullptr; |
| 482 |
|
| 483 |
if (options_.retrieve("copyright") != nullptr) { |
| 484 |
if (myRank_ == 0) { |
| 485 |
fmt::print("{}", copyright("2010-2022")); |
| 486 |
} |
| 487 |
return false; |
| 488 |
} |
| 489 |
|
| 490 |
// Parse remaining options as directory paths. |
| 491 |
if (option_index < argc) { |
| 492 |
basename_ = argv[option_index]; |
| 493 |
|
| 494 |
if (options_.retrieve("auto") != nullptr) { |
| 495 |
// Determine Root, Proc, Extension, and Basename automatically |
| 496 |
// by parsing the basename_ entered by the user. Assumed to be |
| 497 |
// in the form: "/directory/sub/basename.ext.#proc.34" |
| 498 |
FileInfo file(basename_); |
| 499 |
auto path = file.pathname(); |
| 500 |
if (path.empty()) { |
| 501 |
path = "."; |
| 502 |
} |
| 503 |
#if defined(__SUP_WINDOWS__) |
| 504 |
rootDirectory_ = _fullpath(nullptr, path.c_str(), _MAX_PATH); |
| 505 |
#else |
| 506 |
char *tmp = ::realpath(path.c_str(), nullptr); |
| 507 |
if (tmp != nullptr) { |
| 508 |
rootDirectory_ = std::string(tmp); |
| 509 |
free(tmp); |
| 510 |
} |
| 511 |
#endif |
| 512 |
|
| 513 |
basename_ = file.tailname(); |
| 514 |
if (basename_.empty()) { |
| 515 |
std::ostringstream errmsg; |
| 516 |
fmt::print( |
| 517 |
errmsg, |
| 518 |
"\nERROR: (EPU) If the '-auto' option is specified, the basename must specify an " |
| 519 |
"existing filename or portion of a base of a filename (no rank/proc count).\n" |
| 520 |
" The entered basename ('{}') does not contain a filename.\n", |
| 521 |
basename_); |
| 522 |
throw std::runtime_error(errmsg.str()); |
| 523 |
} |
| 524 |
bool success = decompose_filename(basename_); |
| 525 |
if (!success) { |
| 526 |
// See if we can find files that match the basename and take the first match as the "new" |
| 527 |
// basename... |
| 528 |
std::string candidate = find_matching_file(rootDirectory_, basename_); |
| 529 |
if (!candidate.empty()) { |
| 530 |
basename_ = candidate; |
| 531 |
success = decompose_filename(basename_); |
| 532 |
if (!success) { |
| 533 |
std::ostringstream errmsg; |
| 534 |
fmt::print( |
| 535 |
errmsg, |
| 536 |
"\nERROR: (EPU) If the '-auto' option is specified, the basename must specify an " |
| 537 |
"existing filename or a basename (no rank/proc count).\n" |
| 538 |
" The entered basename ('{}') does not contain an extension or processor " |
| 539 |
"count.\n", |
| 540 |
basename_); |
| 541 |
throw std::runtime_error(errmsg.str()); |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
auto_ = true; |
| 546 |
if (myRank_ == 0) { |
| 547 |
fmt::print("\nThe following options were determined automatically:\n" |
| 548 |
"\t basename = '{}'\n" |
| 549 |
"\t-processor_count {}\n" |
| 550 |
"\t-extension {}\n" |
| 551 |
"\t-Root_directory {}\n\n", |
| 552 |
basename_, processorCount_, inExtension_, rootDirectory_); |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
else { |
| 557 |
throw std::runtime_error("\nERROR: (EPU) basename not specified\n"); |
| 558 |
} |
| 559 |
|
| 560 |
// Check that subcycle count does not match processor count -- |
| 561 |
// in that case the existing files will be overwritten. |
| 562 |
if (processorCount_ <= subcycle_) { |
| 563 |
if (myRank_ == 0) { |
| 564 |
fmt::print(stderr, |
| 565 |
"\nERROR: (EPU) Invalid subcycle count specified: '{}'." |
| 566 |
"\n Must be less than processor count '{}'.\n\n", |
| 567 |
subcycle_, processorCount_); |
| 568 |
} |
| 569 |
return false; |
| 570 |
} |
| 571 |
|
| 572 |
// If subcycle is specified, but not part_count, then calculate partCount_ |
| 573 |
if (partCount_ <= 0 && subcycle_ > 0) { |
| 574 |
partCount_ = processorCount_ / subcycle_; |
| 575 |
} |
| 576 |
|
| 577 |
return true; |
| 578 |
} |
| 579 |
|
| 580 |
void Excn::SystemInterface::dump(std::ostream & /*unused*/) const {} |
| 581 |
|
| 582 |
std::string Excn::SystemInterface::output_suffix() const |
| 583 |
{ |
| 584 |
if (outExtension_.empty()) { |
| 585 |
return inExtension_; |
| 586 |
} |
| 587 |
return outExtension_; |
| 588 |
} |
| 589 |
|
| 590 |
void Excn::SystemInterface::show_version(int rank) |
| 591 |
{ |
| 592 |
if (rank == 0) { |
| 593 |
fmt::print("{}\n" |
| 594 |
"\t(Out of Many One -- see http://www.greatseal.com/mottoes/unum.html)\n" |
| 595 |
"\tExodusII Parallel Unification Program\n" |
| 596 |
"\t(Version: {}) Modified: {}\n", |
| 597 |
qainfo[0], qainfo[1], qainfo[2]); |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
void Excn::SystemInterface::parse_step_option(const char *tokens) |
| 602 |
{ |
| 603 |
//: The defined formats for the count attribute are:<br> |
| 604 |
//: <ul> |
| 605 |
//: <li><missing> -- default -- 1 <= count <= oo (all steps)</li> |
| 606 |
//: <li>"X" -- X <= count <= X (just step X) LAST for last step.</li> |
| 607 |
//: <li>"X:Y" -- X to Y by 1</li> |
| 608 |
//: <li>"X:" -- X to oo by 1</li> |
| 609 |
//: <li>":Y" -- 1 to Y by 1</li> |
| 610 |
//: <li>"::Z" -- 1 to oo by Z</li> |
| 611 |
//: </ul> |
| 612 |
//: The step must always be > 0 |
| 613 |
//: If the 'from' or 'to' is < 0, then it is the "-Nth" step... |
| 614 |
//: -1 is "first last" or last |
| 615 |
//: -4 is "fourth last step" |
| 616 |
//: To copy just the last 3 steps, do: `-steps -3:-1` |
| 617 |
|
| 618 |
// Break into tokens separated by ":" |
| 619 |
|
| 620 |
// Default is given in constructor above... |
| 621 |
|
| 622 |
if (tokens != nullptr) { |
| 623 |
if (strchr(tokens, ':') != nullptr) { |
| 624 |
// The string contains a separator |
| 625 |
|
| 626 |
std::array<int, 3> vals{stepMin_, stepMax_, stepInterval_}; |
| 627 |
|
| 628 |
int j = 0; |
| 629 |
for (auto &val : vals) { |
| 630 |
// Parse 'i'th field |
| 631 |
char tmp_str[128]; |
| 632 |
|
| 633 |
int k = 0; |
| 634 |
while (tokens[j] != '\0' && tokens[j] != ':') { |
| 635 |
tmp_str[k++] = tokens[j++]; |
| 636 |
} |
| 637 |
|
| 638 |
tmp_str[k] = '\0'; |
| 639 |
if (strlen(tmp_str) > 0) { |
| 640 |
val = strtol(tmp_str, nullptr, 0); |
| 641 |
} |
| 642 |
|
| 643 |
if (tokens[j++] == '\0') { |
| 644 |
break; // Reached end of string |
| 645 |
} |
| 646 |
} |
| 647 |
stepMin_ = vals[0]; |
| 648 |
stepMax_ = vals[1]; |
| 649 |
stepInterval_ = abs(vals[2]); // step is always positive... |
| 650 |
} |
| 651 |
else if (str_equal("LAST", tokens)) { |
| 652 |
stepMin_ = stepMax_ = -1; |
| 653 |
} |
| 654 |
else { |
| 655 |
// Does not contain a separator, min == max |
| 656 |
stepMin_ = stepMax_ = strtol(tokens, nullptr, 0); |
| 657 |
} |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
bool Excn::SystemInterface::decompose_filename(const std::string &cs) |
| 662 |
{ |
| 663 |
std::string s(cs); |
| 664 |
// Decompose the input string 's' into processor count, extension, basename, and root. |
| 665 |
// Input string should be of the form: |
| 666 |
// "root/basename.ext.proc.nn" |
| 667 |
// 'root/' is optional and is all characters preceding the last (if any) '/'; |
| 668 |
// 'basename' can contain multiple '.' |
| 669 |
|
| 670 |
// NOTE: This used to use the tokenize function, but that didn't work since we need |
| 671 |
// to handle leading and embedded '..' which tokenize threw away... |
| 672 |
|
| 673 |
// Get rid of the 'nn' which is not used at this time... |
| 674 |
size_t ind = s.find_last_of('.', std::string::npos); // last '.' |
| 675 |
if (ind == std::string::npos) { |
| 676 |
return false; |
| 677 |
} |
| 678 |
s.erase(ind); |
| 679 |
|
| 680 |
// Now find the processor count... |
| 681 |
ind = s.find_last_of('.', std::string::npos); |
| 682 |
if (ind == std::string::npos) { |
| 683 |
return false; |
| 684 |
} |
| 685 |
|
| 686 |
std::string tmp = s.substr(ind + 1); // Skip the '.' |
| 687 |
processorCount_ = std::stoi(tmp); |
| 688 |
if (processorCount_ <= 0) { |
| 689 |
fmt::print( |
| 690 |
stderr, |
| 691 |
"\nERROR: (EPU) Invalid processor count specified: '{}'. Must be greater than zero.\n", |
| 692 |
processorCount_); |
| 693 |
return false; |
| 694 |
} |
| 695 |
s.erase(ind); |
| 696 |
|
| 697 |
// Should now be an extension... |
| 698 |
ind = s.find_last_of('.', std::string::npos); |
| 699 |
if (ind == std::string::npos) { |
| 700 |
inExtension_ = ""; |
| 701 |
} |
| 702 |
else { |
| 703 |
inExtension_ = s.substr(ind + 1); |
| 704 |
s.erase(ind); |
| 705 |
} |
| 706 |
|
| 707 |
// The directory path was stripped prior to entering this function, |
| 708 |
// so remainder of 's' is just the new basename_ |
| 709 |
basename_ = s; |
| 710 |
return true; |
| 711 |
} |
| 712 |
|
| 713 |
namespace { |
| 714 |
std::string LowerCase(const std::string &name) |
| 715 |
{ |
| 716 |
std::string s = name; |
| 717 |
std::transform(s.begin(), s.end(), // source |
| 718 |
s.begin(), // destination |
| 719 |
::tolower); // operation |
| 720 |
return s; |
| 721 |
} |
| 722 |
|
| 723 |
using StringVector = std::vector<std::string>; |
| 724 |
|
| 725 |
void parse_variable_names(const char *tokens, Excn::StringIdVector *variable_list) |
| 726 |
{ |
| 727 |
// Break into tokens separated by "," |
| 728 |
|
| 729 |
// Value of num_vars includes optional add_processor_id |
| 730 |
|
| 731 |
if (tokens != nullptr) { |
| 732 |
std::string token_string(tokens); |
| 733 |
StringVector var_list = SLIB::tokenize(token_string, ","); |
| 734 |
|
| 735 |
// At this point, var_list is either a single string, or a string |
| 736 |
// separated from 1 or more block ids with ":" delimiter. |
| 737 |
// For example, sigxx:1:10:100 would indicate that the variable |
| 738 |
// "sigxx" should be written only for blocks with id 1, 10, and |
| 739 |
// 100. "sigxx" would indicate that the variable should be |
| 740 |
// written for all blocks. |
| 741 |
auto I = var_list.begin(); |
| 742 |
while (I != var_list.end()) { |
| 743 |
StringVector name_id = SLIB::tokenize(*I, ":"); |
| 744 |
std::string var_name = LowerCase(name_id[0]); |
| 745 |
if (name_id.size() == 1) { |
| 746 |
(*variable_list).emplace_back(var_name, 0); |
| 747 |
} |
| 748 |
else { |
| 749 |
for (size_t i = 1; i < name_id.size(); i++) { |
| 750 |
// Convert string to integer... |
| 751 |
int id = std::stoi(name_id[i]); |
| 752 |
(*variable_list).emplace_back(var_name, id); |
| 753 |
} |
| 754 |
} |
| 755 |
++I; |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
std::string find_matching_file(const std::string &path, const std::string &basename) |
| 761 |
{ |
| 762 |
glob::glob g(basename + ".*.*"); |
| 763 |
#if !defined(__SUP_WINDOWS__) |
| 764 |
struct dirent *entry = nullptr; |
| 765 |
DIR *dp = nullptr; |
| 766 |
|
| 767 |
dp = opendir(path.c_str()); |
| 768 |
if (dp != nullptr) { |
| 769 |
while ((entry = readdir(dp))) { |
| 770 |
std::string filename = entry->d_name; |
| 771 |
if (glob::glob_match(filename, g)) { |
| 772 |
closedir(dp); |
| 773 |
return filename; |
| 774 |
} |
| 775 |
} |
| 776 |
} |
| 777 |
closedir(dp); |
| 778 |
#endif |
| 779 |
return ""; |
| 780 |
} |
| 781 |
} // namespace |