FML
Namespaces | Data Structures | Typedefs | Functions | Variables
FML Namespace Reference

Namespaces

namespace  CORRELATIONFUNCTIONS
 This namespace deals with computing correlations functions (N-point functions) in real and fourier space.
 
namespace  COSMOLOGY
 This namespace deals with various cosmology specific things: background evolution, perturbation theory, recombination history etc.
 
namespace  FILEUTILS
 This namespace deals with reading and writing files to disc.
 
namespace  FOF
 This namespace deals how to link together particles in groups.
 
namespace  GRID
 This namespace contains various grids for holding data shared across different tasks.
 
namespace  HESSIAN
 This namespace deals with computing the Hessian of a grid and related algorithms that rely on this.
 
namespace  INTERPOLATION
 This namespace deals with interpolation and density assignment.
 
namespace  MATH
 This namespace deals with special math functions and general math algorithms needed in the library.
 
namespace  NBODY
 This namespace deals with N-body simulations.
 
namespace  PARTICLE
 This namespace contains things related to particles: different types, containers for holding shared particles across tasks and algorithms for doing stuff with particles.
 
namespace  RANDOM
 This namespace deals with generating random numbers and random fields.
 
namespace  SOLVERS
 This nanespace contains various solvers.
 
namespace  SURVEY
 This namespace contains methods for dealing with surveys.
 
namespace  TRIANGULATION
 This namespace deals with performin triangulations (Delaunay and Voronoi)
 
namespace  UTILS
 This namespace contains useful things that don't fit anywhere else.
 

Data Structures

struct  FFTWSetup
 Singleton for initializing and cleaning up FFTW with MPI and threads automatically. More...
 
struct  FMLSetup
 Singleton for initializing and cleaning up FML Takes care of automatically initializing MPI and FFTW. More...
 
struct  LogAllocator
 Custom allocator that logs allocations. More...
 
class  MemoryLog
 Logs all heap allocations in the code that are larger than min_bytes_to_log. More...
 
struct  MPISetup
 Singleton for initializing and finalizing MPI automatically on startup and exit. More...
 

Typedefs

template<class T >
using Allocator = FML::LogAllocator< T >
 
template<class T >
using Vector = std::vector< T, Allocator< T > >
 
using IndexIntType = long long int
 
using TimePoint = std::chrono::time_point< std::chrono::steady_clock >
 

Functions

double uniform_random ()
 
void init_mpi (int *argc, char ***argv)
 Initialize MPI. More...
 
void init_fml ()
 Initialize the global variables within FML We here assume MPI has been initialized. More...
 
void info ()
 Show some info about FML. More...
 
void abort_mpi (int exit_code)
 
void finalize_mpi ()
 
void printf_mpi (const char *fmt,...)
 
bool create_folder (std::string foldername)
 
std::pair< double, double > get_system_memory_use ()
 Fetch the resident set size currently and the peak value so far of it. More...
 
void print_system_memory_use ()
 Print the resident set size and the peak value of it so far. More...
 
 TYPES (char)
 
 TYPES (int)
 
 TYPES (unsigned int)
 
 TYPES (long long)
 
 TYPES (size_t)
 
 TYPES (ptrdiff_t)
 
 TYPES (float)
 
 TYPES (double)
 
 TYPES (long double)
 
template<class T >
std::vector< T > GatherFromTasks (T *value)
 Gather a single value from all tasks. Value from task ThisTask is stored in values[ThisTask]. More...
 
template<class T >
void MaxOverTasks (T *value)
 Inplace max over tasks of a single value. More...
 
template<class T >
void MinOverTasks (T *value)
 Inplace min over tasks of a single value. More...
 
template<class T >
void SumOverTasks (T *value)
 Inplace sum over tasks of a single value. More...
 
template<class T >
void SumArrayOverTasks (T *value, int n)
 Inplace sum over tasks of a contigious array of values. More...
 
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. More...
 
