QUDA  v1.1.0
A library for QCD on GPUs
comm_key.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace quda
4 {
5 
6  struct CommKey {
7 
8  static constexpr int n_dim = 4;
9 
10  int array[n_dim] = {0, 0, 0, 0};
11 
12  constexpr inline int product() { return array[0] * array[1] * array[2] * array[3]; }
13 
14  constexpr inline int &operator[](int d) { return array[d]; }
15 
16  constexpr inline const int &operator[](int d) const { return array[d]; }
17 
18  constexpr inline int *data() { return array; }
19 
20  constexpr inline const int *data() const { return array; }
21 
22  constexpr inline bool is_valid() const
23  {
24  return (array[0] > 0) && (array[1] > 0) && (array[2] > 0) && (array[3] > 0);
25  }
26  };
27 
28  constexpr int inline product(const CommKey &input) { return input[0] * input[1] * input[2] * input[3]; }
29 
30  constexpr CommKey inline operator+(const CommKey &lhs, const CommKey &rhs)
31  {
32  CommKey sum;
33  for (int d = 0; d < CommKey::n_dim; d++) { sum[d] = lhs[d] + rhs[d]; }
34  return sum;
35  }
36 
37  constexpr CommKey inline operator*(const CommKey &lhs, const CommKey &rhs)
38  {
40  for (int d = 0; d < CommKey::n_dim; d++) { product[d] = lhs[d] * rhs[d]; }
41  return product;
42  }
43 
44  constexpr CommKey inline operator/(const CommKey &lhs, const CommKey &rhs)
45  {
46  CommKey quotient;
47  for (int d = 0; d < CommKey::n_dim; d++) { quotient[d] = lhs[d] / rhs[d]; }
48  return quotient;
49  }
50 
51  constexpr CommKey inline operator%(const CommKey &lhs, const CommKey &rhs)
52  {
53  CommKey mod;
54  for (int d = 0; d < CommKey::n_dim; d++) { mod[d] = lhs[d] % rhs[d]; }
55  return mod;
56  }
57 
58  constexpr bool inline operator<(const CommKey &lhs, const CommKey &rhs)
59  {
60  for (int d = 0; d < CommKey::n_dim; d++) {
61  if (lhs[d] < rhs[d]) { return true; }
62  }
63  return false;
64  }
65 
66  constexpr bool inline operator>(const CommKey &lhs, const CommKey &rhs)
67  {
68  for (int d = 0; d < CommKey::n_dim; d++) {
69  if (lhs[d] > rhs[d]) { return true; }
70  }
71  return false;
72  }
73 
74  constexpr CommKey inline coordinate_from_index(int index, CommKey dim)
75  {
76  CommKey coord;
77  for (int d = 0; d < CommKey::n_dim; d++) {
78  coord[d] = index % dim[d];
79  index /= dim[d];
80  }
81  return coord;
82  }
83 
84  constexpr int inline index_from_coordinate(CommKey coord, CommKey dim)
85  {
86  return ((coord[3] * dim[2] + coord[2]) * dim[1] + coord[1]) * dim[0] + coord[0];
87  }
88 
89 } // namespace quda
std::array< int, 4 > dim
constexpr int index_from_coordinate(CommKey coord, CommKey dim)
Definition: comm_key.h:84
constexpr bool operator<(const CommKey &lhs, const CommKey &rhs)
Definition: comm_key.h:58
__device__ __host__ ColorSpinor< Float, Nc, Ns > operator*(const S &a, const ColorSpinor< Float, Nc, Ns > &x)
Compute the scalar-vector product y = a * x.
constexpr int product(const CommKey &input)
Definition: comm_key.h:28
constexpr bool operator>(const CommKey &lhs, const CommKey &rhs)
Definition: comm_key.h:66
__device__ __host__ ColorSpinor< Float, Nc, Ns > operator+(const ColorSpinor< Float, Nc, Ns > &x, const ColorSpinor< Float, Nc, Ns > &y)
ColorSpinor addition operator.
constexpr CommKey coordinate_from_index(int index, CommKey dim)
Definition: comm_key.h:74
constexpr CommKey operator%(const CommKey &lhs, const CommKey &rhs)
Definition: comm_key.h:51
constexpr CommKey operator/(const CommKey &lhs, const CommKey &rhs)
Definition: comm_key.h:44
__host__ __device__ T sum(const array< T, s > &a)
Definition: utility.h:76
constexpr int product()
Definition: comm_key.h:12
constexpr const int & operator[](int d) const
Definition: comm_key.h:16
static constexpr int n_dim
Definition: comm_key.h:8
constexpr int & operator[](int d)
Definition: comm_key.h:14
int array[n_dim]
Definition: comm_key.h:10
constexpr const int * data() const
Definition: comm_key.h:20
constexpr int * data()
Definition: comm_key.h:18
constexpr bool is_valid() const
Definition: comm_key.h:22