|
7 | 7 | /* |
8 | 8 | * |
9 | 9 | * 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++ |
11 | 11 | * USM-based interface of random number generators. |
12 | 12 | * |
13 | 13 | *******************************************************************************/ |
@@ -65,12 +65,14 @@ double estimate_pi(sycl::queue& q, size_t n_points) { |
65 | 65 | sycl::vec<float, 2> r; |
66 | 66 | size_t count = 0; |
67 | 67 | 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]; |
69 | 71 | if(sycl::length(r) <= 1.0f) { |
70 | 72 | count += 1; |
71 | 73 | } |
72 | 74 | } |
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>()); |
74 | 76 | }); |
75 | 77 | }); |
76 | 78 |
|
@@ -129,10 +131,21 @@ int main(int argc, char ** argv) { |
129 | 131 | } |
130 | 132 |
|
131 | 133 | // 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 | + } |
132 | 141 | std::cout << "Estimated value of Pi = " << estimated_pi << std::endl; |
133 | 142 | 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; |
135 | 144 | std::cout << std::endl; |
136 | 145 |
|
| 146 | + if(failed) { |
| 147 | + return 1; |
| 148 | + } |
| 149 | + |
137 | 150 | return 0; |
138 | 151 | } |
0 commit comments