-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (41 loc) · 1.56 KB
/
main.cpp
File metadata and controls
62 lines (41 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <Kokkos_Core.hpp>
#include <Kokkos_Random.hpp>
#include <random>
#include <iostream>
#include <fstream>
struct MarkovChainFunctor {
public:
MarkovChainFunctor( Kokkos::Random_XorShift64_Pool<Kokkos::CudaSpace> pool_) :
pool(pool_) {}
KOKKOS_INLINE_FUNCTION
void operator()(const int i, double& sum) const {
auto generator = pool.get_state();
double random_num = generator.drand(0.0, 2.0);
sum += random_num;
pool.free_state(generator);
}
private:
Kokkos::Random_XorShift64_Pool<Kokkos::CudaSpace> pool;
};
int main(int argc, char** argv){
Kokkos::initialize(argc, argv);
{
std::random_device rd;
std::uniform_int_distribution<int> dist(0, 4000);
Kokkos::Random_XorShift64_Pool<Kokkos::CudaSpace> random_pool(dist(rd));
Kokkos::DefaultExecutionSpace().print_configuration(std::cout);
double p = 811193170652452;
double sum = 0;
// TODO handle the case where p is too large to fit into an int
// We can use long long int, but we may need to consider
// external batching to the GPU as well
int64_t dim = static_cast<int64_t>(p);
std::cout << std::numeric_limits<int64_t>::max() << std::endl;
std::cout << dim << std::endl;
Kokkos::RangePolicy<Kokkos::IndexType<int64_t>> policy(0, dim);
Kokkos::parallel_reduce("MarkovChainReduce", policy, MarkovChainFunctor(random_pool), sum);
Kokkos::fence();
std::cout << sum / p << std::endl;
}
Kokkos::finalize();
}