Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic topology phase IV #481

Merged
merged 47 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
feb7c5a
IOSS: More changes to support Dynamic Topology
tokusanya Aug 15, 2024
ef77556
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Aug 15, 2024
f273e85
IOSS: Dynamic Topology changes based on code review
tokusanya Aug 16, 2024
9f82422
IOSS:: More functonality to support Dynamic Topology
tokusanya Aug 18, 2024
779e765
IOSS: Attempt to provide "change set" concept instead of "groups"
tokusanya Aug 20, 2024
e7c1db2
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Aug 20, 2024
d1b1732
IOSS: Fix compiler errors
tokusanya Aug 21, 2024
14aef54
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Aug 21, 2024
90f97ec
IOSS: Refactoring and unit test fix
tokusanya Aug 21, 2024
14be761
IOSS: Introduce concept of Change Sets
tokusanya Sep 2, 2024
4c21e0b
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Sep 3, 2024
2c71918
Hush compiler issues
tokusanya Sep 3, 2024
2791f05
Fix for Dynamic Topology unit test
tokusanya Sep 3, 2024
61236e4
Merge branch 'master' into DynamicTopology-PhaseIV
tokusanya Sep 7, 2024
2794a19
Hush more compiler warnings and address some review comments
tokusanya Sep 11, 2024
2fa97fc
Bump step-security/harden-runner from 2.9.1 to 2.10.0 (#492)
dependabot[bot] Sep 10, 2024
963c159
Lossy compression (#464)
gsjaardema Sep 11, 2024
1351b3c
Merge branch 'master' into DynamicTopology-PhaseIV
tokusanya Sep 11, 2024
bd521ac
Merge branch 'master' into DynamicTopology-PhaseIV
tokusanya Sep 23, 2024
9665d13
Bug fixes and some more refactoring
tokusanya Sep 25, 2024
dfa841c
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Sep 25, 2024
3474237
Add more functionality to support app-side DTIO
tokusanya Sep 26, 2024
4620253
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Sep 26, 2024
e0de79e
More fixes based on review comments
tokusanya Oct 3, 2024
b37d602
Merge remote-tracking branch 'upstream/master' into DynamicTopology-P…
tokusanya Oct 3, 2024
c198bc2
Merge branch 'master' into DynamicTopology-PhaseIV
gsjaardema Oct 3, 2024
4b104fd
Fix typo from previous merge
gsjaardema Oct 4, 2024
311ad5d
Fix issue with invalid exodus file pointer
gsjaardema Oct 8, 2024
0e574e4
IOSS: Remove commented out code
gsjaardema Oct 9, 2024
c258074
Merge branch 'master' into DynamicTopology-PhaseIV
gsjaardema Oct 9, 2024
2eb8964
Merge branch 'master' into DynamicTopology-PhaseIV
gsjaardema Oct 14, 2024
e289e04
Committing clang-format changes
github-actions[bot] Oct 14, 2024
ddf0161
Update io_shell.C from groups to change sets
gsjaardema Oct 14, 2024
a8f2539
Committing clang-format changes
github-actions[bot] Oct 14, 2024
73b4918
Update io_shell_ts.C
gsjaardema Oct 14, 2024
62828ef
DTIO: More fixes to support app usage
tokusanya Oct 16, 2024
523c2ef
Bump sphinx from 8.1.1 to 8.1.3 in /cmake/tribits/doc/sphinx (#523)
dependabot[bot] Oct 14, 2024
8401ace
Bump github/codeql-action from 3.26.12 to 3.26.13 (#524)
dependabot[bot] Oct 14, 2024
6eb2c06
Bump ubuntu from `b359f10` to `ab64a83` in /docker/seacas (#525)
dependabot[bot] Oct 14, 2024
915851b
Bump ubuntu from `b359f10` to `ab64a83` in /docker/exodus (#526)
dependabot[bot] Oct 14, 2024
19db1ff
CI: Add harden runner to clang-format
gdsjaar Oct 15, 2024
697207b
CI: Try different trailing whitespace [ci skip]
gdsjaar Oct 16, 2024
9d55a3f
Merge branch 'master' into DynamicTopology-PhaseIV
gsjaardema Oct 16, 2024
550a642
Committing clang-format changes
github-actions[bot] Oct 16, 2024
5eb0fb5
DTIO: Fix for bad merge and compiler complaints
tokusanya Oct 16, 2024
4626efd
DTIO: Split files into individual classes
tokusanya Oct 16, 2024
a37070b
Committing clang-format changes
github-actions[bot] Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/seacas/libraries/exodus/include/exodusII.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ enum ex_inquiry {
EX_INQ_NUM_ELEM_SET_VAR = 69, /**< number of element set variables */
EX_INQ_NUM_SIDE_SET_VAR = 70, /**< number of sideset variables */
EX_INQ_NUM_GLOBAL_VAR = 71, /**< number of global variables */
EX_INQ_FILE_FORMAT = 72, /**< netCDF file format */
EX_INQ_INVALID = -1
};

Expand Down
12 changes: 12 additions & 0 deletions packages/seacas/libraries/exodus/src/ex_inquire.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,18 @@ static int ex_inquire_internal(int exoid, int req_info, int64_t *ret_int, float
#endif
break;

case EX_INQ_FILE_FORMAT:
gsjaardema marked this conversation as resolved.
Show resolved Hide resolved
/* return netCDF file format.
*/

*ret_int = 0;
#if NC_HAS_HDF5
int nc_format = 0;
nc_inq_format(exoid, &nc_format);
*ret_int = (int)nc_format;
#endif
break;

case EX_INQ_THREADSAFE:
/* Return 1 if the library was compiled in thread-safe mode.
* Return 0 otherwise
Expand Down
359 changes: 359 additions & 0 deletions packages/seacas/libraries/ioss/src/Ioss_ChangeSet.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,359 @@
// Copyright(C) 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
// See packages/seacas/LICENSE for details

#include "Ioss_ChangeSet.h"

#include "Ioss_CodeTypes.h"
#include "Ioss_DBUsage.h"

#include "Ioss_DynamicTopology.h"
#include "Ioss_EntityBlock.h"
#include "Ioss_EntityType.h"
#include "Ioss_Field.h"
#include "Ioss_FileInfo.h"
#include "Ioss_GroupingEntity.h"
#include "Ioss_IOFactory.h"

#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/ostream.h>


#include <assert.h>


namespace {
int file_exists( const Ioss::ParallelUtils &util,
const std::string& filename,
std::string& message,
bool specifiedDecomp )
gsjaardema marked this conversation as resolved.
Show resolved Hide resolved
{
std::string filenameBase = filename;
const int par_size = util.parallel_size();
const int par_rank = util.parallel_rank();

if( par_size > 1 && !specifiedDecomp ) {
filenameBase = Ioss::Utils::decode_filename(filenameBase, par_rank, par_size);
}

Ioss::FileInfo file = Ioss::FileInfo(filenameBase);
return file.parallel_exists(util.communicator(), message);
}

bool internal_decomp_specified(const Ioss::PropertyManager& props)
{
bool internalDecompSpecified = false;

const std::string restartDecompMethod("RESTART_DECOMPOSITION_METHOD");
gsjaardema marked this conversation as resolved.
Show resolved Hide resolved

if (props.exists(restartDecompMethod)) {
Ioss::Property prop = props.get(restartDecompMethod);
if (prop.get_string() != "EXTERNAL") {
internalDecompSpecified = true;
}
}

return internalDecompSpecified;
}

}


namespace Ioss {

ChangeSet::ChangeSet(Ioss::Region *region)
: m_database(region->get_database())
, m_ioDB(region->get_property("base_filename").get_string())
, m_dbType(region->get_property("database_type").get_string())
, m_fileCyclicCount(region->get_file_cyclic_count())
{

}

ChangeSet::ChangeSet(Ioss::DatabaseIO* db, const std::string& dbName, const std::string& dbType, unsigned fileCyclicCount)
: m_database(db)
, m_ioDB(dbName)
, m_dbType(dbType)
, m_fileCyclicCount(fileCyclicCount)
{

}

ChangeSet::~ChangeSet()
{
clear_change_sets();
}

DatabaseIO* ChangeSet::get_database() const
{
return m_database;
}

const ParallelUtils &ChangeSet::util() const
{
return get_database()->util();
}

void ChangeSet::get_cyclic_multi_file_change_sets()
{
auto db = get_database();

m_databaseFormat = CHANGE_SET_CYCLIC_MULTI_FILES;

Ioss::FileNameGenerator generator = Ioss::construct_cyclic_filename_generator(m_fileCyclicCount);

bool found = true;
int step = 0;
int fileCyclicCount = m_fileCyclicCount;

while(found && (step < fileCyclicCount)) {
++step;

std::string expanded = Ioss::expand_topology_files(generator, util(), m_ioDB,
db->get_property_manager(), step);
if(!expanded.empty()) {
m_changeSetNames.push_back(expanded);
}
else {
found = false;
}
}

m_changeSetDatabases.resize(m_changeSetNames.size(), nullptr);
}

void ChangeSet::get_linear_multi_file_change_sets()
{
auto db = get_database();

m_databaseFormat = CHANGE_SET_LINEAR_MULTI_FILES;

Ioss:: FileNameGenerator generator = Ioss::construct_linear_filename_generator();

bool found = true;
int step = 0;

while(found) {
++step;

std::string expanded = Ioss::expand_topology_files(generator, util(), m_ioDB,
db->get_property_manager(), step);
if(!expanded.empty()) {
m_changeSetNames.push_back(expanded);
}
else {
found = false;
}
}

m_changeSetDatabases.resize(m_changeSetNames.size(), nullptr);
}

void ChangeSet::populate_change_sets()
{
clear_change_sets();

if(get_file_cyclic_count() > 0) {
get_cyclic_multi_file_change_sets();
} else {
get_linear_multi_file_change_sets();
}
}

void ChangeSet::verify_change_set_index(unsigned index) const
{
if(index >= m_changeSetNames.size()) {
std::ostringstream errmsg;
fmt::print(errmsg,
"Invalid change set index {} with a max range of {}\n",
gsjaardema marked this conversation as resolved.
Show resolved Hide resolved
index, m_changeSetNames.size());
IOSS_ERROR(errmsg);
}
}

std::string ChangeSet::get_change_set_name(unsigned index) const
{
verify_change_set_index(index);

return m_changeSetNames[index];
}

void ChangeSet::close_change_set(unsigned index)
{
verify_change_set_index(index);

auto db = m_changeSetDatabases[index];
if(nullptr != db) {
db->closeDatabase();
delete db;
m_changeSetDatabases[index] = nullptr;
}
}

Ioss::DatabaseIO* ChangeSet::open_change_set(unsigned index, Ioss::DatabaseUsage usage)
{
verify_change_set_index(index);

Ioss::DatabaseIO* db = nullptr;

auto csdb = m_changeSetDatabases[index];
if(nullptr != csdb) {
if(csdb->usage() == usage) {
return csdb;
} else {
csdb->closeDatabase();
delete csdb;
m_changeSetDatabases[index] = nullptr;
}
}

// open db
const std::string& ioDB = m_changeSetNames[index];
const std::string dbType = m_dbType;

db = Ioss::IOFactory::create(dbType, ioDB, usage, util().communicator(),
get_database()->get_property_manager());
int bad_count = 0;
gsjaardema marked this conversation as resolved.
Show resolved Hide resolved
std::string error_message;
bool is_valid_file = db != nullptr && db->ok(false, &error_message, &bad_count);
if(!is_valid_file) {
delete db;
std::ostringstream errmsg;
errmsg << error_message;
errmsg << __FILE__ << ", " << __FUNCTION__ << ", filename " << ioDB << " is not a valid file\n";
IOSS_ERROR(errmsg);
}

m_changeSetDatabases[index] = db;

return db;
}

void ChangeSet::clear_change_sets()
{
m_changeSetNames.clear();

for(size_t i=0; i<m_changeSetDatabases.size(); i++) {
auto db = m_changeSetDatabases[i];
if(nullptr != db) {
db->closeDatabase();
delete db;
m_changeSetDatabases[i] = nullptr;
}
}

m_changeSetDatabases.clear();
}

std::string
expand_topology_files(FileNameGenerator generator,
const Ioss::ParallelUtils &util,
const std::string& basename,
const Ioss::PropertyManager& properties,
int step)
{
// See if there are multiple topology files

// If the file exists on all processors, return the filename.
// If the file does not exist on any processors, return "";
// If the file exists on some, but not all, throw an exception.

std::string filename = generator(basename, step);

bool internalDecompSpecified = internal_decomp_specified(properties);
std::string message;
int exists = ::file_exists(util, filename, message, internalDecompSpecified);

int par_size = util.parallel_size();
int par_rank = util.parallel_rank();

if( exists > 0 && exists < par_size ) {
std::ostringstream errmsg;
errmsg << "ERROR: Unable to open input database";
if(par_rank == 0) {
errmsg << " '" << filename << "'" << "\n\ton processor(s): " << message;
} else {
errmsg << ". See processor 0 output for more details.\n";
}
IOSS_ERROR(errmsg);
}

if( exists == par_size ) {
return filename;
}

// Does not exist on any processors
return std::string();
}

std::pair<std::string, Ioss::DatabaseIO*>
expand_topology_files(FileNameGenerator generator,
const Ioss::ParallelUtils &util,
const std::string& basename, const std::string& db_type,
const Ioss::PropertyManager& properties,
Ioss::DatabaseUsage usage, int step)
{
// See if there are multiple topology files

// If the file exists on all processors, return the filename.
// If the file does not exist on any processors, return "";
// If the file exists on some, but not all, throw an exception.

Ioss::DatabaseIO* db = nullptr;
std::string filename = expand_topology_files(generator, util, basename, properties, step);

if( !filename.empty() ) {
db = Ioss::IOFactory::create(db_type, filename, usage,
util.communicator(), properties);
int bad_count = 0;
std::string error_message;
bool is_valid_file = db != nullptr && db->ok(false, &error_message, &bad_count);
if(is_valid_file) {
return std::make_pair(filename, db);
} else {
delete db;
std::ostringstream errmsg;
errmsg << error_message;
errmsg << __FILE__ << ", " << __FUNCTION__ << ", filename " << filename << " is not a valid file\n";
IOSS_ERROR(errmsg);
}
}

// Does not exist on any processors
return std::make_pair(filename, db);
}

Ioss::FileNameGenerator construct_cyclic_filename_generator(unsigned cyclicCount)
{
if (cyclicCount > 26)
cyclicCount = 26;

Ioss::FileNameGenerator generator = [cyclicCount](const std::string& baseFileName, unsigned step) {
static std::string suffix = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string filename = baseFileName;
if(step == 0) step++;
filename += "-" + suffix.substr((step-1)%cyclicCount, 1);
return filename;
};

return generator;
}

Ioss::FileNameGenerator construct_linear_filename_generator()
{
Ioss::FileNameGenerator generator = [](const std::string& baseFileName, unsigned step) {
std::ostringstream filename;
filename << baseFileName;
if(step > 1){
filename << "-s" << std::setw(4) << std::setfill('0') << step;
}
return filename.str();
};

return generator;
}
}

Loading