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

Namespaces

namespace  detail

Functions

int width ()
int parts (int width)
template<class F>
void run (const std::vector< std::size_t > &sizes, F &&fn)
template<class F>
void run (std::initializer_list< std::size_t > chunks, F &&fn)
std::size_t chunksOf (std::size_t n, std::size_t grain)
template<class F>
void forRange (std::size_t n, std::size_t grain, F &&fn)

Function Documentation

◆ chunksOf()

std::size_t seams::team::chunksOf ( std::size_t n,
std::size_t grain )
inline

Definition at line 171 of file team_run.hpp.

171 {
172 return grain == 0 ? 0 : (n + grain - 1) / grain;
173}

◆ forRange()

template<class F>
void seams::team::forRange ( std::size_t n,
std::size_t grain,
F && fn )

Definition at line 178 of file team_run.hpp.

178 {
179 if (n == 0) {
180 return;
181 }
182 std::size_t count = chunksOf(n, std::max<std::size_t>(1, grain));
183 const int most = width();
184 const auto workers = static_cast<std::size_t>(
185 othersHoldHalf() ? most : std::max(1, std::min(most, teamWidth())));
186 if (count > 1 && workers > 1) {
187 count = std::min(n, (count + workers - 1) / workers * workers);
188 }
189 const std::size_t step = chunksOf(n, count);
190 run({chunksOf(n, step)}, [&](std::size_t, std::size_t chunk, int worker) {
191 const std::size_t begin = chunk * step;
192 fn(begin, std::min(n, begin + step), worker);
193 });
194}
void run(const std::vector< std::size_t > &sizes, F &&fn)
Definition team_run.hpp:139
int width()
Definition team_run.hpp:44
std::size_t chunksOf(std::size_t n, std::size_t grain)
Definition team_run.hpp:171
int teamWidth()
bool othersHoldHalf()

◆ parts()

int seams::team::parts ( int width)
inline

Definition at line 64 of file team_run.hpp.

64 {
65 if (width <= 1) {
66 return 1;
67 }
68 return othersHoldHalf() ? 2 * width : std::max(1, std::min(width, teamWidth()));
69}

◆ run() [1/2]

template<class F>
void seams::team::run ( const std::vector< std::size_t > & sizes,
F && fn )

Definition at line 139 of file team_run.hpp.

139 {
140 if (sizes.empty()) {
141 return;
142 }
143 detail::Call<std::remove_reference_t<F>> call;
144 call.fn = &fn;
145#if defined(SEAMS_HAS_LINKCELL) && defined(SEAMS_HAS_LINKCELL_TEAM)
146 bool nested = false;
147#ifdef SEAMS_HAS_OPENMP
148 nested = omp_in_parallel() != 0;
149#endif
150 if (!nested && othersHoldHalf()) {
152 if (lc_team_run(sizes.size(), sizes.data(), &decltype(call)::trampoline, &call) != 0) {
153 throw std::runtime_error("linkcell team run failed");
154 }
155 } else {
156 detail::ompRun(sizes, call);
157 }
158#else
159 detail::ompRun(sizes, call);
160#endif
161 if (call.failure) {
162 std::rethrow_exception(call.failure);
163 }
164}
void ompRun(const std::vector< std::size_t > &sizes, C &call)
Definition team_run.hpp:100
int poolFor(int n)
void lc_set_threads(int n)

◆ run() [2/2]

template<class F>
void seams::team::run ( std::initializer_list< std::size_t > chunks,
F && fn )

Definition at line 166 of file team_run.hpp.

166 {
167 run(std::vector<std::size_t>(chunks), std::forward<F>(fn));
168}

◆ width()

int seams::team::width ( )
inline

Definition at line 44 of file team_run.hpp.

44 {
45#ifdef SEAMS_HAS_OPENMP
46 if (omp_in_parallel()) {
47 return 1;
48 }
49#endif
50#ifdef SEAMS_HAS_LINKCELL
51 return std::max(teamWidth(), poolFor(0));
52#else
53 return teamWidth();
54#endif
55}