bool Excn::ExodusFile::create_output(const SystemInterface& si, int cycle) // Create output file... { std::string curdir = si.cwd(); std::string file_prefix = si.basename(); std::string output_suffix = si.output_suffix(); outputFilename_ = file_prefix; if (!output_suffix.empty()) { outputFilename_ += "." + output_suffix; } if(curdir.length() && outputFilename_[0] != '/') { outputFilename_ = curdir + "/" + outputFilename_; } if (si.subcycle() > 1) { Excn::ParallelDisks::Create_IO_Filename(outputFilename_, cycle, si.subcycle()); } // See if output file should be opened in netcdf4 format... // Did user specify it via -netcdf4 or -large_model argument... int mode = 0; if (si.use_netcdf4()) { mode |= EX_NETCDF4; } else if (ex_large_model(fileids_[0]) == 1) { mode |= EX_LARGE_MODEL; } mode |= mode64bit_; if (si.int64()) { mode |= EX_ALL_INT64_DB; mode |= EX_ALL_INT64_API; } if (si.append()) { std::cout << "Output: '" << outputFilename_ << "' (appending)" << std::endl; float version = 0.0; mode |= EX_WRITE; outputId_ = ex_open(outputFilename_.c_str(), mode, &cpuWordSize_, &ioWordSize_, &version); } else { mode |= EX_CLOBBER; if (si.compress_data() > 0) { // Force netcdf-4 if compression is specified... mode |= EX_NETCDF4; } std::cout << "Output: '" << outputFilename_ << "'" << std::endl; outputId_ = ex_create(outputFilename_.c_str(), mode, &cpuWordSize_, &ioWordSize_); } if (outputId_ < 0) { std::cerr << "Cannot open file '" << outputFilename_ << "'" << std::endl; return false; } if (si.compress_data() > 0) { ex_set_option(outputId_, EX_OPT_COMPRESSION_LEVEL, si.compress_data()); ex_set_option(outputId_, EX_OPT_COMPRESSION_SHUFFLE, 1); } // EPU Can add a name of "processor_id_epu" which is 16 characters long. // Make sure maximumNameLength_ is at least that long... if (maximumNameLength_ < 16) maximumNameLength_ = 16; ex_set_option(outputId_, EX_OPT_MAX_NAME_LENGTH, maximumNameLength_); int int_size = si.int64() ? 8 : 4; std::cout << "IO Word sizes: " << ioWordSize_ << " bytes floating point and " << int_size << " bytes integer.\n"; return true; }
bool Excn::ExodusFile::initialize(const SystemInterface& si, int start_part, int part_count) { processorCount_ = si.processor_count(); // Total number processors partCount_ = part_count; // Total parts we are processing startPart_ = start_part; // Which one to start with SMART_ASSERT(partCount_ + startPart_ <= processorCount_)(partCount_)(startPart_)(processorCount_); // EPU always wants entity (block, set, map) ids as 64-bit quantities... mode64bit_ = EX_IDS_INT64_API; if (si.int64()) { mode64bit_ |= EX_ALL_INT64_API; // For output... mode64bit_ |= EX_ALL_INT64_DB; } // See if we can keep files open int max_files = get_free_descriptor_count(); if (partCount_ <= max_files) { keepOpen_ = true; if (si.debug() & 1) std::cout << "Files kept open... (Max open = " << max_files << ")\n\n"; } else { keepOpen_ = false; std::cout << "Single file mode... (Max open = " << max_files << ")\n" << "Consider using the -subcycle option for faster execution...\n\n"; } fileids_.resize(processorCount_); filenames_.resize(processorCount_); std::string curdir = si.cwd(); std::string file_prefix = si.basename(); std::string exodus_suffix = si.exodus_suffix(); std::string root_dir = si.root_dir(); std::string sub_dir = si.sub_dir(); ParallelDisks disks; disks.Raid_Offset(si.raid_offset()); disks.Number_of_Raids(si.raid_count()); float version = 0.0; // create exo names for(int p = 0; p < partCount_; p++) { std::string name = file_prefix; if (!exodus_suffix.empty()) { name += "." + exodus_suffix; } int proc = p + startPart_; disks.rename_file_for_mp(root_dir, sub_dir, name, proc, processorCount_); filenames_[p] = name; if (p == 0) { int cpu_word_size = sizeof(float); int io_word_size_var = 0; int mode = EX_READ; mode |= mode64bit_; int exoid = ex_open(filenames_[p].c_str(), mode, &cpu_word_size, &io_word_size_var, &version); if (exoid < 0) { std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl; return false; } int int64db = ex_int64_status(exoid) & EX_ALL_INT64_DB; if (int64db) { // If anything stored on input db as 64-bit int, then output db will have // everything stored as 64-bit ints and all API functions will use 64-bit mode64bit_ |= EX_ALL_INT64_API; mode64bit_ |= EX_ALL_INT64_DB; } int max_name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH); if (max_name_length > maximumNameLength_) maximumNameLength_ = max_name_length; ex_close(exoid); if (io_word_size_var < (int)sizeof(float)) io_word_size_var = sizeof(float); ioWordSize_ = io_word_size_var; cpuWordSize_ = io_word_size_var; } if (keepOpen_ || p == 0) { int io_word_size_var = 0; int mode = EX_READ; // All entity ids (block, sets) are read/written as 64-bit... mode |= mode64bit_; fileids_[p] = ex_open(filenames_[p].c_str(), mode, &cpuWordSize_, &io_word_size_var, &version); if (fileids_[p] < 0) { std::cerr << "Cannot open file '" << filenames_[p] << "'" << std::endl; return false; } ex_set_max_name_length(fileids_[p], maximumNameLength_); SMART_ASSERT(ioWordSize_ == io_word_size_var)(ioWordSize_)(io_word_size_var); } if (si.debug()&64 || p==0 || p==partCount_-1) { std::cout << "Input(" << p << "): '" << name.c_str() << "'" << std::endl; if (!(si.debug()&64) && p==0) std::cout << "..." << std::endl; } } if (mode64bit_ & EX_ALL_INT64_DB) { std::cout << "Input files contain 8-byte integers.\n"; si.set_int64(); } return true; }