constexpr long long int power (int base, int exponent)
 Simple integer a^b power-function by squaring. More...
 
 OPS (+) OPS(-) OPS(*) OPS(/) OPS(+) OPS(-) OPS(*) OPS(/) OPS(+) OPS(-) OPS(*) OPS(/) template< class T > Vector< T > pow(const Vector< T > &x
 
Vector< T > y (n)
 
 for (size_t i=0;i< n;i++)
 
template<typename T , typename U >
bool operator== (const LogAllocator< T > &, const LogAllocator< U > &)
 
template<typename T , typename U >
bool operator!= (const LogAllocator< T > &a, const LogAllocator< U > &b)
 

Variables

FML::UTILS::Timings global_timer
 
FMLSetupfmlsetup = FMLSetup::init()
 
int ThisTask = 0
 The MPI task number. More...
 
int NTasks = 1
 Total number of MPI tasks. More...
 
int NThreads = 1
 Total number of threads availiable. More...
 
bool FFTWThreadsOK = false
 
bool MPIThreadsOK = false
 If MPI and threads can work together with FFTW. More...
 
double xmin_domain = 0.0
 The local extent of the domain (global domain goes from 0 to 1) More...
 
double xmax_domain = 1.0
 The local extent of the domain (global domain goes from 0 to 1) More...
 
std::mt19937 generator
 
const double exp
 
return y
 

Typedef Documentation

◆ Allocator

template<class T >
typedef std::allocator< T > FML::Allocator

Definition at line 70 of file Global.h.

◆ IndexIntType

using FML::IndexIntType = typedef long long int

Definition at line 84 of file Global.h.

◆ TimePoint

using FML::TimePoint = typedef std::chrono::time_point<std::chrono::steady_clock>

Definition at line 38 of file MemoryLogging.h.

◆ Vector

template<class T >
using FML::Vector = typedef std::vector<T, Allocator<T> >

Definition at line 79 of file Global.h.

Function Documentation

◆ __assert_mpi()

constexpr void FML::__assert_mpi ( const char *  expr_str,
bool  expr,
const char *  file,
int  line,
const char *  msg 
)
constexpr

An assert function that calls MPI_Abort instead of just abort to avoid deadlock.

Definition at line 172 of file Global.h.

172 {
173 if (not expr) {
174 std::cout << "[assert_mpi] Assertion failed: [" << expr_str << "], File: [" << file << "], Line: [" << line
175 << "], Message: [" << msg << "]" << std::endl;
176#ifdef USE_MPI
177 MPI_Abort(MPI_COMM_WORLD, 1);
178#endif
179 abort();
180 }
181 }

◆ abort_mpi()

void FML::abort_mpi ( int  exit_code)

Definition at line 170 of file Global.cpp.

170 {
171#ifdef USE_MPI
172 MPI_Abort(MPI_COMM_WORLD, exit_code);
173#endif
174 exit(exit_code);
175 }

◆ create_folder()

bool FML::create_folder ( std::string  foldername)

Definition at line 207 of file Global.cpp.

207 {
208 bool ok = true;
209 if (FML::ThisTask == 0) {
210 int status = mkdir(foldername.c_str(), 0777);
211 ok = not((status < 0) && (errno != EEXIST));
212 if (not ok) {
213 throw std::runtime_error("Failed to create snapshot folder [" + foldername + "]");
214 }
215 }
216 return ok;
217 }
int ThisTask
The MPI task number.
Definition: Global.cpp:33

◆ finalize_mpi()

void FML::finalize_mpi ( )

Definition at line 180 of file Global.cpp.

180 {
181#ifdef USE_FFTW
182 // If we have MPI and FFTW then FFTW takes care of finalizing
183 return;
184#endif
185#ifdef USE_MPI
186 MPI_Finalize();
187#endif
188 }

◆ for()

FML::for ( )

Definition at line 262 of file Global.h.

262 {
263 y[i] = std::pow(x[i], exp);
264 }
Vector< T > y(n)
const double exp
Definition: Global.h:259
x
Definition: test.py:18

◆ GatherFromTasks()

template<class T >
std::vector< T > FML::GatherFromTasks ( T *  value)

Gather a single value from all tasks. Value from task ThisTask is stored in values[ThisTask].

Definition at line 109 of file Global.h.

109 {
110 std::vector<T> values(FML::NTasks);
111#ifdef USE_MPI
112 MPI_Allgather(value, sizeof(T), MPI_BYTE, values.data(), sizeof(T), MPI_BYTE, MPI_COMM_WORLD);
113#else
114 values[0] = *value;
115#endif
116 return values;
117 }
int NTasks
Total number of MPI tasks.
Definition: Global.cpp:34

◆ get_system_memory_use()

std::pair< double, double > FML::get_system_memory_use ( )

Fetch the resident set size currently and the peak value so far of it.

Returns bytes

Definition at line 223 of file Global.cpp.

223 {
224 double currentSize_bytes = getCurrentRSS();
225 double peakSize_bytes = getPeakRSS();
226 return {currentSize_bytes, peakSize_bytes};
227 }
size_t getCurrentRSS()
Returns the current resident set size (physical memory use) measured in bytes, or zero if the value c...
Definition: SystemMemory.h:82
size_t getPeakRSS()
Returns the peak (maximum so far) resident set size (physical memory use) measured in bytes,...
Definition: SystemMemory.h:41

◆ info()

void FML::info ( )

Show some info about FML.

Definition at line 103 of file Global.cpp.

103 {
104 if (ThisTask == 0) {
105
106 std::cout << "\n";
107 std::cout << "#=====================================================\n";
108 std::cout << "# ________________ .____ \n";
109 std::cout << "# \\_ _____/ \\ | | \n";
110 std::cout << "# | __)/ \\ / \\| | \n";
111 std::cout << "# | \\/ Y \\ |___ \n";
112 std::cout << "# \\___ /\\____|__ /_______ \\ \n";
113 std::cout << "# \\/ \\/ \\/ \n";
114 std::cout << "#\n";
115
116 std::cout << "# Initializing FML, MPI and FFTW\n";
117#ifdef USE_MPI
118 std::cout << "# MPI is enabled. Running with " << NTasks << " MPI tasks\n";
119#else
120 std::cout << "# MPI is *not* enabled\n";
121#endif
122#ifdef USE_OMP
123 std::cout << "# OpenMP is enabled. Main task has " << NThreads << " threads availiable\n";
124#else
125 std::cout << "# OpenMP is *not* enabled\n";
126#endif
127#if defined(USE_MPI) && defined(USE_OMP)
128 std::cout << "# MPI + Threads is" << (FML::MPIThreadsOK ? " " : " *not* ") << "working\n";
129#endif
130#ifdef USE_FFTW
131 std::cout << "# FFTW is enabled. ";
132 std::cout << "Thread support is" << (FML::FFTWThreadsOK ? " " : " *not* ") << "enabled\n";
133#else
134 std::cout << "# FFTW is *not* enabled\n";
135#endif
136 std::cout << "#\n";
137 std::cout << "# List of tasks:\n";
138 }
139
140 for (int i = 0; i < NTasks; i++) {
141 if (FML::ThisTask == i) {
142 std::cout << "# Task " << std::setw(4) << i << " [" << processor_name << "]\n";
143 std::cout << "# x-domain [" << std::setw(8) << FML::xmin_domain << " , " << std::setw(8)
144 << FML::xmax_domain << ")" << std::endl;
145 }
146#ifdef USE_MPI
147 // Sleep to syncronize output to screen (this is not guaranteed to ensure syncronized output, but the only
148 // alternative is communiation and its not that important)
149 MPI_Barrier(MPI_COMM_WORLD);
150 std::this_thread::sleep_for(std::chrono::milliseconds(1));
151#endif
152 }
153
154 if (FML::ThisTask == 0) {
155 std::cout << std::flush;
156 std::cout << "#\n";
157 std::cout << "#=====================================================\n";
158 std::cout << "\n";
159 }
160
161#ifdef USE_MPI
162 MPI_Barrier(MPI_COMM_WORLD);
163 std::this_thread::sleep_for(std::chrono::milliseconds(1));
164#endif
165 }
static std::string processor_name
Definition: Global.cpp:14
double xmax_domain
The local extent of the domain (global domain goes from 0 to 1)
Definition: Global.cpp:42
int NThreads
Total number of threads availiable.
Definition: Global.cpp:35
bool MPIThreadsOK
If MPI and threads can work together with FFTW.
Definition: Global.cpp:38
bool FFTWThreadsOK
Definition: Global.cpp:37
double xmin_domain
The local extent of the domain (global domain goes from 0 to 1)
Definition: Global.cpp:41

◆ init_fml()

void FML::init_fml ( )

Initialize the global variables within FML We here assume MPI has been initialized.

Definition at line 71 of file Global.cpp.

71 {
72#ifdef USE_MPI
73 MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
74 MPI_Comm_size(MPI_COMM_WORLD, &NTasks);
75 int plen;
76 char pname[MPI_MAX_PROCESSOR_NAME];
77 MPI_Get_processor_name(pname, &plen);
78 processor_name = std::string(pname);
79#else
80 ThisTask = 0;
81 NTasks = 1;
82 processor_name = "ComputerNameNotAvailiable";
83#endif
84
85 // Initialize OpenMP
86#ifdef USE_OMP
87#pragma omp parallel
88 {
89 int id = omp_get_thread_num();
90 if (id == 0)
91 NThreads = omp_get_num_threads();
92 }
93#else
94 NThreads = 1;
95#endif
96
97 // Set range for local domain
98 xmin_domain = ThisTask / double(NTasks);
99 xmax_domain = (ThisTask + 1) / double(NTasks);
100 }

◆ init_mpi()

void FML::init_mpi ( int *  argc,
char ***  argv 
)

Initialize MPI.

This function is automatically called unless NO_AUTO_MPI_SETUP is defined

Definition at line 55 of file Global.cpp.

55 {
56#ifdef USE_MPI
57#ifdef USE_OMP
58 int provided;
59 MPI_Init_thread(argc, argv, MPI_THREAD_FUNNELED, &provided);
60 MPIThreadsOK = provided >= MPI_THREAD_FUNNELED;
61#else
62 MPI_Init(argc, argv);
63#endif
64#endif
65 }

◆ MaxOverTasks()

template<class T >
void FML::MaxOverTasks ( T *  value)

Inplace max over tasks of a single value.

Definition at line 121 of file Global.h.

121 {
122 if (FML::NTasks == 1)
123 return;
124 std::vector<T> values = GatherFromTasks(value);
125 T maxvalue = *value;
126 for (auto v : values)
127 if (maxvalue < v)
128 maxvalue = v;
129 *value = maxvalue;
130 }
std::vector< T > GatherFromTasks(T *value)
Gather a single value from all tasks. Value from task ThisTask is stored in values[ThisTask].
Definition: Global.h:109

◆ MinOverTasks()

template<class T >
void FML::MinOverTasks ( T *  value)

Inplace min over tasks of a single value.

Definition at line 134 of file Global.h.

134 {
135 if (FML::NTasks == 1)
136 return;
137 std::vector<T> values = GatherFromTasks(value);
138 T minvalue = *value;
139 for (auto v : values)
140 if (minvalue > v)
141 minvalue = v;
142 *value = minvalue;
143 }

◆ operator!=()

template<typename T , typename U >
bool FML::operator!= ( const LogAllocator< T > &  a,
const LogAllocator< U > &  b 
)
inline

Definition at line 308 of file MemoryLogging.h.

308 {
309 return not(a == b);
310 }

◆ operator==()

template<typename T , typename U >
bool FML::operator== ( const LogAllocator< T > &  ,
const LogAllocator< U > &   
)
inline

Definition at line 303 of file MemoryLogging.h.

303 {
304 return true;
305 }

◆ OPS()

FML::OPS ( ) const &

◆ power()

constexpr long long int FML::power ( int  base,
int  exponent 
)
constexpr

Simple integer a^b power-function by squaring.

Definition at line 187 of file Global.h.

187 {
188 return exponent == 0 ?
189 1 :
190 (exponent % 2 == 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));
193 }
constexpr long long int power(int base, int exponent)
Simple integer a^b power-function by squaring.
Definition: Global.h:187

