feat(SpectralSolver): Spectral Solver now works in a limited fashion
Major work on spectral solver, can now evolve up to about a year. At that point we likely need to impliment repartitioning logic to stabalize the network or some other scheme based on the jacobian structure
This commit is contained in:
50
src/include/gridfire/utils/gf_omp.h
Normal file
50
src/include/gridfire/utils/gf_omp.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include "fourdst/logging/logging.h"
|
||||
#include "quill/LogMacros.h"
|
||||
|
||||
#if defined(GF_USE_OPENMP)
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
namespace gridfire::omp {
|
||||
static bool s_par_mode_initialized = false;
|
||||
|
||||
inline unsigned long get_thread_id() {
|
||||
return static_cast<unsigned long>(omp_get_thread_num());
|
||||
}
|
||||
|
||||
inline bool in_parallel() {
|
||||
return omp_in_parallel() != 0;
|
||||
}
|
||||
|
||||
inline void init_parallel_mode() {
|
||||
if (s_par_mode_initialized) {
|
||||
return; // Only initialize once
|
||||
}
|
||||
quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
LOG_INFO(logger, "Initializing OpenMP parallel mode with {} threads", static_cast<unsigned long>(omp_get_max_threads()));
|
||||
CppAD::thread_alloc::parallel_setup(
|
||||
static_cast<size_t>(omp_get_max_threads()), // Max threads
|
||||
[]() -> bool { return in_parallel(); }, // Function to get thread ID
|
||||
[]() -> size_t { return get_thread_id(); } // Function to check parallel state
|
||||
);
|
||||
|
||||
CppAD::thread_alloc::hold_memory(true);
|
||||
s_par_mode_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
#define GF_PAR_INIT() gridfire::omp::init_parallel_mode();
|
||||
|
||||
#else
|
||||
|
||||
namespace gridfire::omp {
|
||||
inline void log_not_in_parallel_mode() {
|
||||
quill::Logger* logger = fourdst::logging::LogManager::getInstance().getLogger("log");
|
||||
LOG_INFO(logger, "This is not an error! Note: OpenMP parallel mode is not enabled. GF_USE_OPENMP is not defined. Pass -DGF_USE_OPENMP when compiling to enable OpenMP support. When using meson use the option -Dopenmp_support=true");
|
||||
}
|
||||
}
|
||||
|
||||
#define GF_PAR_INIT() gridfire::omp::log_not_in_parallel_mode();
|
||||
|
||||
#endif
|
||||
9
src/include/gridfire/utils/macros.h
Normal file
9
src/include/gridfire/utils/macros.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#if defined(GF_USE_OPENMP)
|
||||
#define GF_OMP_PRAGMA(x) _Pragma(#x)
|
||||
#define GF_OMP(omp_args, _) GF_OMP_PRAGMA(omp omp_args)
|
||||
#else
|
||||
#define GF_OMP(_,fallback_args) fallback_args
|
||||
#endif
|
||||
@@ -5,3 +5,4 @@
|
||||
#include "gridfire/utils/logging.h"
|
||||
#include "gridfire/utils/sundials.h"
|
||||
#include "gridfire/utils/table_format.h"
|
||||
#include "gridfire/utils/macros.h"
|
||||
|
||||
Reference in New Issue
Block a user