| 14 | |
| 15 | template<typename IteratorT, typename FilterT, typename ActionT> |
| 16 | void |
| 17 | iteratorMultithreading( |
| 18 | const IteratorT& start, |
| 19 | const IteratorT& end, |
| 20 | const FilterT& filter, |
| 21 | const ActionT& action, |
| 22 | const int threads = 0) |
| 23 | { |
| 24 | #if _OPENMP |
| 25 | int threadsBefore = 1; |
| 26 | if (threads > 0) { |
| 27 | threadsBefore = omp_get_max_threads(); |
| 28 | omp_set_num_threads(threads); |
| 29 | } |
| 30 | #else |
| 31 | (void)threads; |
| 32 | #endif |
| 33 | IteratorT it = start; |
| 34 | while (it != end) { |
| 35 | #pragma omp parallel |
| 36 | #pragma omp single |
| 37 | { |
| 38 | #if _OPENMP |
| 39 | for (unsigned i = 0; i < MAX_SIMULTANEOUS_TASKS; i++) |
| 40 | #endif |
| 41 | { |
| 42 | if (filter(*it)) { |
| 43 | #pragma omp task firstprivate(it) |
| 44 | { |
| 45 | action(*it); |
| 46 | } |
| 47 | } |
| 48 | ++it; |
| 49 | #if _OPENMP |
| 50 | if (it == end) |
| 51 | break; |
| 52 | #endif |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | #if _OPENMP |
| 57 | if (threads > 0) { |
| 58 | omp_set_num_threads(threadsBefore); |
| 59 | } |
| 60 | #endif |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | progressStart(const std::string& name, unsigned total); |
no outgoing calls
no test coverage detected