Skip to content
Snippets Groups Projects
Select Git revision
  • d590297a0b14e2cac95e964f8cdf6c510883b361
  • develop default protected
  • feature/advection
  • feature/composite-scheme-other-fluxes
  • origin/stage/bouguettaia
  • save_clemence
  • feature/local-dt-fsi
  • feature/variational-hydro
  • feature/gmsh-reader
  • feature/reconstruction
  • feature/kinetic-schemes
  • feature/composite-scheme-sources
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

test_checkpointing_SetResumeFrom.cpp

Blame
  • test_checkpointing_SetResumeFrom.cpp 3.85 KiB
    #include <catch2/catch_test_macros.hpp>
    #include <catch2/matchers/catch_matchers_all.hpp>
    
    #include <utils/HighFivePugsUtils.hpp>
    #include <utils/Messenger.hpp>
    #include <utils/checkpointing/SetResumeFrom.hpp>
    
    #include <filesystem>
    
    // clazy:excludeall=non-pod-global-static
    
    TEST_CASE("checkpointing_SetResumeFrom", "[utils/checkpointing]")
    {
    #ifdef PUGS_HAS_HDF5
    
      std::string tmp_dirname;
      {
        {
          if (parallel::rank() == 0) {
            tmp_dirname = [&]() -> std::string {
              std::string temp_filename = std::filesystem::temp_directory_path() / "pugs_checkpointing_XXXXXX";
              return std::string{mkdtemp(&temp_filename[0])};
            }();
          }
          parallel::broadcast(tmp_dirname, 0);
        }
        std::filesystem::path path = tmp_dirname;
        const std::string filename = path / "checkpoint.h5";
    
        const std::string data_file0 = R"(Un tiens vaut mieux que deux tu l'auras,
    Un tiens vaut mieux que deux tu l'auras,...)";
        const std::string data_file1 = R"(All work and no play makes Jack a dull boy,
    All work and no play makes Jack a dull boy,...)";
        const std::string data_file2 = R"(solo trabajo y nada de juego hacen de Jack un chico aburrido,
    solo trabajo y nada de juego hacen de Jack un chico aburrido,...)";
    
        {
          HighFive::FileAccessProps fapl;
          fapl.add(HighFive::MPIOFileAccess{MPI_COMM_WORLD, MPI_INFO_NULL});
          fapl.add(HighFive::MPIOCollectiveMetadata{});
          HighFive::File file = HighFive::File(filename, HighFive::File::Truncate, fapl);
    
          file.createGroup("/checkpoint_0").createAttribute("data.pgs", data_file0);
          file.createGroup("/checkpoint_1").createAttribute("data.pgs", data_file1);
          file.createGroup("/checkpoint_2").createAttribute("data.pgs", data_file2);
        }
    
        {
          std::ostringstream os;
          setResumeFrom(filename, 0, os);
          REQUIRE(os.str() == "Resuming checkpoint successfully set to 0\n");
    
          HighFive::FileAccessProps fapl;
          fapl.add(HighFive::MPIOFileAccess{MPI_COMM_WORLD, MPI_INFO_NULL});
          fapl.add(HighFive::MPIOCollectiveMetadata{});
          HighFive::File file = HighFive::File(filename, HighFive::File::ReadOnly, fapl);
          REQUIRE(file.getGroup("/resuming_checkpoint").getAttribute("data.pgs").read<std::string>() == data_file0);
        }
    
        {
          std::ostringstream os;
          setResumeFrom(filename, 1, os);
          REQUIRE(os.str() == "Resuming checkpoint successfully set to 1\n");
    
          HighFive::FileAccessProps fapl;
          fapl.add(HighFive::MPIOFileAccess{MPI_COMM_WORLD, MPI_INFO_NULL});
          fapl.add(HighFive::MPIOCollectiveMetadata{});
          HighFive::File file = HighFive::File(filename, HighFive::File::ReadOnly, fapl);
          REQUIRE(file.getGroup("/resuming_checkpoint").getAttribute("data.pgs").read<std::string>() == data_file1);
        }
    
        {
          std::ostringstream os;
          setResumeFrom(filename, 2, os);
          REQUIRE(os.str() == "Resuming checkpoint successfully set to 2\n");
    
          HighFive::FileAccessProps fapl;
          fapl.add(HighFive::MPIOFileAccess{MPI_COMM_WORLD, MPI_INFO_NULL});
          fapl.add(HighFive::MPIOCollectiveMetadata{});
          HighFive::File file = HighFive::File(filename, HighFive::File::ReadOnly, fapl);
          REQUIRE(file.getGroup("/resuming_checkpoint").getAttribute("data.pgs").read<std::string>() == data_file2);
        }
    
        {
          std::ostringstream error_msg;
          error_msg << "error: cannot find checkpoint " << 12 << " in " << filename;
          REQUIRE_THROWS_WITH(setResumeFrom(filename, 12), error_msg.str());
        }
      }
    
      parallel::barrier();
      if (parallel::rank() == 0) {
        std::filesystem::remove_all(std::filesystem::path{tmp_dirname});
      }
    
    #else   // PUGS_HAS_HDF5
    
      if (parallel::rank() == 0) {
        std::cerr.setstate(std::ios::badbit);
      }
    
      std::ostringstream os;
      REQUIRE_NOTHROW(setResumeFrom("foo.h5", 0, os));
    
      if (parallel::rank() == 0) {
        std::cerr.clear();
      }
    
      REQUIRE(os.str() == "");
    
    #endif   // PUGS_HAS_HDF5
    }