From a3b7f5d5ca20872ac1ef40e9c7767fb7baaf3e83 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Tue, 12 Nov 2024 18:03:07 -0700 Subject: [PATCH] IOSS: fix thread-safe group/change_set handling --- .../seacas/libraries/ioss/src/main/io_shell.C | 40 +++++++++---------- .../libraries/ioss/src/main/io_shell_ts.C | 22 ++++++++-- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/packages/seacas/libraries/ioss/src/main/io_shell.C b/packages/seacas/libraries/ioss/src/main/io_shell.C index d2dfc07881..b0d854088e 100644 --- a/packages/seacas/libraries/ioss/src/main/io_shell.C +++ b/packages/seacas/libraries/ioss/src/main/io_shell.C @@ -83,15 +83,15 @@ namespace { return options; } - bool open_change_set(const std::string &cs_name, Ioss::DatabaseIO *db, int rank) + bool open_change_set(const std::string &cs_name, Ioss::Region ®ion, int rank) { bool success = true; if (!cs_name.empty()) { - success = db->open_internal_change_set(cs_name); + success = region.load_internal_change_set_mesh(cs_name); if (!success) { if (rank == 0) { fmt::print(stderr, "ERROR: Unable to open change_set '{}' in file '{}'\n", cs_name, - db->get_filename()); + region.get_database()->get_filename()); } } } @@ -278,17 +278,17 @@ namespace { dbi->set_block_omissions(interFace.omitted_blocks, inclusions); } + // NOTE: 'region' owns 'db' pointer at this time... + Ioss::Region region(dbi, "region_1"); + // Change_set specified... We will read the specified changeSet from the input file if (!interFace.changeSetName.empty()) { - bool success = open_change_set(interFace.changeSetName, dbi, rank); + bool success = open_change_set(interFace.changeSetName, region, rank); if (!success) { return; } } - // NOTE: 'region' owns 'db' pointer at this time... - Ioss::Region region(dbi, "region_1"); - if (region.mesh_type() == Ioss::MeshType::HYBRID) { if (rank == 0) { fmt::print(stderr, @@ -599,31 +599,31 @@ namespace { dbi2->set_int_byte_size_api(Ioss::USE_INT64_API); } + // NOTE: 'input_region2' owns 'dbi2' pointer at this time... + Ioss::Region input_region2(dbi2, "region_2"); + + if (input_region2.mesh_type() == Ioss::MeshType::HYBRID) { + fmt::print(stderr, + "\nERROR: io_shell does not support '{}' meshes. Only 'Unstructured' or " + "'Structured' mesh is supported at this time.\n", + input_region2.mesh_type_string()); + return false; + } + { - bool success = open_change_set(interFace.changeSetName, dbi1, rank); + bool success = open_change_set(interFace.changeSetName, input_region1, rank); if (!success) { return false; } } { - bool success = open_change_set(interFace.changeSetName, dbi2, rank); + bool success = open_change_set(interFace.changeSetName, input_region2, rank); if (!success) { return false; } } - // NOTE: 'input_region2' owns 'dbi2' pointer at this time... - Ioss::Region input_region2(dbi2, "region_2"); - - if (input_region2.mesh_type() == Ioss::MeshType::HYBRID) { - fmt::print(stderr, - "\nERROR: io_shell does not support '{}' meshes. Only 'Unstructured' or " - "'Structured' mesh is supported at this time.\n", - input_region2.mesh_type_string()); - return false; - } - // Get integer size being used on input file #1 and set it in // the interFace. int_byte_size_api = dbi2->int_byte_size_api(); diff --git a/packages/seacas/libraries/ioss/src/main/io_shell_ts.C b/packages/seacas/libraries/ioss/src/main/io_shell_ts.C index f37b5079cf..1435188e50 100644 --- a/packages/seacas/libraries/ioss/src/main/io_shell_ts.C +++ b/packages/seacas/libraries/ioss/src/main/io_shell_ts.C @@ -95,6 +95,22 @@ namespace { template void set_owned_node_count(Ioss::Region ®ion, int my_processor, INT dummy); + + bool open_change_set(const std::string &cs_name, Ioss::Region ®ion, int rank) + { + bool success = true; + if (!cs_name.empty()) { + success = region.load_internal_change_set_mesh(cs_name); + if (!success) { + if (rank == 0) { + fmt::print(stderr, "ERROR: Unable to open change_set '{}' in file '{}'\n", cs_name, + region.get_database()->get_filename()); + } + } + } + return success; + } + } // namespace // ======================================================================== @@ -217,12 +233,12 @@ namespace { dbi->set_int_byte_size_api(Ioss::USE_INT64_API); } - if (!interFace.groupName.empty()) { - bool success = dbi->open_internal_change_set(interFace.groupName); + if (!interFace.changeSetName.empty()) { + bool success = open_change_set(interFace.changeSetName, region, rank); if (!success) { if (rank == 0) { fmt::print(stderr, "ERROR: Unable to open group '{}' in file '{}'\n", - interFace.groupName, inpfile); + interFace.changeSetName, inpfile); } return; }