Commit 8909887d authored by stefanow's avatar stefanow
Browse files

makefile

parent f2e650e5
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){
......@@ -75,11 +75,11 @@ int main(){
best_thetas.push_back(get_most_likely_theta(thetas, weights));
/// Resampling
resample(weights, resample_count);
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;
}
......@@ -99,7 +99,7 @@ int main(){
#endif
//std::cout << resample_count.transpose() << "<- res count\n";
//std::cout << indices_for_mcmc.transpose() << "<- indices\n";
/// Compute sample mean and covariance
sample_mean = thetas * weights;
......@@ -112,7 +112,7 @@ int main(){
sample_cov_mat += 0.001 * CovMat::Identity();
sample_cov_mat *= BETA * BETA;
/// MCMC
/// MCMC
normal_random_variable sample {sample_cov_mat};
#ifdef USE_FOR_VERSION
#pragma omp parallel for schedule(static)
......@@ -140,9 +140,9 @@ int main(){
}
}
}
#endif
#endif
assert(likelihoods.minCoeff() >= 0);
/// Prepare next iteration
std::cout << "Step " << step_count++ << " done.\n";
thetas.swap(thetas_new);
......
......@@ -76,7 +76,6 @@ extern XoroshiroRandomNumberEngine GEN;
/// Defines
//#define UNIF_PRIOR
//#define USE_BRENTS_METHOD
#define USE_FOR_VERSION
#define BURNIN 10
#pragma omp threadprivate(GEN)
Markdown is supported
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