CMS 3D CMS Logo

alpakastdAlgorithm.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
2 #define HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
3 
4 #include <algorithm>
5 #include <functional>
6 #include <utility>
7 
8 #include <alpaka/alpaka.hpp>
9 
10 // reimplementation of std algorithms able to compile with Alpaka,
11 // mostly by declaring them constexpr (until C++20, which will make it
12 // constexpr by default. TODO: drop when moving to C++20)
13 
14 namespace alpaka_std {
15 
16  template <typename RandomIt, typename T, typename Compare = std::less<T>>
17  ALPAKA_FN_HOST_ACC constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp = {}) {
18  auto count = last - first;
19 
20  while (count > 0) {
21  auto it = first;
22  auto step = count / 2;
23  it += step;
24  if (!comp(value, *it)) {
25  first = ++it;
26  count -= step + 1;
27  } else {
28  count = step;
29  }
30  }
31  return first;
32  }
33 
34 } // namespace alpaka_std
35 
36 #endif // HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
ALPAKA_FN_HOST_ACC constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: value.py:1
step
Definition: StallMonitor.cc:83
long double T