aboutsummaryrefslogtreecommitdiff
path: root/Source/Utils/Algorithms/UpperBound.H
diff options
context:
space:
mode:
authorGravatar Luca Fedeli <luca.fedeli@cea.fr> 2022-10-10 20:36:14 +0200
committerGravatar GitHub <noreply@github.com> 2022-10-10 11:36:14 -0700
commite9cc65ffeb0684a97618b67c2164d95ea497226c (patch)
treeed65f7ac86cc4e8945021dc36a79c8bc246c150d /Source/Utils/Algorithms/UpperBound.H
parent56e04c1b911f9399662c4ff9ecf6630d686cc220 (diff)
downloadWarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.tar.gz
WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.tar.zst
WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.zip
Partial refactoring of the utils directory (#3404)
* initial work to clean WarpX Utils * remove AMRCore from Ionization tables * progress * refactoring of a part of the utils directory * fix bug * fixed bug * fixed bug * remove debug line accidentally slipped into the code * remove debug line accidentally slipped into the code * remove debug line accidentally slipped into the code * cleaning * fixed bug
Diffstat (limited to 'Source/Utils/Algorithms/UpperBound.H')
-rw-r--r--Source/Utils/Algorithms/UpperBound.H49
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/Utils/Algorithms/UpperBound.H b/Source/Utils/Algorithms/UpperBound.H
new file mode 100644
index 000000000..8a528971a
--- /dev/null
+++ b/Source/Utils/Algorithms/UpperBound.H
@@ -0,0 +1,49 @@
+/* Copyright 2022 Luca Fedeli
+ *
+ * This file is part of WarpX.
+ *
+ * License: BSD-3-Clause-LBNL
+ */
+
+#ifndef WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_
+#define WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_
+
+#include <AMReX_Extension.H>
+#include <AMReX_GpuQualifiers.H>
+
+namespace utils::algorithms
+{
+
+ /** \brief Returns a pointer to the first element in the range [first, last) that is greater than val
+ *
+ * A re-implementation of the upper_bound algorithm suitable for GPU kernels.
+ *
+ * @param first: pointer to left limit of the range to consider
+ * @param last: pointer to right limit of the range to consider
+ * @param val: value to compare the elements of [first, last) to
+ */
+ template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
+ const T* upper_bound(const T* first, const T* last, const T& val)
+ {
+ const T* it;
+ size_t count, step;
+ count = last-first;
+ while(count>0){
+ it = first;
+ step = count/2;
+ it += step;
+ if (!(val<*it)){
+ first = ++it;
+ count -= step + 1;
+ }
+ else{
+ count = step;
+ }
+ }
+
+ return first;
+ }
+
+}
+
+#endif //WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_