◆ print_system_memory_use()

void FML::print_system_memory_use ( )

Print the resident set size and the peak value of it so far.

Definition at line 233 of file Global.cpp.

233 {
234 auto sysmem = FML::get_system_memory_use();
235 double cur_rss = sysmem.first / 1e6;
236 double peak_rss = sysmem.second / 1e6;
237 double min_cur_rss = cur_rss;
238 double max_cur_rss = cur_rss;
239 double min_peak = peak_rss;
240 double max_peak = peak_rss;
241 FML::MinOverTasks(&min_cur_rss);
242 FML::MaxOverTasks(&max_cur_rss);
243 FML::MinOverTasks(&min_peak);
244 FML::MaxOverTasks(&max_peak);
245 if (FML::ThisTask == 0) {
246 std::cout << "#=====================================================\n";
247 std::cout << "# System memory use (resident set size): \n";
248 std::cout << "# Current RSS: " << std::setw(15) << min_cur_rss << " MB (min over tasks)\n";
249 std::cout << "# Current RSS: " << std::setw(15) << max_cur_rss << " MB (max over tasks)\n";
250 std::cout << "# Peak RSS: " << std::setw(15) << min_peak << " MB (min over tasks)\n";
251 std::cout << "# Peak RSS: " << std::setw(15) << max_peak << " MB (max over tasks)\n";
252 std::cout << "#=====================================================\n";
253 }
254 }
void MinOverTasks(T *value)
Inplace min over tasks of a single value.
Definition: Global.h:134
std::pair< double, double > get_system_memory_use()
Fetch the resident set size currently and the peak value so far of it.
Definition: Global.cpp:223
void MaxOverTasks(T *value)
Inplace max over tasks of a single value.
Definition: Global.h:121

