Skip to content

Commit 504dab1

Browse files
committed
monte carlo pi changes
1 parent 56bd29e commit 504dab1

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

Libraries/oneMKL/monte_carlo_pi/mc_pi.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/*
88
*
99
* Content:
10-
* This file contains Monte Carlo Pi number evaluation benchmark for DPC++
10+
* This file contains Monte Carlo Pi number evaluation benchmark for DPC++
1111
* interface of random number generators.
1212
*
1313
*******************************************************************************/
@@ -126,10 +126,21 @@ int main(int argc, char ** argv) {
126126
}
127127

128128
// Printing results
129+
double abs_error = std::fabs(pi - estimated_pi);
130+
bool failed = abs_error > 1.0e-3;
131+
if(failed) {
132+
std::cout << "TEST FAILED" << std::endl;
133+
} else {
134+
std::cout << "TEST PASSED" << std::endl;
135+
}
129136
std::cout << "Estimated value of Pi = " << estimated_pi << std::endl;
130137
std::cout << "Exact value of Pi = " << pi << std::endl;
131-
std::cout << "Absolute error = " << fabs(pi-estimated_pi) << std::endl;
138+
std::cout << "Absolute error = " << abs_error << std::endl;
132139
std::cout << std::endl;
133140

141+
if(failed) {
142+
return 1;
143+
}
144+
134145
return 0;
135146
}

Libraries/oneMKL/monte_carlo_pi/mc_pi_device_api.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,25 @@ int main(int argc, char ** argv) {
112112
} catch (...) {
113113
// Some other exception detected
114114
std::cout << "Failure" << std::endl;
115-
std::terminate();
115+
exit(1);
116116
}
117117

118118
// Printing results
119+
double abs_error = std::fabs(pi - estimated_pi);
120+
bool failed = abs_error > 1.0e-4;
121+
if(failed) {
122+
std::cout << "TEST FAILED" << std::endl;
123+
} else {
124+
std::cout << "TEST PASSED" << std::endl;
125+
}
119126
std::cout << "Estimated value of Pi = " << estimated_pi << std::endl;
120127
std::cout << "Exact value of Pi = " << pi << std::endl;
121-
std::cout << "Absolute error = " << fabs(pi-estimated_pi) << std::endl;
128+
std::cout << "Absolute error = " << abs_error << std::endl;
122129
std::cout << std::endl;
123130

131+
if(failed) {
132+
return 1;
133+
}
134+
124135
return 0;
125136
}

Libraries/oneMKL/monte_carlo_pi/mc_pi_usm.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/*
88
*
99
* Content:
10-
* This file contains Monte Carlo Pi number evaluation benchmark for DPC++
10+
* This file contains Monte Carlo Pi number evaluation benchmark for DPC++
1111
* USM-based interface of random number generators.
1212
*
1313
*******************************************************************************/
@@ -65,12 +65,14 @@ double estimate_pi(sycl::queue& q, size_t n_points) {
6565
sycl::vec<float, 2> r;
6666
size_t count = 0;
6767
for(int i = 0; i < count_per_thread; i++) {
68-
r.load(i + item.get_global_linear_id() * count_per_thread, sycl::global_ptr<float>(rng_ptr));
68+
// r.load(i + item.get_global_linear_id() * count_per_thread, sycl::global_ptr<float>(rng_ptr));
69+
r[0] = rng_ptr[2 * (i + item.get_global_linear_id() * count_per_thread)];
70+
r[1] = rng_ptr[2 * (i + item.get_global_linear_id() * count_per_thread) + 1];
6971
if(sycl::length(r) <= 1.0f) {
7072
count += 1;
7173
}
7274
}
73-
count_ptr[item.get_group_linear_id()] = reduce_over_group(item.get_group(), count, std::plus<size_t>());
75+
count_ptr[item.get_group_linear_id()] = sycl::reduce_over_group(item.get_group(), count, std::plus<size_t>());
7476
});
7577
});
7678

@@ -129,10 +131,21 @@ int main(int argc, char ** argv) {
129131
}
130132

131133
// Printing results
134+
double abs_error = std::fabs(pi - estimated_pi);
135+
bool failed = abs_error > 1.0e-3;
136+
if(failed) {
137+
std::cout << "TEST FAILED" << std::endl;
138+
} else {
139+
std::cout << "TEST PASSED" << std::endl;
140+
}
132141
std::cout << "Estimated value of Pi = " << estimated_pi << std::endl;
133142
std::cout << "Exact value of Pi = " << pi << std::endl;
134-
std::cout << "Absolute error = " << fabs(pi-estimated_pi) << std::endl;
143+
std::cout << "Absolute error = " << abs_error << std::endl;
135144
std::cout << std::endl;
136145

146+
if(failed) {
147+
return 1;
148+
}
149+
137150
return 0;
138151
}

0 commit comments

Comments
 (0)