From f56fc7cab0c9dc4c2bd31ac23c9dd8c714e3fc01 Mon Sep 17 00:00:00 2001 From: Christopher Bignamini Date: Tue, 19 Nov 2024 11:57:57 +0100 Subject: [PATCH] Compile propagators in a separate library (#462) Groups of related propagators are now compiled in separate translation units. --------- Co-authored-by: Sebastian Keller --- domain/include/cstone/fields/field_states.hpp | 1 + domain/include/cstone/halos/CMakeLists.txt | 2 +- domain/include/cstone/halos/halos.hpp | 8 +- main/src/CMakeLists.txt | 1 + .../sedov_solution/CMakeLists.txt | 4 +- main/src/io/CMakeLists.txt | 2 +- main/src/io/arg_parser.cpp | 89 +++++++++++++++++ main/src/io/arg_parser.hpp | 83 +++------------- main/src/propagator/CMakeLists.txt | 29 ++++++ main/src/propagator/factory.hpp | 33 ++----- main/src/propagator/ipropagator.hpp | 3 + main/src/propagator/nbody.cpp | 55 +++++++++++ main/src/propagator/propagator.h | 61 ++++++++++++ main/src/propagator/std_hydro.cpp | 55 +++++++++++ main/src/propagator/std_hydro_grackle.cpp | 60 ++++++++++++ main/src/propagator/std_hydro_grackle.hpp | 4 +- main/src/propagator/turb_ve.hpp | 48 +-------- main/src/propagator/turb_ve_bdt.hpp | 98 +++++++++++++++++++ main/src/propagator/ve_hydro.cpp | 65 ++++++++++++ main/src/propagator/ve_hydro.hpp | 2 - main/src/propagator/ve_hydro_bdt.cpp | 70 +++++++++++++ main/src/propagator/ve_hydro_bdt.hpp | 1 + main/src/sphexa/CMakeLists.txt | 6 +- main/src/sphexa/sphexa.cpp | 3 +- main/src/util/pm_reader.hpp | 2 +- main/test/CMakeLists.txt | 2 +- sph/include/sph/groups.hpp | 1 + sph/include/sph/ts_global.hpp | 1 + sph/include/sph/types.hpp | 2 +- 29 files changed, 628 insertions(+), 163 deletions(-) create mode 100644 main/src/io/arg_parser.cpp create mode 100644 main/src/propagator/CMakeLists.txt create mode 100644 main/src/propagator/nbody.cpp create mode 100644 main/src/propagator/propagator.h create mode 100644 main/src/propagator/std_hydro.cpp create mode 100644 main/src/propagator/std_hydro_grackle.cpp create mode 100644 main/src/propagator/turb_ve_bdt.hpp create mode 100644 main/src/propagator/ve_hydro.cpp create mode 100644 main/src/propagator/ve_hydro_bdt.cpp diff --git a/domain/include/cstone/fields/field_states.hpp b/domain/include/cstone/fields/field_states.hpp index 2e30a42c4..633fb356a 100644 --- a/domain/include/cstone/fields/field_states.hpp +++ b/domain/include/cstone/fields/field_states.hpp @@ -32,6 +32,7 @@ #pragma once #include +#include #include #include diff --git a/domain/include/cstone/halos/CMakeLists.txt b/domain/include/cstone/halos/CMakeLists.txt index 69f3ce6cd..106c629da 100644 --- a/domain/include/cstone/halos/CMakeLists.txt +++ b/domain/include/cstone/halos/CMakeLists.txt @@ -5,4 +5,4 @@ endif() if(CMAKE_CUDA_COMPILER OR CMAKE_HIP_COMPILER) add_library(gather_halos_obj OBJECT gather_halos_gpu.cu) target_include_directories(gather_halos_obj PRIVATE ${PROJECT_SOURCE_DIR}/include) -endif() \ No newline at end of file +endif() diff --git a/domain/include/cstone/halos/halos.hpp b/domain/include/cstone/halos/halos.hpp index 8da037584..be508f7a5 100644 --- a/domain/include/cstone/halos/halos.hpp +++ b/domain/include/cstone/halos/halos.hpp @@ -54,10 +54,10 @@ namespace detail { //! @brief check that only owned particles in [particleStart_:particleEnd_] are sent out as halos -void checkIndices(const SendList& sendList, - [[maybe_unused]] LocalIndex start, - [[maybe_unused]] LocalIndex end, - [[maybe_unused]] LocalIndex bufferSize) +static void checkIndices(const SendList& sendList, + [[maybe_unused]] LocalIndex start, + [[maybe_unused]] LocalIndex end, + [[maybe_unused]] LocalIndex bufferSize) { for (const auto& manifest : sendList) { diff --git a/main/src/CMakeLists.txt b/main/src/CMakeLists.txt index 50cbf0ae4..dc82eeefc 100644 --- a/main/src/CMakeLists.txt +++ b/main/src/CMakeLists.txt @@ -16,6 +16,7 @@ endfunction() add_subdirectory(init) add_subdirectory(io) add_subdirectory(observables) +add_subdirectory(propagator) add_subdirectory(sphexa) if (BUILD_ANALYTICAL) diff --git a/main/src/analytical_solutions/sedov_solution/CMakeLists.txt b/main/src/analytical_solutions/sedov_solution/CMakeLists.txt index 861c189e5..a422aa414 100644 --- a/main/src/analytical_solutions/sedov_solution/CMakeLists.txt +++ b/main/src/analytical_solutions/sedov_solution/CMakeLists.txt @@ -2,8 +2,8 @@ set(SOURCES sedov_solution.cpp main.cpp) add_executable(sedov_solution ${SOURCES}) target_include_directories(sedov_solution PRIVATE ${CSTONE_DIR} ${PROJECT_SOURCE_DIR}/main/src) if(CMAKE_OSX_SYSROOT) - target_link_libraries(sedov_solution stdc++) + target_link_libraries(sedov_solution io stdc++) else() - target_link_libraries(sedov_solution stdc++fs) + target_link_libraries(sedov_solution io stdc++fs) endif() install(TARGETS sedov_solution RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/main/src/io/CMakeLists.txt b/main/src/io/CMakeLists.txt index 173e10452..ae34cbd9b 100644 --- a/main/src/io/CMakeLists.txt +++ b/main/src/io/CMakeLists.txt @@ -10,7 +10,7 @@ function(enableH5Part exename) endif() endfunction() -add_library(io ifile_io_ascii.cpp ifile_io_hdf5.cpp) +add_library(io ifile_io_ascii.cpp ifile_io_hdf5.cpp arg_parser.cpp) target_include_directories(io PRIVATE ${CSTONE_DIR} ${MPI_CXX_INCLUDE_PATH}) target_link_libraries(io PRIVATE ${MPI_CXX_LIBRARIES}) enableH5Part(io) diff --git a/main/src/io/arg_parser.cpp b/main/src/io/arg_parser.cpp new file mode 100644 index 000000000..767c30c82 --- /dev/null +++ b/main/src/io/arg_parser.cpp @@ -0,0 +1,89 @@ +#include + +#include "arg_parser.hpp" + +namespace sphexa +{ + +ArgParser::ArgParser(int argc, const char** argv) + : begin(argv) + , end(argv + argc) +{ +} + +std::vector ArgParser::getCommaList(const std::string& option) const +{ + std::string listWithCommas = get(option); + + std::replace(listWithCommas.begin(), listWithCommas.end(), ',', ' '); + + std::vector list; + std::stringstream ss(listWithCommas); + std::string field; + while (ss >> field) + { + list.push_back(field); + } + + return list; +} + +bool ArgParser::exists(const std::string& option) const { return std::find(begin, end, option) != end; } + +bool strIsIntegral(const std::string& str) +{ + char* ptr; + std::strtol(str.c_str(), &ptr, 10); + return (*ptr) == '\0' && !str.empty(); +} + +bool isExtraOutputStep(size_t step, double t1, double t2, const std::vector& extraOutputs) +{ + auto matchStepOrTime = [step, t1, t2](const std::string& token) + { + double time = std::stod(token); + bool isIntegral = strIsIntegral(token); + return (isIntegral && std::stoul(token) == step) || (!isIntegral && t1 <= time && time < t2); + }; + + return std::any_of(extraOutputs.begin(), extraOutputs.end(), matchStepOrTime); +} + +bool isOutputTime(double t1, double t2, const std::string& frequencyStr) +{ + double frequency = std::stod(frequencyStr); + if (strIsIntegral(frequencyStr) || frequency == 0.0) { return false; } + + double closestMultiple = int(t2 / frequency) * frequency; + return t2 > frequency && t1 <= closestMultiple && closestMultiple < t2; +} + +bool isOutputStep(size_t step, const std::string& frequencyStr) +{ + int frequency = std::stoi(frequencyStr); + return strIsIntegral(frequencyStr) && frequency != 0 && (step % frequency == 0); +} + +std::string strBeforeSign(const std::string& str, const std::string& sign) +{ + auto commaPos = str.find_first_of(sign); + return str.substr(0, commaPos); +} + +std::string strAfterSign(const std::string& str, const std::string& sign) +{ + auto commaPos = str.find_first_of(sign); + if (commaPos == std::string::npos) { return {}; } + + return str.substr(commaPos + sign.size()); +} + +int numberAfterSign(const std::string& str, const std::string& sign) +{ + std::string afterComma = strAfterSign(str, sign); + return strIsIntegral(afterComma) ? std::stoi(afterComma) : -1; +} + +std::string removeModifiers(const std::string& initCond) { return strBeforeSign(strBeforeSign(initCond, ":"), ","); } + +} // namespace sphexa diff --git a/main/src/io/arg_parser.hpp b/main/src/io/arg_parser.hpp index ac03e3693..14c720015 100644 --- a/main/src/io/arg_parser.hpp +++ b/main/src/io/arg_parser.hpp @@ -4,28 +4,17 @@ #include #include #include -#include -#include namespace sphexa { //! @brief returns true if all characters of @p str together represent a valid integral number -bool strIsIntegral(const std::string& str) -{ - char* ptr; - std::strtol(str.c_str(), &ptr, 10); - return (*ptr) == '\0' && !str.empty(); -} +bool strIsIntegral(const std::string& str); class ArgParser { public: - ArgParser(int argc, const char** argv) - : begin(argv) - , end(argv + argc) - { - } + ArgParser(int argc, const char** argv); //! @brief look for @p option in the supplied cmd-line arguments and convert to T if found template @@ -44,24 +33,9 @@ class ArgParser } //! @brief parse a comma-separated list - std::vector getCommaList(const std::string& option) const - { - std::string listWithCommas = get(option); - - std::replace(listWithCommas.begin(), listWithCommas.end(), ',', ' '); - - std::vector list; - std::stringstream ss(listWithCommas); - std::string field; - while (ss >> field) - { - list.push_back(field); - } - - return list; - } + std::vector getCommaList(const std::string& option) const; - bool exists(const std::string& option) const { return std::find(begin, end, option) != end; } + bool exists(const std::string& option) const; private: const char** begin; @@ -77,17 +51,7 @@ class ArgParser * @return true if @p step matches any integral numbers in @p extraOutput or * if any floating point number therein falls into the interval @p [t1, t2) */ -bool isExtraOutputStep(size_t step, double t1, double t2, const std::vector& extraOutputs) -{ - auto matchStepOrTime = [step, t1, t2](const std::string& token) - { - double time = std::stod(token); - bool isIntegral = strIsIntegral(token); - return (isIntegral && std::stoul(token) == step) || (!isIntegral && t1 <= time && time < t2); - }; - - return std::any_of(extraOutputs.begin(), extraOutputs.end(), matchStepOrTime); -} +bool isExtraOutputStep(size_t step, double t1, double t2, const std::vector& extraOutputs); /*! @brief Evaluate whether the current step should be output (to file) according to time frequency * @@ -96,14 +60,7 @@ bool isExtraOutputStep(size_t step, double t1, double t2, const std::vector frequency && t1 <= closestMultiple && closestMultiple < t2; -} +bool isOutputTime(double t1, double t2, const std::string& frequencyStr); /*! @brief Evaluate whether the current step should be output (to file) according to iteration frequency * @@ -111,34 +68,16 @@ bool isOutputTime(double t1, double t2, const std::string& frequencyStr) * @param frequencyStr iteration frequency to output the simulation as string * @return true if the step is an integral multiple of the output frequency */ -bool isOutputStep(size_t step, const std::string& frequencyStr) -{ - int frequency = std::stoi(frequencyStr); - return strIsIntegral(frequencyStr) && frequency != 0 && (step % frequency == 0); -} +bool isOutputStep(size_t step, const std::string& frequencyStr); -std::string strBeforeSign(const std::string& str, const std::string& sign) -{ - auto commaPos = str.find_first_of(sign); - return str.substr(0, commaPos); -} +std::string strBeforeSign(const std::string& str, const std::string& sign); //! @brief If the input string ends with @p sign followed by an integer, return the integer, otherwise return -1 -std::string strAfterSign(const std::string& str, const std::string& sign) -{ - auto commaPos = str.find_first_of(sign); - if (commaPos == std::string::npos) { return {}; } - - return str.substr(commaPos + sign.size()); -} +std::string strAfterSign(const std::string& str, const std::string& sign); //! @brief If the input string ends with @p sign followed by an integer, return the integer, otherwise return -1 -int numberAfterSign(const std::string& str, const std::string& sign) -{ - std::string afterComma = strAfterSign(str, sign); - return strIsIntegral(afterComma) ? std::stoi(afterComma) : -1; -} +int numberAfterSign(const std::string& str, const std::string& sign); -std::string removeModifiers(const std::string& initCond) { return strBeforeSign(strBeforeSign(initCond, ":"), ","); } +std::string removeModifiers(const std::string& initCond); } // namespace sphexa diff --git a/main/src/propagator/CMakeLists.txt b/main/src/propagator/CMakeLists.txt new file mode 100644 index 000000000..2a7a359d2 --- /dev/null +++ b/main/src/propagator/CMakeLists.txt @@ -0,0 +1,29 @@ +set(PROP_SOURCES nbody.cpp std_hydro_grackle.cpp std_hydro.cpp ve_hydro.cpp ve_hydro_bdt.cpp) + +add_library(propagator ${PROP_SOURCES}) +target_include_directories(propagator PRIVATE ${PROJECT_SOURCE_DIR}/main/src ${COOLING_DIR} ${CSTONE_DIR} + ${SPH_DIR} ${RYOANJI_DIR} ${MPI_CXX_INCLUDE_PATH}) +target_link_libraries(propagator PRIVATE ${MPI_CXX_LIBRARIES} util OpenMP::OpenMP_CXX) +enableGrackle(propagator) + +if (CMAKE_CUDA_COMPILER OR CMAKE_HIP_COMPILER) + add_library(propagator_gpu ${PROP_SOURCES}) + target_compile_definitions(propagator_gpu PRIVATE USE_CUDA) + target_include_directories(propagator_gpu PRIVATE ${PROJECT_SOURCE_DIR}/main/src ${COOLING_DIR} ${CSTONE_DIR} + ${SPH_DIR} ${RYOANJI_DIR} ${MPI_CXX_INCLUDE_PATH}) + target_link_libraries(propagator_gpu PRIVATE ${MPI_CXX_LIBRARIES} cstone_gpu ryoanji sph_gpu util OpenMP::OpenMP_CXX) + enableGrackle(propagator_gpu) + if (GPU_DIRECT) + target_compile_definitions(propagator_gpu PRIVATE USE_GPU_DIRECT) + endif () +endif () + +if (CMAKE_CUDA_COMPILER) + target_link_libraries(propagator_gpu PRIVATE CUDA::cudart) +endif () + +if (CMAKE_HIP_COMPILER) + target_link_libraries(propagator_gpu PRIVATE hip::host) + target_compile_definitions(propagator_gpu PRIVATE THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP) + set_target_properties(propagator_gpu PROPERTIES LINKER_LANGUAGE CXX) +endif () diff --git a/main/src/propagator/factory.hpp b/main/src/propagator/factory.hpp index 182172818..dd7a58e64 100644 --- a/main/src/propagator/factory.hpp +++ b/main/src/propagator/factory.hpp @@ -28,21 +28,13 @@ * * @author Sebastian Keller * @author Jose A. Escartin + * @author ChristopherBignamini */ #pragma once -#include - #include "ipropagator.hpp" -#include "nbody.hpp" -#include "std_hydro.hpp" -#include "ve_hydro.hpp" -#include "ve_hydro_bdt.hpp" -#ifdef SPH_EXA_HAVE_GRACKLE -#include "std_hydro_grackle.hpp" -#endif -#include "turb_ve.hpp" +#include "propagator.h" namespace sphexa { @@ -51,33 +43,26 @@ template std::unique_ptr> propagatorFactory(const std::string& choice, bool avClean, std::ostream& output, size_t rank, const InitSettings& s) { - if (choice == "ve") - { - if (avClean) { return std::make_unique>(output, rank); } - else { return std::make_unique>(output, rank); } - } + if (choice == "ve") { return PropLib::makeHydroVeProp(output, rank, avClean); } if (choice == "ve-bdt") { - if (avClean) { return std::make_unique>(output, rank, s); } - else { return std::make_unique>(output, rank, s); } + return PropLib::makeHydroVeBdtProp(output, rank, s, avClean); } - if (choice == "std") { return std::make_unique>(output, rank); } + if (choice == "std") { return PropLib::makeHydroProp(output, rank); } #ifdef SPH_EXA_HAVE_GRACKLE if (choice == "std-cooling") { - return std::make_unique>(output, rank, s); + return PropLib::makeHydroGrackleProp(output, rank, s); } #endif - if (choice == "nbody") { return std::make_unique>(output, rank); } + if (choice == "nbody") { return PropLib::makeNbodyProp(output, rank); } if (choice == "turbulence") { - if (avClean) { return std::make_unique>(output, rank, s); } - else { return std::make_unique>(output, rank, s); } + return PropLib::makeTurbVeBdtProp(output, rank, s, avClean); } if (choice == "turbulence-ve") { - if (avClean) { return std::make_unique>(output, rank, s); } - else { return std::make_unique>(output, rank, s); } + return PropLib::makeTurbVeProp(output, rank, s, avClean); } throw std::runtime_error("Unknown propagator choice: " + choice); diff --git a/main/src/propagator/ipropagator.hpp b/main/src/propagator/ipropagator.hpp index b29c6c113..87c16e5a4 100644 --- a/main/src/propagator/ipropagator.hpp +++ b/main/src/propagator/ipropagator.hpp @@ -34,7 +34,10 @@ #include +#include "cstone/sfc/box.hpp" +#include "cstone/tree/accel_switch.hpp" #include "io/ifile_io.hpp" +#include "sph/particles_data.hpp" #include "util/pm_reader.hpp" #include "util/timer.hpp" diff --git a/main/src/propagator/nbody.cpp b/main/src/propagator/nbody.cpp new file mode 100644 index 000000000..54b7be5b6 --- /dev/null +++ b/main/src/propagator/nbody.cpp @@ -0,0 +1,55 @@ +/* + * MIT License + * + * Copyright (c) 2024 CSCS, ETH Zurich + * 2024 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief Translation unit for the nbody propagator initializer + * + * @author Sebastian Keller + * @author ChristopherBignamini + */ + +#include "sph/types.hpp" +#include "propagator.h" +#include "nbody.hpp" + +namespace sphexa +{ + +template +std::unique_ptr> +PropLib::makeNbodyProp(std::ostream& output, size_t rank) +{ + return std::make_unique>(output, rank); +} + +#ifdef USE_CUDA +template struct PropLib, + SimulationData>; +#else +template struct PropLib, + SimulationData>; +#endif + +} // namespace sphexa diff --git a/main/src/propagator/propagator.h b/main/src/propagator/propagator.h new file mode 100644 index 000000000..4244edf69 --- /dev/null +++ b/main/src/propagator/propagator.h @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2021 CSCS, ETH Zurich + * 2021 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief Propagator initialization + * + * @author Sebastian Keller + * @author ChristopherBignamini + */ + +#pragma once + +#include + +#include "ipropagator.hpp" +#include "init/settings.hpp" +#include "sphexa/simulation_data.hpp" + +namespace sphexa +{ + +template +struct PropLib +{ + + using PropPtr = std::unique_ptr>; + + static PropPtr makeHydroVeProp(std::ostream& output, size_t rank, bool avClean); + static PropPtr makeHydroProp(std::ostream& output, size_t rank); + static PropPtr makeHydroVeBdtProp(std::ostream& output, size_t rank, const InitSettings& settings, bool avClean); +#ifdef SPH_EXA_HAVE_GRACKLE + static PropPtr makeHydroGrackleProp(std::ostream& output, size_t rank, const InitSettings& settings); +#endif + static PropPtr makeNbodyProp(std::ostream& output, size_t rank); + static PropPtr makeTurbVeBdtProp(std::ostream& output, size_t rank, const InitSettings& settings, bool avClean); + static PropPtr makeTurbVeProp(std::ostream& output, size_t rank, const InitSettings& settings, bool avClean); +}; + +} // namespace sphexa diff --git a/main/src/propagator/std_hydro.cpp b/main/src/propagator/std_hydro.cpp new file mode 100644 index 000000000..8cb118e0a --- /dev/null +++ b/main/src/propagator/std_hydro.cpp @@ -0,0 +1,55 @@ +/* + * MIT License + * + * Copyright (c) 2024 CSCS, ETH Zurich + * 2024 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief Translation unit for the std hydro propagator initializer + * + * @author Sebastian Keller + * @author ChristopherBignamini + */ + +#include "sph/types.hpp" +#include "propagator.h" +#include "std_hydro.hpp" + +namespace sphexa +{ + +template +std::unique_ptr> +PropLib::makeHydroProp(std::ostream& output, size_t rank) +{ + return std::make_unique>(output, rank); +} + +#ifdef USE_CUDA +template struct PropLib, + SimulationData>; +#else +template struct PropLib, + SimulationData>; +#endif + +} // namespace sphexa diff --git a/main/src/propagator/std_hydro_grackle.cpp b/main/src/propagator/std_hydro_grackle.cpp new file mode 100644 index 000000000..1cd36c271 --- /dev/null +++ b/main/src/propagator/std_hydro_grackle.cpp @@ -0,0 +1,60 @@ +/* + * MIT License + * + * Copyright (c) 2024 CSCS, ETH Zurich + * 2024 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief Translation unit for the std hydro grackle propagator initializer + * + * @author Sebastian Keller + * @author ChristopherBignamini + */ + +#ifdef SPH_EXA_HAVE_GRACKLE + +#include "sph/types.hpp" +#include "propagator.h" +#include "std_hydro_grackle.hpp" + +namespace sphexa +{ + +template +std::unique_ptr> +PropLib::makeHydroGrackleProp(std::ostream& output, size_t rank, + const InitSettings& settings) +{ + return std::make_unique>(output, rank, settings); +} + +#ifdef USE_CUDA +template struct PropLib, + SimulationData>; +#else +template struct PropLib, + SimulationData>; +#endif + +} // namespace sphexa + +#endif diff --git a/main/src/propagator/std_hydro_grackle.hpp b/main/src/propagator/std_hydro_grackle.hpp index fef90608c..2202cccca 100644 --- a/main/src/propagator/std_hydro_grackle.hpp +++ b/main/src/propagator/std_hydro_grackle.hpp @@ -27,16 +27,14 @@ * @brief A Propagator class for standard SPH including Grackle chemistry and cooling * * @author Sebastian Keller - * @author Jose A. Escartin * @author Noah Kubli */ #pragma once -#include - #include "cstone/fields/field_get.hpp" #include "cstone/util/value_list.hpp" +#include "io/arg_parser.hpp" #include "sph/particles_data.hpp" #include "sph/sph.hpp" diff --git a/main/src/propagator/turb_ve.hpp b/main/src/propagator/turb_ve.hpp index c2f371c44..ec4fa1852 100644 --- a/main/src/propagator/turb_ve.hpp +++ b/main/src/propagator/turb_ve.hpp @@ -37,6 +37,7 @@ #include "cstone/util/constexpr_string.hpp" #include "cstone/fields/field_get.hpp" +#include "io/arg_parser.hpp" #include "sph/sph.hpp" #include "sph/hydro_turb/turbulence_data.hpp" @@ -48,53 +49,6 @@ namespace sphexa using namespace sph; -//! @brief VE hydro propagator that adds turbulence stirring to the acceleration prior to position update -template -class TurbVeBdtProp final : public HydroVeBdtProp -{ - using Base = HydroVeBdtProp; - using Base::rank_; - using Base::timer; - - sph::TurbulenceData turbulenceData; - -public: - TurbVeBdtProp(std::ostream& output, size_t rank, const InitSettings& settings) - : Base(output, rank, settings) - , turbulenceData(settings, rank == 0) - { - } - - void computeForces(DomainType& domain, DataType& simData) override - { - Base::computeForces(domain, simData); - driveTurbulence(Base::activeRungs_, simData.hydro, turbulenceData); - timer.step("Turbulence Stirring"); - } - - void save(IFileWriter* writer) override - { - Base::save(writer); - turbulenceData.loadOrStore(writer); - } - - void load(const std::string& initCond, IFileReader* reader) override - { - Base::load(initCond, reader); - - int step = numberAfterSign(initCond, ":"); - std::string path = removeModifiers(initCond); - // The file does not exist, we're starting from scratch. Nothing to do. - if (!std::filesystem::exists(path)) { return; } - - reader->setStep(path, step, FileMode::independent); - turbulenceData.loadOrStore(reader); - - if (rank_ == 0) { std::cout << "Restored turbulence state from " << path << ":" << step << std::endl; } - reader->closeStep(); - } -}; - template class TurbVeProp final : public HydroVeProp { diff --git a/main/src/propagator/turb_ve_bdt.hpp b/main/src/propagator/turb_ve_bdt.hpp new file mode 100644 index 000000000..85479865c --- /dev/null +++ b/main/src/propagator/turb_ve_bdt.hpp @@ -0,0 +1,98 @@ +/* + * MIT License + * + * Copyright (c) 2021 CSCS, ETH Zurich + * 2021 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief A Propagator class for modern SPH with generalized volume elements + * + * @author Sebastian Keller + */ + +#pragma once + +#include +#include +#include + +#include "cstone/util/constexpr_string.hpp" +#include "cstone/fields/field_get.hpp" +#include "io/arg_parser.hpp" +#include "sph/sph.hpp" +#include "sph/hydro_turb/turbulence_data.hpp" + +#include "ve_hydro_bdt.hpp" +#include "gravity_wrapper.hpp" + +namespace sphexa +{ + +using namespace sph; + +//! @brief VE hydro propagator that adds turbulence stirring to the acceleration prior to position update +template +class TurbVeBdtProp final : public HydroVeBdtProp +{ + using Base = HydroVeBdtProp; + using Base::rank_; + using Base::timer; + sph::TurbulenceData turbulenceData; + +public: + TurbVeBdtProp(std::ostream& output, size_t rank, const InitSettings& settings) + : Base(output, rank, settings) + , turbulenceData(settings, rank == 0) + { + } + + void computeForces(DomainType& domain, DataType& simData) override + { + Base::computeForces(domain, simData); + driveTurbulence(Base::activeRungs_, simData.hydro, turbulenceData); + timer.step("Turbulence Stirring"); + } + + void save(IFileWriter* writer) override + { + Base::save(writer); + turbulenceData.loadOrStore(writer); + } + + void load(const std::string& initCond, IFileReader* reader) override + { + Base::load(initCond, reader); + + int step = numberAfterSign(initCond, ":"); + std::string path = removeModifiers(initCond); + // The file does not exist, we're starting from scratch. Nothing to do. + if (!std::filesystem::exists(path)) { return; } + + reader->setStep(path, step, FileMode::independent); + turbulenceData.loadOrStore(reader); + + if (rank_ == 0) { std::cout << "Restored turbulence state from " << path << ":" << step << std::endl; } + reader->closeStep(); + } +}; + +} // namespace sphexa diff --git a/main/src/propagator/ve_hydro.cpp b/main/src/propagator/ve_hydro.cpp new file mode 100644 index 000000000..08f9033bd --- /dev/null +++ b/main/src/propagator/ve_hydro.cpp @@ -0,0 +1,65 @@ +/* + * MIT License + * + * Copyright (c) 2024 CSCS, ETH Zurich + * 2024 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief Translation unit for the ve hydro propagator initializer + * + * @author Sebastian Keller + * @author ChristopherBignamini + */ + +#include "sph/types.hpp" +#include "propagator.h" +#include "turb_ve.hpp" +#include "ve_hydro.hpp" + +namespace sphexa +{ + +template +std::unique_ptr> +PropLib::makeHydroVeProp(std::ostream& output, size_t rank, bool avClean) +{ + if (avClean) { return std::make_unique>(output, rank); } + else { return std::make_unique>(output, rank); } +} + +template +std::unique_ptr> +PropLib::makeTurbVeProp(std::ostream& output, size_t rank, const InitSettings& settings, + bool avClean) +{ + if (avClean) { return std::make_unique>(output, rank, settings); } + else { return std::make_unique>(output, rank, settings); } +} + +#ifdef USE_CUDA +template struct PropLib, + SimulationData>; +#else +template struct PropLib, + SimulationData>; +#endif +} // namespace sphexa diff --git a/main/src/propagator/ve_hydro.hpp b/main/src/propagator/ve_hydro.hpp index 54d58f792..9cfe937c4 100644 --- a/main/src/propagator/ve_hydro.hpp +++ b/main/src/propagator/ve_hydro.hpp @@ -32,8 +32,6 @@ #pragma once -#include - #include "cstone/fields/field_get.hpp" #include "sph/particles_data.hpp" #include "sph/sph.hpp" diff --git a/main/src/propagator/ve_hydro_bdt.cpp b/main/src/propagator/ve_hydro_bdt.cpp new file mode 100644 index 000000000..d6e7531f1 --- /dev/null +++ b/main/src/propagator/ve_hydro_bdt.cpp @@ -0,0 +1,70 @@ +/* + * MIT License + * + * Copyright (c) 2024 CSCS, ETH Zurich + * 2024 University of Basel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/*! @file + * @brief Translation unit for the ve hydro bdt propagator initializer + * + * @author Sebastian Keller + * @author ChristopherBignamini + */ + +#include "sph/types.hpp" +#include "propagator.h" +#include "turb_ve_bdt.hpp" +#include "ve_hydro_bdt.hpp" + +namespace sphexa +{ + +template +std::unique_ptr> +PropLib::makeHydroVeBdtProp(std::ostream& output, size_t rank, + const InitSettings& settings, bool avClean) +{ + if (avClean) + { + return std::make_unique>(output, rank, settings); + } + else { return std::make_unique>(output, rank, settings); } +} + +template +std::unique_ptr> +PropLib::makeTurbVeBdtProp(std::ostream& output, size_t rank, + const InitSettings& settings, bool avClean) +{ + if (avClean) { return std::make_unique>(output, rank, settings); } + else { return std::make_unique>(output, rank, settings); } +} + +#ifdef USE_CUDA +template struct PropLib, + SimulationData>; +#else +template struct PropLib, + SimulationData>; +#endif + +} // namespace sphexa diff --git a/main/src/propagator/ve_hydro_bdt.hpp b/main/src/propagator/ve_hydro_bdt.hpp index 247722686..15cab4bee 100644 --- a/main/src/propagator/ve_hydro_bdt.hpp +++ b/main/src/propagator/ve_hydro_bdt.hpp @@ -36,6 +36,7 @@ #include "cstone/cuda/device_vector.h" #include "cstone/fields/field_get.hpp" +#include "io/arg_parser.hpp" #include "sph/particles_data.hpp" #include "sph/sph.hpp" #include "sph/ts_rungs.hpp" diff --git a/main/src/sphexa/CMakeLists.txt b/main/src/sphexa/CMakeLists.txt index e3540c497..7617764ea 100644 --- a/main/src/sphexa/CMakeLists.txt +++ b/main/src/sphexa/CMakeLists.txt @@ -25,7 +25,7 @@ endfunction() set(exename sphexa) add_executable(${exename} sphexa.cpp) target_include_directories(${exename} PRIVATE ${SPH_EXA_INCLUDE_DIRS}) -target_link_libraries(${exename} PRIVATE io sim_init observables OpenMP::OpenMP_CXX ${MPI_CXX_LIBRARIES}) +target_link_libraries(${exename} PRIVATE io sim_init propagator observables OpenMP::OpenMP_CXX ${MPI_CXX_LIBRARIES}) target_include_directories(${exename} PRIVATE ${PROJECT_SOURCE_DIR}/physics/cooling/include/) enableInSituViz(${exename}) @@ -37,7 +37,7 @@ if(CMAKE_CUDA_COMPILER) target_include_directories(${exename}-cuda PRIVATE ${SPH_EXA_INCLUDE_DIRS}) target_include_directories(${exename}-cuda PUBLIC ${CMAKE_BINARY_DIR}/main/src) target_compile_definitions(${exename}-cuda PRIVATE USE_CUDA) - target_link_libraries(${exename}-cuda PRIVATE cstone_gpu ryoanji sph_gpu io sim_init_gpu observables_gpu OpenMP::OpenMP_CXX + target_link_libraries(${exename}-cuda PRIVATE ryoanji sph_gpu io sim_init_gpu propagator_gpu observables_gpu OpenMP::OpenMP_CXX ${MPI_CXX_LIBRARIES} CUDA::cudart) enableInSituViz(${exename}-cuda) enableGpuDirect(${exename}-cuda) @@ -48,7 +48,7 @@ elseif(CMAKE_HIP_COMPILER) add_executable(${exename}-hip sphexa.cpp) target_include_directories(${exename}-hip PRIVATE ${SPH_EXA_INCLUDE_DIRS}) target_compile_definitions(${exename}-hip PRIVATE USE_CUDA THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP) - target_link_libraries(${exename}-hip PRIVATE cstone_gpu ryoanji sph_gpu io sim_init_gpu observables_gpu OpenMP::OpenMP_CXX + target_link_libraries(${exename}-hip PRIVATE ryoanji sph_gpu io sim_init_gpu propagator_gpu observables_gpu OpenMP::OpenMP_CXX ${MPI_CXX_LIBRARIES} hip::host) set_target_properties(${exename}-hip PROPERTIES LINKER_LANGUAGE CXX) enableInSituViz(${exename}-hip) diff --git a/main/src/sphexa/sphexa.cpp b/main/src/sphexa/sphexa.cpp index ae077cb33..de61d6a46 100644 --- a/main/src/sphexa/sphexa.cpp +++ b/main/src/sphexa/sphexa.cpp @@ -44,6 +44,7 @@ #include "io/factory.hpp" #include "observables/factory.hpp" #include "propagator/factory.hpp" +#include "sph/types.hpp" #include "util/timer.hpp" #include "util/utils.hpp" @@ -75,7 +76,7 @@ int main(int argc, char** argv) } using Dataset = SimulationData; - using Domain = cstone::Domain; + using Domain = cstone::Domain; const std::string initCond = parser.get("--init"); const size_t problemSize = parser.get("-n", 50); diff --git a/main/src/util/pm_reader.hpp b/main/src/util/pm_reader.hpp index b11ca2342..81b1b1cbc 100644 --- a/main/src/util/pm_reader.hpp +++ b/main/src/util/pm_reader.hpp @@ -8,7 +8,7 @@ namespace sphexa { -int readPmCounter(const char* fname, unsigned long long* joules, unsigned long long* ms) +static int readPmCounter(const char* fname, unsigned long long* joules, unsigned long long* ms) { auto file = fopen(fname, "r"); if (file == nullptr) { return 1; } diff --git a/main/test/CMakeLists.txt b/main/test/CMakeLists.txt index ea693b19a..86efda0ed 100644 --- a/main/test/CMakeLists.txt +++ b/main/test/CMakeLists.txt @@ -13,7 +13,7 @@ if (SPH_EXA_WITH_H5PART) target_compile_options(${exename} PRIVATE -Wall -Wextra -Wno-unknown-pragmas) target_include_directories(${exename} PRIVATE ${MPI_CXX_INCLUDE_PATH} ${SPH_DIR} ${CSTONE_DIR} ${PROJECT_SOURCE_DIR}/main/src) - target_link_libraries(${exename} PRIVATE ${MPI_CXX_LIBRARIES} GTest::gtest_main) + target_link_libraries(${exename} PRIVATE io ${MPI_CXX_LIBRARIES} GTest::gtest_main) enableH5Part(${exename}) add_test(NAME FrontendUnits COMMAND ${exename}) endif () diff --git a/sph/include/sph/groups.hpp b/sph/include/sph/groups.hpp index 6edb80829..e55eef642 100644 --- a/sph/include/sph/groups.hpp +++ b/sph/include/sph/groups.hpp @@ -7,6 +7,7 @@ #pragma once #include "cstone/sfc/box.hpp" +#include "cstone/primitives/primitives_gpu.h" #include "sph/sph_gpu.hpp" namespace sph diff --git a/sph/include/sph/ts_global.hpp b/sph/include/sph/ts_global.hpp index b909e6579..9bd1250e1 100644 --- a/sph/include/sph/ts_global.hpp +++ b/sph/include/sph/ts_global.hpp @@ -36,6 +36,7 @@ #include #include +#include "cstone/primitives/mpi_wrappers.hpp" #include "cstone/primitives/primitives_gpu.h" #include "kernels.hpp" diff --git a/sph/include/sph/types.hpp b/sph/include/sph/types.hpp index 8f9d30941..ded63cb5e 100644 --- a/sph/include/sph/types.hpp +++ b/sph/include/sph/types.hpp @@ -31,7 +31,7 @@ #pragma once -#include +#include namespace sph {