aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/prolongate_3d_dgfe_rf2.cc
blob: c16d59061da10c91a35bb018d800c2e4238ac3dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#include <cctk.h>
#include <cctk_Parameters.h>

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>

#include <hrscc.hh>

#include "operator_prototypes_3d.hh"
#include "typeprops.hh"

using namespace std;
#ifdef HRSCC_GLL_ELEMENT_HH
using namespace hrscc;
#endif



namespace CarpetLib {
  
#define SRCIND3(i,j,k)                          \
  index3 (i, j, k,                              \
          srcipadext, srcjpadext, srckpadext,   \
          srciext, srcjext, srckext)
#define DSTIND3(i,j,k)                          \
  index3 (i, j, k,                              \
          dstipadext, dstjpadext, dstkpadext,   \
          dstiext, dstjext, dstkext)
#define SRCOFF3(i,j,k)                          \
  offset3 (i, j, k,                             \
           srciext, srcjext, srckext)
#define DSTOFF3(i,j,k)                          \
  offset3 (i, j, k,                             \
           dstiext, dstjext, dstkext)
  
  
  
  template<typename T, int ORDER>
  void
  prolongate_3d_dgfe_rf2(T const *restrict const src,
                         ivect3 const& restrict srcpadext,
                         ivect3 const& restrict srcext,
                         T *restrict const dst,
                         ivect3 const& restrict dstpadext,
                         ivect3 const& restrict dstext,
                         ibbox3 const& restrict srcbbox,
                         ibbox3 const& restrict dstbbox,
                         ibbox3 const& restrict,
                         ibbox3 const& restrict regbbox,
                         void* const extraargs)
  {
#ifdef HRSCC_GLL_ELEMENT_HH
    assert(not extraargs);
    
    static_assert(ORDER>=0, "ORDER must be non-negative");
    
    
    
    if (any(srcbbox.stride() <= regbbox.stride() or
            dstbbox.stride() != regbbox.stride()))
    {
      CCTK_WARN(0, "Internal error: strides disagree");
    }
    
    if (any(srcbbox.stride() != reffact2 * dstbbox.stride())) {
      CCTK_WARN(0, "Internal error: source strides are not twice the destination strides");
    }
    
    if (any(dstbbox.stride() % 2 != 0)) {
      CCTK_WARN(0, "Internal error: destination strides are not even");
    }
    
    // This could be handled, but is likely to point to an error
    // elsewhere
    if (regbbox.empty()) {
      CCTK_WARN(0, "Internal error: region extent is empty");
    }
    
    
    
    bvect3 const is_upper_face =
      (regbbox.lower() - srcbbox.lower() + regbbox.stride() / 2) %
      srcbbox.stride() != 0;
    
    ivect3 const regext = regbbox.shape() / regbbox.stride();
    assert(all((regbbox.lower() - srcbbox.lower() +
                either(is_upper_face, -1, +1) * regbbox.stride() / 2) %
               srcbbox.stride() == 0));
    ivect3 const srcoff =
      (regbbox.lower()- srcbbox.lower() +
       either(is_upper_face, -1, +1) * regbbox.stride() / 2) /
      srcbbox.stride();
    assert(all((regbbox.lower() - dstbbox.lower()) % regbbox.stride() == 0));
    ivect3 const dstoff =
      (regbbox.lower() - dstbbox.lower()) / regbbox.stride();
    
    
    
    if (not regbbox.is_contained_in(srcbbox) or
        not regbbox.is_contained_in(dstbbox))
    {
      cerr << "ORDER=" << ORDER << "\n"
           << "regbbox=" << regbbox << "\n"
           << "dstbbox=" << dstbbox << "\n"
           << "regbbox=" << regbbox << "\n"
           << "srcbbox=" << srcbbox << "\n";
      CCTK_WARN(0, "Internal error: region extent is not contained in array extent");
    }
    
    
    
    ptrdiff_t const srcipadext = srcpadext[0];
    ptrdiff_t const srcjpadext = srcpadext[1];
    ptrdiff_t const srckpadext = srcpadext[2];
    
    ptrdiff_t const dstipadext = dstpadext[0];
    ptrdiff_t const dstjpadext = dstpadext[1];
    ptrdiff_t const dstkpadext = dstpadext[2];
    
    ptrdiff_t const srciext = srcext[0];
    ptrdiff_t const srcjext = srcext[1];
    ptrdiff_t const srckext = srcext[2];
    
    ptrdiff_t const dstiext = dstext[0];
    ptrdiff_t const dstjext = dstext[1];
    ptrdiff_t const dstkext = dstext[2];
    
    ptrdiff_t const regiext = regext[0];
    ptrdiff_t const regjext = regext[1];
    ptrdiff_t const regkext = regext[2];
    
    ptrdiff_t const srcioff = srcoff[0];
    ptrdiff_t const srcjoff = srcoff[1];
    ptrdiff_t const srckoff = srcoff[2];
    
    ptrdiff_t const dstioff = dstoff[0];
    ptrdiff_t const dstjoff = dstoff[1];
    ptrdiff_t const dstkoff = dstoff[2];
    
    
    
    if (regext[0] == 1) {
      // 2D prolongation on x face
      
      assert(not is_upper_face[1]);
      assert(not is_upper_face[2]);
      
      // Ensure we traverse an even integer number of elements
      assert(regext[1] % (2*(ORDER+1)) == 0);
      assert(regext[2] % (2*(ORDER+1)) == 0);
      
      int const srcdi = 1;      // 2d face
      int const srcdj = SRCOFF3(0,1,0) - SRCOFF3(0,0,0);
      int const srcdk = SRCOFF3(0,0,1) - SRCOFF3(0,0,0);
      int const dstdi = 1;      // 2d face
      int const dstdj = DSTOFF3(0,1,0) - DSTOFF3(0,0,0);
      int const dstdk = DSTOFF3(0,0,1) - DSTOFF3(0,0,0);
      int const srcstr2d[2] = {srcdj, srcdk};
      int const dststr2d[2] = {dstdj, dstdk};
      
      // Loop over fine region
      ptrdiff_t const i=0;
#pragma omp parallel for collapse(2)
      // Zwicky's Intel compiler 11.1 ices on ptrdiff_t
      for (/*ptrdiff_t*/int k=0; k<regkext; k+=2*(ORDER+1)) {
        for (/*ptrdiff_t*/int j=0; j<regjext; j+=2*(ORDER+1)) {
          GLLElement<ORDER>::prolongate_2D
            (&src[SRCIND3(srcioff+i, srcjoff+j, srckoff+k)], srcstr2d,
             &dst[DSTIND3(dstioff+2*i, dstjoff+2*j, dstkoff+2*k)], dststr2d);
        }
      }
      
    } else if (regext[1] == 1) {
      // 2D prolongation on y face
      
      assert(not is_upper_face[0]);
      assert(not is_upper_face[2]);
      
      // Ensure we traverse an even integer number of elements
      assert(regext[0] % (2*(ORDER+1)) == 0);
      assert(regext[2] % (2*(ORDER+1)) == 0);
      
      // int const srcdi = SRCOFF3(1,0,0) - SRCOFF3(0,0,0);
      int const srcdi = 1;
      assert(srcdi == SRCOFF3(1,0,0) - SRCOFF3(0,0,0));
      int const srcdj = 1;      // 2d face
      int const srcdk = SRCOFF3(0,0,1) - SRCOFF3(0,0,0);
      // int const dstdi = DSTOFF3(1,0,0) - DSTOFF3(0,0,0);
      int const dstdi = 1;
      assert(dstdi == DSTOFF3(1,0,0) - DSTOFF3(0,0,0));
      int const dstdj = 1;      // 2d face
      int const dstdk = DSTOFF3(0,0,1) - DSTOFF3(0,0,0);
      int const srcstr2d[2]= {srcdi, srcdk};
      int const dststr2d[2]= {dstdi, dstdk};
      
      // Loop over fine region
      ptrdiff_t const j=0;
#pragma omp parallel for collapse(2)
      // Zwicky's Intel compiler 11.1 ices on ptrdiff_t
      for (/*ptrdiff_t*/int k=0; k<regkext; k+=2*(ORDER+1)) {
        for (/*ptrdiff_t*/int i=0; i<regiext; i+=2*(ORDER+1)) {
          GLLElement<ORDER>::prolongate_2D
            (&src[SRCIND3(srcioff+i, srcjoff+j, srckoff+k)], srcstr2d,
             &dst[DSTIND3(dstioff+2*i, dstjoff+2*j, dstkoff+2*k)], dststr2d);
        }
      }
      
    } else if (regext[2] == 1) {
      // 2D prolongation on z face
      
      assert(not is_upper_face[0]);
      assert(not is_upper_face[1]);
      
      // Ensure we traverse an even integer number of elements
      assert(regext[0] % (2*(ORDER+1)) == 0);
      assert(regext[1] % (2*(ORDER+1)) == 0);
      
      // int const srcdi = SRCOFF3(1,0,0) - SRCOFF3(0,0,0);
      int const srcdi = 1;
      assert(srcdi == SRCOFF3(1,0,0) - SRCOFF3(0,0,0));
      int const srcdj = SRCOFF3(0,1,0) - SRCOFF3(0,0,0);
      int const srcdk = 1;      // 2d face
      // int const dstdi = DSTOFF3(1,0,0) - DSTOFF3(0,0,0);
      int const dstdi = 1;
      assert(dstdi == DSTOFF3(1,0,0) - DSTOFF3(0,0,0));
      int const dstdj = DSTOFF3(0,1,0) - DSTOFF3(0,0,0);
      int const dstdk = 1;      // 2d face
      int const srcstr2d[2]= {srcdi, srcdj};
      int const dststr2d[2]= {dstdi, dstdj};
      
      // Loop over fine region
      ptrdiff_t const k=0;
#pragma omp parallel for collapse(2)
      // Zwicky's Intel compiler 11.1 ices on ptrdiff_t
      for (/*ptrdiff_t*/int j=0; j<regjext; j+=2*(ORDER+1)) {
        for (/*ptrdiff_t*/int i=0; i<regiext; i+=2*(ORDER+1)) {
          GLLElement<ORDER>::prolongate_2D
            (&src[SRCIND3(srcioff+i, srcjoff+j, srckoff+k)], srcstr2d,
             &dst[DSTIND3(dstioff+2*i, dstjoff+2*j, dstkoff+2*k)], dststr2d);
        }
      }
      
    } else {
      // 3D prolongation
      
      assert(not any(is_upper_face));
      
      // Ensure we traverse an even integer number of elements
      assert(all(regext % (2*(ORDER+1)) == 0));
      
      // int const srcdi = SRCOFF3(1,0,0) - SRCOFF3(0,0,0);
      int const srcdi = 1;
      assert(srcdi == SRCOFF3(1,0,0) - SRCOFF3(0,0,0));
      int const srcdj = SRCOFF3(0,1,0) - SRCOFF3(0,0,0);
      int const srcdk = SRCOFF3(0,0,1) - SRCOFF3(0,0,0);
      // int const dstdi = DSTOFF3(1,0,0) - DSTOFF3(0,0,0);
      int const dstdi = 1;
      assert(dstdi == DSTOFF3(1,0,0) - DSTOFF3(0,0,0));
      int const dstdj = DSTOFF3(0,1,0) - DSTOFF3(0,0,0);
      int const dstdk = DSTOFF3(0,0,1) - DSTOFF3(0,0,0);
      int const srcstr[3] = {srcdi, srcdj, srcdk};
      int const dststr[3] = {dstdi, dstdj, dstdk};
      
      // Loop over fine region
#pragma omp parallel for collapse(3)
      // Zwicky's Intel compiler 11.1 ices on ptrdiff_t
      for (/*ptrdiff_t*/int k=0; k<regkext; k+=2*(ORDER+1)) {
        for (/*ptrdiff_t*/int j=0; j<regjext; j+=2*(ORDER+1)) {
          for (/*ptrdiff_t*/int i=0; i<regiext; i+=2*(ORDER+1)) {
            GLLElement<ORDER>::prolongate_full
              (&src[SRCIND3(srcioff+i, srcjoff+j, srckoff+k)], srcstr,
               &dst[DSTIND3(dstioff+2*i, dstjoff+2*j, dstkoff+2*k)], dststr);
          }
        }
      }
      
    }
    
#else
    // HRSCCore is not available
    assert(0);
#endif
  }
  
  
  
#define TYPECASE(N,T)                                           \
                                                                \
  template                                                      \
  void                                                          \
  prolongate_3d_dgfe_rf2<T,5>(T const *restrict const src,      \
                              ivect3 const& restrict srcpadext, \
                              ivect3 const& restrict srcext,    \
                              T *restrict const dst,            \
                              ivect3 const& restrict dstpadext, \
                              ivect3 const& restrict dstext,    \
                              ibbox3 const& restrict srcbbox,   \
                              ibbox3 const& restrict dstbbox,   \
                              ibbox3 const& restrict,           \
                              ibbox3 const& restrict regbbox,   \
                              void *extraargs);
  
#define CARPET_NO_INT
#define CARPET_NO_COMPLEX
#include "typecase.hh"
#undef TYPECASE
  
  
  
  template<>
  void
  prolongate_3d_dgfe_rf2<CCTK_COMPLEX,5>(CCTK_COMPLEX const *restrict const src,
                                         ivect3 const& restrict srcpadext,
                                         ivect3 const& restrict srcext,
                                         CCTK_COMPLEX *restrict const dst,
                                         ivect3 const& restrict dstpadext,
                                         ivect3 const& restrict dstext,
                                         ibbox3 const& restrict srcbbox,
                                         ibbox3 const& restrict dstbbox,
                                         ibbox3 const& restrict,
                                         ibbox3 const& restrict regbbox,
                                         void *extraargs)
  {
    assert(0);
  }
  
} // namespace CarpetLib