JDFTx  1.2.0
LoopMacros.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman
3 
4 This file is part of JDFTx.
5 
6 JDFTx is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 JDFTx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
18 -------------------------------------------------------------------*/
19 
20 #ifndef JDFTX_CORE_LOOPMACROS_H
21 #define JDFTX_CORE_LOOPMACROS_H
22 
24 #define THREAD_rLoop(code) \
25  size_t i=iStart; \
26  vector3<int> iv( \
27  i / (S[2]*S[1]), \
28  (i/S[2]) % S[1], \
29  i % S[2] ); \
30  while(i<iStop) \
31  { \
32  code \
33  \
34  i++; if(i==iStop) break; \
35  iv[2]++; \
36  if(iv[2]==S[2]) \
37  { iv[2]=0; \
38  iv[1]++; \
39  if(iv[1]==S[1]) \
40  { iv[1] = 0; \
41  iv[0]++; \
42  } \
43  } \
44  }
45 
47 #define COMPUTE_rIndices \
48  vector3<int> iv( \
49  threadIdx.z + zBlock * blockDim.z, \
50  kernelIndex(y), \
51  kernelIndex(x) ); \
52  if(iv[0]>=S[0] || iv[1]>=S[1] || iv[2]>=S[2]) return; \
53  size_t i = iv[2] + S[2]*size_t(iv[1] + S[1]*iv[0]);
54 
55 
57 #define THREAD_fullGspaceLoop(code) \
58  size_t i=iStart; \
59  vector3<int> iG( i / (S[2]*S[1]), (i/S[2]) % S[1], i % S[2] ); \
60  for(int j=0; j<3; j++) if(2*iG[j]>S[j]) iG[j]-=S[j]; \
61  while(true) \
62  { \
63  code \
64  \
65  i++; if(i==iStop) break; \
66  iG[2]++; \
67  if(2*iG[2]>S[2]) iG[2]-=S[2]; \
68  if(iG[2]==0) \
69  { iG[1]++; \
70  if(2*iG[1]>S[1]) iG[1]-=S[1]; \
71  if(iG[1]==0) \
72  { iG[0]++; \
73  if(2*iG[0]>S[0]) iG[0]-=S[0]; \
74  } \
75  } \
76  }
77 
80 #define COMPUTE_fullGindices \
81  vector3<int> iG( \
82  zBlock * blockDim.z + threadIdx.z, \
83  kernelIndex(y), \
84  kernelIndex(x) ); \
85  if(iG[0]>=S[0] || iG[1]>=S[1] || iG[2]>=S[2]) return; \
86  size_t i = iG[2] + S[2]*size_t(iG[1] + S[1]*iG[0]); \
87  for(int j=0; j<3; j++) if(2*iG[j]>S[j]) iG[j]-=S[j];
88 
89 
91 #define THREAD_halfGspaceLoop(code) \
92  int size2 = S[2]/2+1; \
93  size_t i=iStart; \
94  vector3<int> iG( i / (size2*S[1]), (i/size2) % S[1], i % size2 ); \
95  for(int j=0; j<3; j++) if(2*iG[j]>S[j]) iG[j]-=S[j]; \
96  while(i<iStop) \
97  { \
98  code \
99  \
100  i++; if(i==iStop) break; \
101  iG[2]++; \
102  if(iG[2]==size2) \
103  { iG[2]=0; \
104  iG[1]++; \
105  if(2*iG[1]>S[1]) iG[1]-=S[1]; \
106  if(iG[1]==0) \
107  { iG[0]++; \
108  if(2*iG[0]>S[0]) iG[0]-=S[0]; \
109  } \
110  } \
111  }
112 
115 #define COMPUTE_halfGindices \
116  int size2 = S[2]/2+1; \
117  vector3<int> iG( \
118  threadIdx.z + zBlock * blockDim.z, \
119  kernelIndex(y), \
120  kernelIndex(x) ); \
121  if(iG[0]>=S[0] || iG[1]>=S[1] || iG[2]>=size2) return; \
122  size_t i = iG[2] + size2*size_t(iG[1] + S[1]*iG[0]); \
123  for(int j=0; j<3; j++) if(2*iG[j]>S[j]) iG[j]-=S[j];
124 
127 #define IS_NYQUIST ( (!(2*iG[0]-S[0])) | (!(2*iG[1]-S[1])) | (!(2*iG[2]-S[2])) )
128 
129 #endif // JDFTX_CORE_LOOPMACROS_H