From 17398eb2c4af0b2d8c5c7c4cc3622433b8673e2c Mon Sep 17 00:00:00 2001 From: Reynaldo Morillo Date: Mon, 17 Apr 2017 21:57:52 -0400 Subject: [PATCH] Sequential version done. --- README.md | 18 ++++++++++++++++++ sequential/gibbs_metropolis.cpp | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a65de42..1da5537 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,21 @@ Parallel MCMC On GPU =========================== This project compares the performance of MCMC on a single threaded CPU, and a multicore, multithreaded GPU (using CUDA). + + +## Sequential + +#### Dependencies +* gcc 5.4.0 or newer + +#### How to compile +``` +cd ./sequential +g++ -std=c++11 gibbs_metropolis.cpp -o gibbs_metropolis +``` + +##### Run +**Small Example** +`` +./gibbs_metropolis smallData.txt +``` diff --git a/sequential/gibbs_metropolis.cpp b/sequential/gibbs_metropolis.cpp index f10279c..ebd3ce8 100755 --- a/sequential/gibbs_metropolis.cpp +++ b/sequential/gibbs_metropolis.cpp @@ -46,7 +46,7 @@ specifically http://docs.nvidia.com/cuda/curand/index.html#topic_1_2_1 #include #include #include -// #include +#include #define PI 3.14159265359f @@ -272,11 +272,13 @@ void sample_theta(float *theta, float *log_theta, int *y, float *n, float a, float b, int K){ float hyperA, hyperB; + std::default_random_engine generator; for ( int i = 0; i < K; i++ ){ hyperA = a + y[i]; hyperB = b + n[i]; - theta[i] = rgamma(hyperA, hyperB); + std::gamma_distribution distribution(hyperA, hyperB); + theta[i] = distribution(generator); log_theta[i] = log(theta[i]); } }