-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile propagators in a separate library (#462)
Groups of related propagators are now compiled in separate translation units. --------- Co-authored-by: Sebastian Keller <[email protected]>
- Loading branch information
1 parent
4673595
commit f56fc7c
Showing
29 changed files
with
628 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
#pragma once | ||
|
||
#include <array> | ||
#include <algorithm> | ||
#include <vector> | ||
#include <variant> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include <algorithm> | ||
|
||
#include "arg_parser.hpp" | ||
|
||
namespace sphexa | ||
{ | ||
|
||
ArgParser::ArgParser(int argc, const char** argv) | ||
: begin(argv) | ||
, end(argv + argc) | ||
{ | ||
} | ||
|
||
std::vector<std::string> ArgParser::getCommaList(const std::string& option) const | ||
{ | ||
std::string listWithCommas = get(option); | ||
|
||
std::replace(listWithCommas.begin(), listWithCommas.end(), ',', ' '); | ||
|
||
std::vector<std::string> 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<std::string>& 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,13 @@ | |
* | ||
* @author Sebastian Keller <[email protected]> | ||
* @author Jose A. Escartin <[email protected]> | ||
* @author ChristopherBignamini <[email protected]> | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <variant> | ||
|
||
#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<class DomainType, class ParticleDataType> | |
std::unique_ptr<Propagator<DomainType, ParticleDataType>> | ||
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<HydroVeProp<true, DomainType, ParticleDataType>>(output, rank); } | ||
else { return std::make_unique<HydroVeProp<false, DomainType, ParticleDataType>>(output, rank); } | ||
} | ||
if (choice == "ve") { return PropLib<DomainType, ParticleDataType>::makeHydroVeProp(output, rank, avClean); } | ||
if (choice == "ve-bdt") | ||
{ | ||
if (avClean) { return std::make_unique<HydroVeBdtProp<true, DomainType, ParticleDataType>>(output, rank, s); } | ||
else { return std::make_unique<HydroVeBdtProp<false, DomainType, ParticleDataType>>(output, rank, s); } | ||
return PropLib<DomainType, ParticleDataType>::makeHydroVeBdtProp(output, rank, s, avClean); | ||
} | ||
if (choice == "std") { return std::make_unique<HydroProp<DomainType, ParticleDataType>>(output, rank); } | ||
if (choice == "std") { return PropLib<DomainType, ParticleDataType>::makeHydroProp(output, rank); } | ||
#ifdef SPH_EXA_HAVE_GRACKLE | ||
if (choice == "std-cooling") | ||
{ | ||
return std::make_unique<HydroGrackleProp<DomainType, ParticleDataType>>(output, rank, s); | ||
return PropLib<DomainType, ParticleDataType>::makeHydroGrackleProp(output, rank, s); | ||
} | ||
#endif | ||
if (choice == "nbody") { return std::make_unique<NbodyProp<DomainType, ParticleDataType>>(output, rank); } | ||
if (choice == "nbody") { return PropLib<DomainType, ParticleDataType>::makeNbodyProp(output, rank); } | ||
if (choice == "turbulence") | ||
{ | ||
if (avClean) { return std::make_unique<TurbVeBdtProp<true, DomainType, ParticleDataType>>(output, rank, s); } | ||
else { return std::make_unique<TurbVeBdtProp<false, DomainType, ParticleDataType>>(output, rank, s); } | ||
return PropLib<DomainType, ParticleDataType>::makeTurbVeBdtProp(output, rank, s, avClean); | ||
} | ||
if (choice == "turbulence-ve") | ||
{ | ||
if (avClean) { return std::make_unique<TurbVeProp<true, DomainType, ParticleDataType>>(output, rank, s); } | ||
else { return std::make_unique<TurbVeProp<false, DomainType, ParticleDataType>>(output, rank, s); } | ||
return PropLib<DomainType, ParticleDataType>::makeTurbVeProp(output, rank, s, avClean); | ||
} | ||
|
||
throw std::runtime_error("Unknown propagator choice: " + choice); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.