seams-core v2.14.2
libyodaLib, the C++ engine of d-SEAMS
Loading...
Searching...
No Matches
seams::team::detail Namespace Reference

Classes

struct  Call

Functions

template<class C>
void ompRun (const std::vector< std::size_t > &sizes, C &call)

Function Documentation

◆ ompRun()

template<class C>
void seams::team::detail::ompRun ( const std::vector< std::size_t > & sizes,
C & call )

Definition at line 100 of file team_run.hpp.

100 {
101 std::size_t most = 0;
102 for (const std::size_t n : sizes) {
103 most = std::max(most, n);
104 }
105#ifdef SEAMS_HAS_OPENMP
106 const int threads =
107 omp_in_parallel() ? 1 : static_cast<int>(std::min<std::size_t>(
108 static_cast<std::size_t>(omp_get_max_threads()), most));
109 if (threads > 1) {
110#pragma omp parallel num_threads(threads)
111 {
112 const std::size_t worker = static_cast<std::size_t>(omp_get_thread_num());
113 for (std::size_t s = 0; s < sizes.size(); ++s) {
114 const long long count = static_cast<long long>(sizes[s]);
115 // Each thread takes one contiguous run of chunks, as the loops
116 // this replaced did.
117#pragma omp for schedule(static)
118 for (long long c = 0; c < count; ++c) {
119 call.one(s, static_cast<std::size_t>(c), worker);
120 }
121 }
122 }
123 return;
124 }
125#endif
126 for (std::size_t s = 0; s < sizes.size(); ++s) {
127 for (std::size_t c = 0; c < sizes[s]; ++c) {
128 call.one(s, c, 0);
129 }
130 }
131}