◆ printf_mpi()

void FML::printf_mpi ( const char *  fmt,
  ... 
)

Definition at line 193 of file Global.cpp.

193 {
194 if (FML::ThisTask == 0) {
195 va_list argp;
196 va_start(argp, fmt);
197 std::vfprintf(stdout, fmt, argp);
198 std::fflush(stdout);
199 va_end(argp);
200 }
201 }

◆ SumArrayOverTasks()

template<class T >
void FML::SumArrayOverTasks ( T *  value,
int  n 
)

Inplace sum over tasks of a contigious array of values.

Definition at line 160 of file Global.h.

160 {
161 if (FML::NTasks == 1)
162 return;
163 for(int i = 0; i < n; i++){
164 SumOverTasks(&value[i]);
165 }
166 }
void SumOverTasks(T *value)
Inplace sum over tasks of a single value.
Definition: Global.h:147

◆ SumOverTasks()

template<class T >
void FML::SumOverTasks ( T *  value)

Inplace sum over tasks of a single value.

Definition at line 147 of file Global.h.

147 {
148 if (FML::NTasks == 1)
149 return;
150 std::vector<T> values = GatherFromTasks(value);
151 T sum = 0;
152 for (auto v : values) {
153 sum += v;
154 }
155 *value = sum;
156 }

