aboutsummaryrefslogtreecommitdiff
path: root/CarpetDev/CarpetIOF5/src/distribute.cc
blob: 05658ee4273facfec3aad12a9a1e1b2e2095b508 (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#include "distribute.hh"

#include <cctk_Parameters.h>

#include <carpet.hh>

#include <cassert>
#include <cstdlib>
#include <cstring>
#include <vector>



namespace CarpetIOF5 {
  
  using namespace std;
  
  
  
  /*** fragdesc_t *************************************************************/
  
  int fragdesc_t::npoints() const
  {
    int np = 1;
    for (int d=0; d<dim; ++d) {
      np *= imax[d] - imin[d] + 1;
    }
    assert(np>0);
    return np;
  }
  
  int fragdesc_t::vartypesize() const
  {
    assert(varindex>=0);
    int const vartype = CCTK_VarTypeI(varindex);
    assert(vartype>=0);
    int const size = CCTK_VarTypeSize(vartype);
    assert(size>0);
    return size;
  }
  
  MPI_Datatype fragdesc_t::datatype() const
  {
    assert(varindex>=0);
    int const vartype = CCTK_VarTypeI(varindex);
    assert(vartype>=0);
    switch (vartype) {
    case CCTK_VARIABLE_BYTE   : return dist::mpi_datatype<CCTK_BYTE   >();
    case CCTK_VARIABLE_INT    : return dist::mpi_datatype<CCTK_INT    >();
    case CCTK_VARIABLE_REAL   : return dist::mpi_datatype<CCTK_REAL   >();
    case CCTK_VARIABLE_COMPLEX: return dist::mpi_datatype<CCTK_COMPLEX>();
    default: assert(0);
    }
  }
  
  
  
  /*** scatter_t **************************************************************/
  
  scatter_t::scatter_t(cGH const *const cctkGH_)
    : cctkGH(cctkGH_),
      num_received(0), num_sent(0), bytes_allocated(0),
      did_send_all(false),
      did_receive_sent_all(0), did_receive_all_sent_all(false)
  {
    DECLARE_CCTK_PARAMETERS;
    if (verbose) {
      CCTK_INFO("Creating global scatter object");
    }
    post_public_recvs();
  }
  
  
  
  scatter_t::~scatter_t()
  {
    DECLARE_CCTK_PARAMETERS;
    if (verbose) {
      CCTK_INFO("Shutting down global scatter object");
    }
    
    // Wait until everything has been sent
    bool did_send_everything;
    for (;;) {
      if (verbose) {
        CCTK_INFO("Waiting until something has been transmitted...");
      }
      did_send_everything = sends.empty();
      if (did_send_everything) break;
      do_some_work(true);
    }
    if (verbose) {
      CCTK_INFO("We sent all our data");
    }
    
    // Notify others: we sent all our data
    set_did_send_all();
    
    // Wait until everything has been transmitted
    bool did_transmit_everything;
    for (;;) {
      if (verbose) {
        CCTK_INFO("Waiting until something has been transmitted...");
      }
      did_transmit_everything =
        did_receive_all_sent_all and recvs.empty() and sends.empty();
      if (did_transmit_everything) break;
      do_some_work(true);
    }
    if (verbose) {
      CCTK_INFO("Everything has been transmitted");
    }
    
    int const my_difference = num_sent - num_received;
    int total_difference;
    MPI_Allreduce(const_cast<int*>(&my_difference), &total_difference,
                  1, MPI_INT, MPI_SUM,
                  dist::comm());
    if (total_difference < 0) {
      CCTK_WARN(CCTK_WARN_ABORT,
                "More received messages than sent messages -- impossible!");
    }
    if (total_difference > 0) {
      CCTK_WARN(CCTK_WARN_ABORT, "Not all sent messages have been received");
    }
    if (verbose) {
      CCTK_INFO("Global number of sent and received messages is consistent");
    }
    
    // Cancel the public receives
    if (verbose) {
      CCTK_INFO("Cancelling all public receives...");
    }
    while (not public_recvs.empty()) {
      list<transmission_t*>::iterator const tmi = public_recvs.begin();
      transmission_t *const tm = *tmi;
      MPI_Cancel(&tm->request);
      public_recvs.erase(tmi);
    }
    
    if (verbose) {
      CCTK_INFO("Destroying down global scatter object");
    }
    
    assert(public_recvs.empty());
    assert(recvs.empty());
    assert(sends.empty());
  }
  
  
  
  // Communication tree
  int nsiblings() { return 2; }
  // Get process id of my first child (the other children are
  // consecutive)
  int child() { return dist::rank()*nsiblings() + 1; }
  // Get process id if my parent
  int parent() { return (dist::rank()-1) / nsiblings(); }
  
  // Check whether we should tell our parent that all our (ours and
  // our childrens') messages have been sent
  void scatter_t::maybe_send_did_send()
  {
    DECLARE_CCTK_PARAMETERS;
    int need_receive = 0;
    for (int p = child(); p<child()+nsiblings(); ++p) {
      if (p < dist::size()) ++need_receive;
    }
    if (did_send_all and did_receive_sent_all == need_receive) {
      if (dist::rank() == 0) {
        // We are root; now broadcast this to all
        set_did_receive_all_sent_all();
      } else {
        if (verbose) {
          CCTK_INFO("[Telling our parent that we and our children sent all our data]");
        }
        to_parent.state = fragdesc_t::state_sent_all;
        int const p = parent();
        MPI_Request request;
        MPI_Isend(&to_parent, to_parent.num_ints(), MPI_INT, p, tag_desc,
                  dist::comm(), &request);
      }
    }
  }
  
  // Broadcast "all message have been sent" to all our children
  void scatter_t::send_all_did_send()
  {
    DECLARE_CCTK_PARAMETERS;
    if (verbose) {
      CCTK_INFO("[Telling our children that all data have been sent]");
    }
    to_children.state = fragdesc_t::state_all_sent_all;
    for (int p = child(); p<child()+nsiblings(); ++p) {
      if (p < dist::size()) {
        MPI_Request request;
        MPI_Isend(&to_children, to_children.num_ints(), MPI_INT, p, tag_desc,
                  dist::comm(), &request);
      }
    }
  }
  
  // We (this process) sent all our messages
  void scatter_t::set_did_send_all()
  {
    DECLARE_CCTK_PARAMETERS;
    if (verbose) {
      CCTK_INFO("[We sent all our data]");
    }
    assert(not did_send_all);
    did_send_all = true;
    maybe_send_did_send();
  }
  
  // One of our children (and all its children) sent all their
  // messages
  void scatter_t::set_did_receive_sent_all()
  {
    DECLARE_CCTK_PARAMETERS;
    if (verbose) {
      CCTK_INFO("[One of our children sent all their data]");
    }
    assert(did_receive_sent_all < 2);
    ++did_receive_sent_all;
    maybe_send_did_send();
  }
  
  // Our parent broadcast that all messages have been sent
  void scatter_t::set_did_receive_all_sent_all()
  {
    DECLARE_CCTK_PARAMETERS;
    if (verbose) {
      CCTK_INFO("[Everything has been sent]");
    }
    assert(not did_receive_all_sent_all);
    did_receive_all_sent_all = true;
    send_all_did_send();
  }
  
  // Dispatch upon a state change message
  void scatter_t::handle_state_transition(fragdesc_t const& fd)
  {
    switch (fd.state) {
    case fragdesc_t::state_sent_all: set_did_receive_sent_all(); break;
    case fragdesc_t::state_all_sent_all: set_did_receive_all_sent_all(); break;
    default: assert(0);
    }
  }
  
  
  
  void scatter_t::send(fragdesc_t const& fd, void const *const data)
  {
    DECLARE_CCTK_PARAMETERS;
    
    assert(data);
    
    if (verbose) {
      char *const fullname = CCTK_FullName(fd.varindex);
      CCTK_VInfo(CCTK_THORNSTRING,
                 "Sending data read from variable %s, reflevel %d, map %d, component %d, timelevel %d",
                 fullname, fd.reflevel, fd.map, fd.src_component, fd.timelevel);
      free(fullname);
    }
    
    list<transmission_t*> tosend = split_for_sending(fd, data);
    
    while (not tosend.empty()) {
      list<transmission_t*>::iterator const tmi = tosend.begin();
      transmission_t *const tm = *tmi;
      
      if (verbose) {
        CCTK_VInfo(CCTK_THORNSTRING,
                   "   Sending to process %d...", tm->fragdesc.process);
      }
      
      // Send descriptor and data
      MPI_Request req;
      MPI_Isend(&tm->fragdesc, tm->fragdesc.num_ints(), MPI_INT,
                tm->fragdesc.process, tag_desc,
                dist::comm(), &req);
      MPI_Isend(&tm->data[0], tm->fragdesc.npoints(), tm->fragdesc.datatype(),
                tm->fragdesc.process, tag_data,
                dist::comm(), &tm->request);
      
      tosend.erase(tmi);
      sends.push_back(tm);
    }
    
    // Do some work (if some is available)
    do_some_work();
    
    if (verbose) {
      CCTK_INFO("Done sending");
    }
  }
  
  
  
  void scatter_t::post_public_recvs()
  {
    DECLARE_CCTK_PARAMETERS;
    
    if (verbose) {
      CCTK_INFO("Posting public receives");
    }
    
    // Post public receives
    while ((int)public_recvs.size() < num_public_recvs) {
      transmission_t *const tm = new transmission_t;
      MPI_Irecv(&tm->fragdesc, tm->fragdesc.num_ints(), MPI_INT,
                MPI_ANY_SOURCE, tag_desc,
                dist::comm(), &tm->request);
      public_recvs.push_back(tm);
    }
  }
  
  
  
  void scatter_t::do_some_work(bool const do_wait)
  {
    DECLARE_CCTK_PARAMETERS;
    
    if (verbose) {
      CCTK_INFO("Checking for progress");
    }
    
    // Set up an array of all open requests
    vector<MPI_Request> requests;
    vector<list<transmission_t*>::iterator> iterators;
    int const npublic_recvs = public_recvs.size();
    int const nrecvs = recvs.size();
    int const nsends = sends.size();
    int const nrequests = npublic_recvs + nrecvs + nsends;
    requests.reserve(nrequests);
    iterators.reserve(nrequests);
    for (list<transmission_t*>::iterator
           tmi = public_recvs.begin(); tmi != public_recvs.end(); ++tmi)
    {
      transmission_t const *const tm = *tmi;
      requests.push_back(tm->request);
      iterators.push_back(tmi);
    }
    for (list<transmission_t*>::iterator
           tmi = recvs.begin(); tmi != recvs.end(); ++tmi)
    {
      transmission_t const *const tm = *tmi;
      requests.push_back(tm->request);
      iterators.push_back(tmi);
    }
    for (list<transmission_t*>::iterator
           tmi = sends.begin(); tmi != sends.end(); ++tmi)
    {
      transmission_t const *const tm = *tmi;
      requests.push_back(tm->request);
      iterators.push_back(tmi);
    }
    
    // Wait for (or test for) some open requests
    int outcount;
    vector<int> indices(nrequests);
    vector<MPI_Status> statuses(nrequests);
    if (do_wait) {
      if (verbose) {
        CCTK_INFO("Waiting for some progress...");
      }
      MPI_Waitsome(requests.size(), &requests[0],
                   &outcount, &indices[0], &statuses[0]);
    } else {
      if (verbose) {
        CCTK_INFO("Testing for some progress...");
      }
      MPI_Testsome(requests.size(), &requests[0],
                   &outcount, &indices[0], &statuses[0]);
    }
    if (verbose) {
      CCTK_VInfo(CCTK_THORNSTRING, "Completed %d transmissions", outcount);
    }
    
    // Process all completed requests
    for (int n=0; n<outcount; ++n) {
      int const idx = indices.at(n);
      
      if (idx < npublic_recvs) {
        
        // We received a new descriptor
        int const source = statuses.at(idx).MPI_SOURCE;
        
        if (verbose) {
          CCTK_VInfo(CCTK_THORNSTRING,
                     "Receiving data from process %d", source);
        }
        
        list<transmission_t*>::iterator const tmi = iterators.at(idx);
        transmission_t *const tm = *tmi;
        public_recvs.erase(tmi);
        
        if (tm->fragdesc.state != fragdesc_t::state_normal) {
          handle_state_transition(tm->fragdesc);
        } else {
          
          // Prepare receiving the data
          assert(tm->fragdesc.process == dist::rank());
          tm->data.resize(tm->fragdesc.npoints() * tm->fragdesc.vartypesize());
          bytes_allocated += tm->data.size();
          MPI_Irecv(&tm->data[0],
                    tm->fragdesc.npoints(), tm->fragdesc.datatype(),
                    source, tag_data,
                    dist::comm(), &tm->request);
          recvs.push_back(tm);
          if (verbose) {
            CCTK_VInfo(CCTK_THORNSTRING,
                       "   Current buffer size: %td bytes", bytes_allocated);
          }
          
          post_public_recvs();
        }
        
      } else if (idx < npublic_recvs + nrecvs) {
        
        // We completed receiving a dataset; process it
        list<transmission_t*>::iterator const tmi = iterators.at(idx);
        transmission_t *const tm = *tmi;
        
        if (verbose) {
          char *const fullname = CCTK_FullName(tm->fragdesc.varindex);
          CCTK_VInfo(CCTK_THORNSTRING,
                     "Completed receiving data for variable %s", fullname);
          free(fullname);
        }
        
        write_data(tm);
        bytes_allocated -= tm->data.size();
        delete tm;
        if (verbose) {
          CCTK_VInfo(CCTK_THORNSTRING,
                     "   Current buffer size: %td bytes", bytes_allocated);
        }
        recvs.erase(tmi);
        ++num_received;
        
      } else {
        
        // We completed sending a dataset; forget it
        list<transmission_t*>::iterator const tmi = iterators.at(idx);
        transmission_t *const tm = *tmi;
        
        if (verbose) {
          char *const fullname = CCTK_FullName(tm->fragdesc.varindex);
          CCTK_VInfo(CCTK_THORNSTRING,
                     "Completed sending data for variable %s", fullname);
          free(fullname);
        }
        
        bytes_allocated -= tm->data.size();
        delete tm;
        if (verbose) {
          CCTK_VInfo(CCTK_THORNSTRING,
                     "   Current buffer size: %td bytes", bytes_allocated);
        }
        sends.erase(tmi);
        ++num_sent;
        
      }
    }
  }
  
  
  
  list<scatter_t::transmission_t*>
  scatter_t::split_for_sending(fragdesc_t const& fd, void const *const data)
  {
    DECLARE_CCTK_PARAMETERS;
    
    int const groupindex = CCTK_GroupIndexFromVarI(fd.varindex);
    assert(groupindex>=0);
    int const varoffset = fd.varindex - CCTK_FirstVarIndexI(groupindex);
    assert(varoffset>=0 and varoffset<=fd.varindex);
    
    gh const& hh = *Carpet::arrdata.at(groupindex).at(fd.map).hh;
    dh const& dd = *Carpet::arrdata.at(groupindex).at(fd.map).dd;
    th const& tt = *Carpet::arrdata.at(groupindex).at(fd.map).tt;
    
    ibbox const& baseext =
      hh.baseextents.AT(fd.mglevel).AT(fd.reflevel);
    
    ibbox const mybox(baseext.lower() + fd.imin * baseext.stride(),
                      baseext.lower() + fd.imax * baseext.stride(),
                      baseext.stride());
    
    ibset done;
    list<transmission_t*> tosend;
    dh::light_cboxes const& light_cbox =
      dd.light_boxes.at(fd.mglevel).at(fd.reflevel);
    for (int c=0; c<hh.components(fd.reflevel); ++c) {
      dh::light_dboxes const& light_box = light_cbox.at(c);
      ibbox const& intr = light_box.interior;
      ibbox const ovlp = mybox & intr;
      assert((ovlp & done).empty());
      done += ovlp;
      
      if (not ovlp.empty()) {
        ibbox const& box = ovlp;
        transmission_t *const tm = new transmission_t;
        tm->fragdesc = fd;
        tm->fragdesc.imin = (box.lower() - baseext.lower()) / baseext.stride();
        tm->fragdesc.imax = (box.upper() - baseext.lower()) / baseext.stride();
        tm->fragdesc.component = c;
        tm->fragdesc.process = hh.processor(fd.reflevel, c);
        
        ptrdiff_t const vartypesize = tm->fragdesc.vartypesize();
        ptrdiff_t const ni = tm->fragdesc.imax[0] - tm->fragdesc.imin[0] + 1;
        ptrdiff_t const nj = tm->fragdesc.imax[1] - tm->fragdesc.imin[1] + 1;
        ptrdiff_t const nk = tm->fragdesc.imax[2] - tm->fragdesc.imin[2] + 1;
        ptrdiff_t const di = 1;
        ptrdiff_t const dj = ni;
        ptrdiff_t const dk = ni * nj;
        ptrdiff_t const np = ni * nj * nk;
        tm->data.resize(np * vartypesize);
        bytes_allocated += tm->data.size();
        if (verbose) {
          CCTK_VInfo(CCTK_THORNSTRING,
                     "   Current buffer size: %td bytes", bytes_allocated);
        }
        char *const dst = &tm->data[0];
        
        ptrdiff_t const nis = fd.imax[0] - fd.imin[0] + 1;
        ptrdiff_t const njs = fd.imax[1] - fd.imin[1] + 1;
        ptrdiff_t const nks = fd.imax[2] - fd.imin[2] + 1;
        ptrdiff_t const dis = 1;
        ptrdiff_t const djs = nis;
        ptrdiff_t const dks = nis * njs;
        ptrdiff_t const nps = nis * njs * nks;
        ptrdiff_t const i0s = tm->fragdesc.imin[0] - fd.imin[0];
        ptrdiff_t const j0s = tm->fragdesc.imin[1] - fd.imin[1];
        ptrdiff_t const k0s = tm->fragdesc.imin[2] - fd.imin[2];
        ptrdiff_t const ind0s = i0s * dis + j0s * djs + k0s * dks;
        char const *const src = &((char const*)data)[vartypesize * ind0s];
        
#pragma omp parallel for //collapse(2)
        for (ptrdiff_t k=0; k<nk; ++k) {
          for (ptrdiff_t j=0; j<nj; ++j) {
            ptrdiff_t const ind = j*dj + k*dk;
            ptrdiff_t const inds = j*djs + k*dks;
            memcpy(&dst[ind], &src[inds], ni*vartypesize);
          }
        }
        
        tosend.push_back(tm);
      }
    }
    // Don't enforce this -- mesh refinement boundaries have ghosts
    // that do not overlap with any interior
    // assert(done == mybox);
    
    return tosend;
  }
  
  
  
  void scatter_t::write_data(transmission_t *const tm)
  {
    fragdesc_t const& fd = tm->fragdesc;
    int const groupindex = CCTK_GroupIndexFromVarI(fd.varindex);
    assert(groupindex>=0);
    int const varoffset = fd.varindex - CCTK_FirstVarIndexI(groupindex);
    assert(varoffset>=0 and varoffset<=fd.varindex);
    
    gh const& hh = *Carpet::arrdata.at(groupindex).at(fd.map).hh;
    dh const& dd = *Carpet::arrdata.at(groupindex).at(fd.map).dd;
    th const& tt = *Carpet::arrdata.at(groupindex).at(fd.map).tt;
    ggf const& ff =
      *Carpet::arrdata.at(groupindex).at(fd.map).data.at(varoffset);
    int const lc = hh.get_local_component(fd.reflevel, fd.component);
    gdata const& data =
      *ff.data_pointer(fd.timelevel, fd.reflevel, lc, fd.mglevel);
    
    ibbox const& baseext =
      hh.baseextents.AT(fd.mglevel).AT(fd.reflevel);
    
    ibbox const mybox(baseext.lower() + fd.imin * baseext.stride(),
                      baseext.lower() + fd.imax * baseext.stride(),
                      baseext.stride());
    
    dh::light_dboxes const& light_box =
      dd.light_boxes.at(fd.mglevel).at(fd.reflevel).at(fd.component);
    ibbox const& intr = light_box.interior;
    assert(mybox.is_contained_in(intr));
    ibbox const& extr = light_box.exterior;
    
    ptrdiff_t const vartypesize = fd.vartypesize();
    ptrdiff_t const ni = fd.imax[0] - fd.imin[0] + 1;
    ptrdiff_t const nj = fd.imax[1] - fd.imin[1] + 1;
    ptrdiff_t const nk = fd.imax[2] - fd.imin[2] + 1;
    ptrdiff_t const di = 1;
    ptrdiff_t const dj = ni;
    ptrdiff_t const dk = ni * nj;
    ptrdiff_t const np = ni * nj * nk;
    char const *const src = (char const*)&tm->data[0];
    
    ivect const lbnd = (extr.lower() - baseext.lower()) / baseext.stride();
    ivect const lsh  = extr.shape() / baseext.stride();
    ptrdiff_t const nid = lsh[0];
    ptrdiff_t const njd = lsh[1];
    ptrdiff_t const nkd = lsh[2];
    ptrdiff_t const did = 1;
    ptrdiff_t const djd = nid;
    ptrdiff_t const dkd = nid * njd;
    ptrdiff_t const npd = nid * njd * nkd;
    ptrdiff_t const i0d = fd.imin[0] - lbnd[0];
    ptrdiff_t const j0d = fd.imin[1] - lbnd[1];
    ptrdiff_t const k0d = fd.imin[2] - lbnd[2];
    ptrdiff_t const ind0d = i0d * did + j0d * djd + k0d * dkd;
    assert(data.has_storage());
    char *const dst = &((char*)data.storage())[ind0d];
    
#pragma omp parallel for //collapse(2)
    for (ptrdiff_t k=0; k<nk; ++k) {
      for (ptrdiff_t j=0; j<nj; ++j) {
        ptrdiff_t const indd = j*djd + k*dkd;
        ptrdiff_t const ind = j*dj + k*dk;
        memcpy(&dst[indd], &src[ind], ni*vartypesize);
      }
    }
  }
  
} // end namespace CarpetIOF5