ARTEMIS
IndexHandling.H
Go to the documentation of this file.
1 /* Copyright 2019-2022 Axel Huebl
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef ABLASTR_INDEX_HANDLING_H
8 #define ABLASTR_INDEX_HANDLING_H
9 
10 #include <cstdint>
11 
12 
13 namespace ablastr::particles {
14 
21  constexpr uint64_t
22  localIDtoGlobal (int const id, int const cpu)
23  {
24  static_assert(sizeof(int) * 2u <= sizeof(uint64_t),
25  "int size might cause collisions in global IDs");
26  // implementation:
27  // - we cast both 32-bit (or smaller) ints to a 64bit unsigned int
28  // - this will leave half of the "upper range" bits in the 64bit unsigned int zeroed out
29  // because the corresponding (extended) value range was not part of the value range in
30  // the int representation
31  // - we bit-shift the cpu into the upper half of zero bits in the 64 bit unsigned int
32  // (imagine this step as "adding a per-cpu/rank offset to the local integers")
33  // - then we add this offset
34  // note: the add is expressed as bitwise OR (|) since this saves us from writing
35  // brackets for operator precedence between + and <<
36  return uint64_t(id) | uint64_t(cpu) << 32u;
37  }
38 
39 } // namespace ablastr::particles
40 
41 #endif // ABLASTR_INDEX_HANDLING_H
Definition: DepositCharge.H:22
constexpr uint64_t localIDtoGlobal(int const id, int const cpu)
Definition: IndexHandling.H:22