◆ TYPES() [1/9]

FML::TYPES ( char  )

◆ TYPES() [2/9]

FML::TYPES ( double  )

◆ TYPES() [3/9]

FML::TYPES ( float  )

◆ TYPES() [4/9]

FML::TYPES ( int  )

◆ TYPES() [5/9]

FML::TYPES ( long double  )

◆ TYPES() [6/9]

FML::TYPES ( long long  )

◆ TYPES() [7/9]

FML::TYPES ( ptrdiff_t  )

◆ TYPES() [8/9]

FML::TYPES ( size_t  )

◆ TYPES() [9/9]

FML::TYPES ( unsigned int  )

◆ uniform_random()

auto FML::uniform_random ( )

Definition at line 46 of file Global.cpp.

46 {
47 auto udist = std::uniform_real_distribution<double>(0.0, 1.0);
48 return udist(generator);
49 }
std::mt19937 generator
Definition: Global.cpp:45

◆ y()

Vector< T > FML::y ( )

Variable Documentation

◆ exp

const double FML::exp
Initial value:
{
const size_t n = x.size()

Definition at line 259 of file Global.h.

◆ FFTWThreadsOK

bool FML::FFTWThreadsOK = false

Definition at line 37 of file Global.cpp.

◆ fmlsetup

FMLSetup& FML::fmlsetup = FMLSetup::init()

Definition at line 24 of file Global.cpp.

◆ generator

std::mt19937 FML::generator

Definition at line 45 of file Global.cpp.

◆ global_timer

FML::UTILS::Timings FML::global_timer

Definition at line 18 of file Global.cpp.

◆ MPIThreadsOK

bool FML::MPIThreadsOK = false

If MPI and threads can work together with FFTW.

Definition at line 38 of file Global.cpp.

◆ NTasks

int FML::NTasks = 1

Total number of MPI tasks.

Definition at line 34 of file Global.cpp.

◆ NThreads

int FML::NThreads = 1

Total number of threads availiable.

Definition at line 35 of file Global.cpp.

◆ ThisTask

int FML::ThisTask = 0

The MPI task number.

Definition at line 33 of file Global.cpp.

◆ xmax_domain

double FML::xmax_domain = 1.0

The local extent of the domain (global domain goes from 0 to 1)

Definition at line 42 of file Global.cpp.

◆ xmin_domain

double FML::xmin_domain = 0.0

The local extent of the domain (global domain goes from 0 to 1)

Definition at line 41 of file Global.cpp.

◆ y

return FML::y

Definition at line 265 of file Global.h.