Commit c0be4b3d authored by chbauman's avatar chbauman
Browse files

merged

parents ffc82a4c d92e4397
CXX ?= g++
macroDefines :=
parallelFlags :=
ifdef NDEBUG
$(info Release build)
......@@ -32,6 +33,14 @@ else
$(info not using for version)
endif
ifdef USE_SERIAL
$(info using serial version)
else
$(info using parallel version)
parallelFlags += -fopenmp
endif
ifdef USE_BRENTS_METHOD
$(info Using Brent's method to find the tho values, needs boost)
......@@ -55,7 +64,7 @@ boostIncludes :=
endif
CFLAGS := -g -fopenmp -std=c++14 $(optimizationFlags) $(macroDefines) $(CFLAGS)
CFLAGS := -g -std=c++14 $(parallelFlags) $(optimizationFlags) $(macroDefines) $(CFLAGS)
eigenIncludes := $(shell pkg-config --cflags eigen3)
......
#ifndef MCFTLE_OPEN_MP_HPP
#define MCFTLE_OPEN_MP_HPP
#ifdef _OPENMP
// use OpenMP
#include <omp.h>
class OMPLock {
public:
OMPLock() { omp_init_lock(&lck_); }
OMPLock(const OMPLock& l) = delete;
OMPLock& operator=(const OMPLock& l) = delete;
OMPLock(OMPLock&& l) = default;
OMPLock& operator=(OMPLock&& l) = default;
inline void lock() { omp_set_lock(&lck_); }
inline void unlock() { omp_unset_lock(&lck_); }
~OMPLock() { omp_destroy_lock(&lck_); }
private:
omp_lock_t lck_;
};
#else
// no OpenMP
class OMPLock {
public:
OMPLock() {}
OMPLock(const OMPLock& l) = delete;
OMPLock& operator=(const OMPLock& l) = delete;
OMPLock(OMPLock&& l) = default;
OMPLock& operator=(OMPLock&& l) = default;
inline void lock() {}
inline void unlock() {}
};
#define omp_get_max_threads() 1
#define omp_get_num_threads() 1
#define omp_get_thread_num() 0
#define omp_get_num_procs() 1
#endif // _OPENMP
#endif
......@@ -7,7 +7,7 @@
#include "util.hpp"
#include "next_rho.hpp"
#include "likelihood.hpp"
#include <omp.h>
#include "open_mp.hpp"
#include <ctime>
#include <cstdint>
......@@ -46,7 +46,7 @@ int main(){
ThetaVector sample_mean;
numeric_t evidence_s = 1.0;
const auto likelihood = get_likelihood_function_from_data("data.txt");
/// Compute likelihoods of prior samples
#pragma omp parallel for schedule(static)
for(index_t i = 0; i < POP_SIZE; ++i){
......@@ -76,11 +76,10 @@ int main(){
/// Resampling
resample(weights, resample_count);
#ifdef USE_FOR_VERSION
/// Precomputing indices for mcmc chains
index_t nnonzero = 0;
index_t nnonzero = 0;
for(index_t i = 0; i < POP_SIZE; ++i){
if(resample_count(i) > 0) ++nnonzero;
}
......@@ -141,7 +140,7 @@ int main(){
}
}
}
#endif
#endif
assert(likelihoods.minCoeff() >= 0);
/// Prepare next iteration
......
......@@ -75,7 +75,6 @@ extern XoroshiroRandomNumberEngine GEN;
/// Defines
//#define UNIF_PRIOR
#define USE_BRENTS_METHOD
//#define USE_FOR_VERSION
#define BURNIN 10
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment