1 /* 2 Copyright (c) 2023 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #ifndef TBB_examples_pi_H 18 #define TBB_examples_pi_H 19 20 #include <cstdlib> 21 22 typedef std::size_t number_t; 23 typedef double pi_t; 24 25 extern const number_t chunk_size; 26 extern number_t num_intervals; 27 extern pi_t step; 28 29 extern bool silent; 30 pi_kernel(number_t i)31inline pi_t pi_kernel(number_t i) { 32 pi_t dx = (pi_t(i) + pi_t(0.5)) * step; 33 return pi_t(4.0) / (pi_t(1.0) + dx * dx); 34 } 35 36 inline double pi_slice_kernel(number_t slice, number_t slice_size = chunk_size) { 37 pi_t pi = pi_t(0.0); 38 for (number_t i = slice; i < slice + slice_size; ++i) { 39 pi += pi_kernel(i); 40 } 41 return pi; 42 } 43 44 struct threading { 45 threading(int p); 46 ~threading(); 47 }; 48 49 double compute_pi_parallel(); 50 51 #endif // TBB_examples_pi_H 52