-
Notifications
You must be signed in to change notification settings - Fork 5
/
12_generatingvectors_medianqmc_demo.cpp
56 lines (44 loc) · 2.21 KB
/
12_generatingvectors_medianqmc_demo.cpp
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
/*
* Compile without GPU support:
* c++ -std=c++17 -pthread -I../src 12_generatingvectors_medianqmc_demo.cpp -o 12_generatingvectors_medianqmc_demo.out -lgsl -lgslcblas
* Compile with GPU support:
* nvcc -arch=<arch> -std=c++17 -rdc=true -x cu -Xptxas -O0 -Xptxas --disable-optimizer-constants -I../src 12_generatingvectors_medianqmc_demo.cpp -o 12_generatingvectors_medianqmc_demo.out -lgsl -lgslcblas
* Here `<arch>` is the architecture of the target GPU or `compute_30` if you are happy to use Just-in-Time compilation (See the Nvidia `nvcc` manual for more details).
*/
#include <iostream>
#include "qmc.hpp"
struct my_functor_t {
const unsigned long long int number_of_integration_variables = 3;
#ifdef __CUDACC__
__host__ __device__
#endif
double operator()(double* x) const
{
return x[0]*x[1]*x[2];
}
} my_functor;
int main() {
const unsigned int MAXVAR = 3;
integrators::Qmc<double,double,MAXVAR,integrators::transforms::Korobov<3>::type> integrator;
integrator.generatingvectors = integrators::generatingvectors::none();
integrator.keeplattices = true; // keep newly generating vector for subsequent integrations, only recommended if integrands are similar
integrator.minn = 100;
integrator.epsrel = 1e-6;
integrators::result<double> result = integrator.integrate(my_functor);
std::cout << "integral = " << result.integral << std::endl;
std::cout << "error = " << result.error << std::endl;
std::cout << "generating vectors:" << std::endl;
for (auto &gv : integrator.generatingvectors) {
std::cout << gv.first << ":"; for (auto i : gv.second) std::cout << " " << i; std::cout << std::endl;
}
std::cout << std::endl;
// repeat integration; no new generating vectors are constructed if integrator.keeplattices is set
result = integrator.integrate(my_functor);
std::cout << "integral = " << result.integral << std::endl;
std::cout << "error = " << result.error << std::endl;
std::cout << "generating vectors:" << std::endl;
for (auto &gv : integrator.generatingvectors) {
std::cout << gv.first << ":"; for (auto i : gv.second) std::cout << " " << i; std::cout << std::endl;
}
return 0;
}