79 using Vector = std::vector<T, Allocator<T>>;
89 void init_mpi(
int * argc,
char *** argv);
112 MPI_Allgather(value,
sizeof(T), MPI_BYTE, values.data(),
sizeof(T), MPI_BYTE, MPI_COMM_WORLD);
126 for (
auto v : values)
139 for (
auto v : values)
152 for (
auto v : values) {
163 for(
int i = 0; i < n; i++){
172 constexpr void __assert_mpi(
const char * expr_str,
bool expr,
const char * file,
int line,
const char * msg) {
174 std::cout <<
"[assert_mpi] Assertion failed: [" << expr_str <<
"], File: [" << file <<
"], Line: [" << line
175 <<
"], Message: [" << msg <<
"]" << std::endl;
177 MPI_Abort(MPI_COMM_WORLD, 1);
182#define assert_mpi(Expr, Msg) __assert_mpi(#Expr, Expr, __FILE__, __LINE__, Msg)
187 constexpr long long int power(
int base,
int exponent) {
188 return exponent == 0 ?
191 power(base, exponent / 2) *
power(base, exponent / 2) :
192 (
long long int)(base)*
power(base, (exponent - 1) / 2) *
power(base, (exponent - 1) / 2));
209 auto operator OP(const Vector<T> & lhs, const Vector<T> & rhs)->Vector<T> { \
210 const size_t nlhs = lhs.size(); \
211 const size_t nrhs = rhs.size(); \
213 throw std::runtime_error("Error vectors need to have the same size:"); \
215 for (size_t i = 0; i < nlhs; i++) { \
216 y[i] = lhs[i] OP rhs[i]; \
228 auto operator OP(const Vector<T> & lhs, const double & rhs)->Vector<T> { \
229 const size_t nlhs = lhs.size(); \
231 for (size_t i = 0; i < nlhs; i++) { \
232 y[i] = lhs[i] OP rhs; \
244 auto operator OP(const double & lhs, const Vector<T> & rhs)->Vector<T> { \
245 const size_t nrhs = rhs.size(); \
247 for (size_t i = 0; i < nrhs; i++) { \
248 y[i] = lhs OP rhs[i]; \
260 const size_t n =
x.size();
262 for (
size_t i = 0; i < n; i++) {
263 y[i] = std::pow(
x[i],
exp);
270 auto FUN(const Vector<T> & x)->Vector<T> { \
271 auto op_##FUN = [](double x) -> Vector<T> { return std::FUN(x); }; \
272 Vector<T> y(x.size()); \
273 std::transform(x.begin(), x.end(), y.begin(), op_##FUN); \
293 static MPISetup &
init(
int * argc =
nullptr,
char *** argv =
nullptr) {
294 static MPISetup instance(argc, argv);
299 MPISetup(
int * argc =
nullptr,
char *** argv =
nullptr) {
init_mpi(argc, argv); }
307 void init_fftw(
int * argc,
char *** argv);
334 static FMLSetup &
init(
int * argc =
nullptr,
char *** argv =
nullptr) {
335 static FMLSetup instance(argc, argv);
340 FMLSetup(
int * argc,
char *** argv) {
356 ~FMLSetup() =
default;
Class for performing timings of the code using std::chrono.
void init_fftw(int *argc, char ***argv)
void set_fftw_nthreads(int nthreads)
bool create_folder(std::string foldername)
double xmax_domain
The local extent of the domain (global domain goes from 0 to 1)
void MinOverTasks(T *value)
Inplace min over tasks of a single value.
std::pair< double, double > get_system_memory_use()
Fetch the resident set size currently and the peak value so far of it.
int NThreads
Total number of threads availiable.
void SumArrayOverTasks(T *value, int n)
Inplace sum over tasks of a contigious array of values.
bool MPIThreadsOK
If MPI and threads can work together with FFTW.
void init_mpi(int *argc, char ***argv)
Initialize MPI.
void MaxOverTasks(T *value)
Inplace max over tasks of a single value.
constexpr long long int power(int base, int exponent)
Simple integer a^b power-function by squaring.
void abort_mpi(int exit_code)
OPS(+) OPS(-) OPS(*) OPS(/) OPS(+) OPS(-) OPS(*) OPS(/) OPS(+) OPS(-) OPS(*) OPS(/) template< class T > Vector< T > pow(const Vector< T > &x
int ThisTask
The MPI task number.
void printf_mpi(const char *fmt,...)
std::vector< T > GatherFromTasks(T *value)
Gather a single value from all tasks. Value from task ThisTask is stored in values[ThisTask].
long long int IndexIntType
void print_system_memory_use()
Print the resident set size and the peak value of it so far.
FML::UTILS::Timings global_timer
void info()
Show some info about FML.
void SumOverTasks(T *value)
Inplace sum over tasks of a single value.
double xmin_domain
The local extent of the domain (global domain goes from 0 to 1)
std::vector< T, Allocator< T > > Vector
int NTasks
Total number of MPI tasks.
constexpr void __assert_mpi(const char *expr_str, bool expr, const char *file, int line, const char *msg)
An assert function that calls MPI_Abort instead of just abort to avoid deadlock.
void init_fml()
Initialize the global variables within FML We here assume MPI has been initialized.
Singleton for initializing and cleaning up FFTW with MPI and threads automatically.
static FFTWSetup & init(int *argc=nullptr, char ***argv=nullptr)
Singleton for initializing and cleaning up FML Takes care of automatically initializing MPI and FFTW.
static FMLSetup & init(int *argc=nullptr, char ***argv=nullptr)
Custom allocator that logs allocations.
Singleton for initializing and finalizing MPI automatically on startup and exit.
static MPISetup & init(int *argc=nullptr, char ***argv=nullptr)