-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy pathAMReX_FabArray.H
More file actions
4013 lines (3562 loc) · 139 KB
/
AMReX_FabArray.H
File metadata and controls
4013 lines (3562 loc) · 139 KB
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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef BL_FABARRAY_H
#define BL_FABARRAY_H
#include <AMReX_Config.H>
#include <AMReX_BLassert.H>
#include <AMReX_Array.H>
#include <AMReX_Vector.H>
#include <AMReX_Box.H>
#include <AMReX.H>
#include <AMReX_BoxArray.H>
#include <AMReX_BoxDomain.H>
#include <AMReX_FabFactory.H>
#include <AMReX_DistributionMapping.H>
#include <AMReX_Geometry.H>
#include <AMReX_GpuComplex.H>
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_Utility.H>
#include <AMReX_ccse-mpi.H>
#include <AMReX_BLProfiler.H>
#include <AMReX_Periodicity.H>
#include <AMReX_Print.H>
#include <AMReX_FabArrayBase.H>
#include <AMReX_MFIter.H>
#include <AMReX_MakeType.H>
#include <AMReX_TypeTraits.H>
#include <AMReX_LayoutData.H>
#include <AMReX_BaseFab.H>
#include <AMReX_BaseFabUtility.H>
#include <AMReX_MFParallelFor.H>
#include <AMReX_TagParallelFor.H>
#include <AMReX_ParReduce.H>
#include <AMReX_Gpu.H>
#ifdef AMREX_USE_EB
#include <AMReX_EBFabFactory.H>
#endif
#ifdef AMREX_USE_OMP
#include <omp.h>
#endif
#include <algorithm>
#include <cstring>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <utility>
#include <set>
#include <string>
#include <vector>
namespace amrex {
template <typename T, std::enable_if_t<!IsBaseFab<T>::value,int> = 0>
Long nBytesOwned (T const&) noexcept { return 0; }
template <typename T>
Long nBytesOwned (BaseFab<T> const& fab) noexcept { return fab.nBytesOwned(); }
/**
* \brief FabArray memory allocation information
*/
struct MFInfo {
// alloc: allocate memory or not
bool alloc = true;
bool alloc_single_chunk = FabArrayBase::getAllocSingleChunk();
Arena* arena = nullptr;
Vector<std::string> tags;
MFInfo& SetAlloc (bool a) noexcept { alloc = a; return *this; }
MFInfo& SetAllocSingleChunk (bool a) noexcept { alloc_single_chunk = a; return *this; }
MFInfo& SetArena (Arena* ar) noexcept { arena = ar; return *this; }
MFInfo& SetTag () noexcept { return *this; }
MFInfo& SetTag (const char* t) noexcept {
tags.emplace_back(t);
return *this;
}
MFInfo& SetTag (const std::string& t) noexcept {
tags.emplace_back(t);
return *this;
}
template <typename T, typename... Ts>
MFInfo& SetTag (T&& t, Ts&&... ts) noexcept {
tags.emplace_back(std::forward<T>(t));
return SetTag(std::forward<Ts>(ts)...);
}
};
struct TheFaArenaDeleter {
using pointer = char*;
void operator()(pointer p) const noexcept {
The_Comms_Arena()->free(p);
}
};
using TheFaArenaPointer = std::unique_ptr<char, TheFaArenaDeleter>;
// Data used in non-blocking fill boundary.
template <class FAB>
struct FBData {
const FabArrayBase::FB* fb = nullptr;
int scomp;
int ncomp;
//
char* the_recv_data = nullptr;
char* the_send_data = nullptr;
Vector<int> recv_from;
Vector<char*> recv_data;
Vector<std::size_t> recv_size;
Vector<MPI_Request> recv_reqs;
Vector<MPI_Status> recv_stat;
//
Vector<char*> send_data;
Vector<MPI_Request> send_reqs;
int tag;
//
bool deterministic = false;
};
// Data used in non-blocking parallel copy.
template <class FAB>
struct PCData {
const FabArrayBase::CPC* cpc = nullptr;
const FabArray<FAB>* src = nullptr;
FabArrayBase::CpOp op;
int tag = -1;
int actual_n_rcvs = -1;
int SC = -1, NC = -1, DC = -1;
char* the_recv_data = nullptr;
char* the_send_data = nullptr;
Vector<int> recv_from;
Vector<char*> recv_data;
Vector<std::size_t> recv_size;
Vector<MPI_Request> recv_reqs;
Vector<MPI_Request> send_reqs;
bool deterministic = false;
};
template <typename T>
struct MultiArray4
{
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
Array4<T> const& operator[] (int li) const noexcept {
AMREX_IF_ON_DEVICE((return dp[li];))
AMREX_IF_ON_HOST((return hp[li];))
}
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
explicit operator bool() const noexcept {
AMREX_IF_ON_DEVICE((return dp != nullptr;))
AMREX_IF_ON_HOST((return hp != nullptr;))
}
#ifdef AMREX_USE_GPU
Array4<T> const* AMREX_RESTRICT dp = nullptr;
#endif
Array4<T> const* AMREX_RESTRICT hp = nullptr;
};
template <class FAB> class FabArray;
template <class DFAB, class SFAB,
std::enable_if_t<std::conjunction_v<
IsBaseFab<DFAB>, IsBaseFab<SFAB>,
std::is_convertible<typename SFAB::value_type,
typename DFAB::value_type>>, int> BAR = 0>
void
Copy (FabArray<DFAB>& dst, FabArray<SFAB> const& src, int srccomp, int dstcomp, int numcomp, int nghost)
{
Copy(dst,src,srccomp,dstcomp,numcomp,IntVect(nghost));
}
template <class DFAB, class SFAB,
std::enable_if_t<std::conjunction_v<
IsBaseFab<DFAB>, IsBaseFab<SFAB>,
std::is_convertible<typename SFAB::value_type,
typename DFAB::value_type>>, int> BAR = 0>
void
Copy (FabArray<DFAB>& dst, FabArray<SFAB> const& src, int srccomp, int dstcomp, int numcomp, const IntVect& nghost)
{
BL_PROFILE("amrex::Copy()");
using DT = typename DFAB::value_type;
if (dst.local_size() == 0) { return; }
// avoid self copy
if constexpr (std::is_same_v<typename SFAB::value_type, typename DFAB::value_type>) {
if (dst.atLocalIdx(0).dataPtr(dstcomp) == src.atLocalIdx(0).dataPtr(srccomp)) {
return;
}
}
#ifdef AMREX_USE_GPU
if (Gpu::inLaunchRegion() && dst.isFusingCandidate()) {
auto const& srcarr = src.const_arrays();
auto const& dstarr = dst.arrays();
ParallelFor(dst, nghost, numcomp,
[=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
{
dstarr[box_no](i,j,k,dstcomp+n) = DT(srcarr[box_no](i,j,k,srccomp+n));
});
if (!Gpu::inNoSyncRegion()) {
Gpu::streamSynchronize();
}
} else
#endif
{
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(dst,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const Box& bx = mfi.growntilebox(nghost);
if (bx.ok())
{
auto const& srcFab = src.const_array(mfi);
auto const& dstFab = dst.array(mfi);
AMREX_HOST_DEVICE_PARALLEL_FOR_4D( bx, numcomp, i, j, k, n,
{
dstFab(i,j,k,dstcomp+n) = DT(srcFab(i,j,k,srccomp+n));
});
}
}
}
}
template <class FAB,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
void
Add (FabArray<FAB>& dst, FabArray<FAB> const& src, int srccomp, int dstcomp, int numcomp, int nghost)
{
Add(dst,src,srccomp,dstcomp,numcomp,IntVect(nghost));
}
template <class FAB,
class bar = std::enable_if_t<IsBaseFab<FAB>::value> >
void
Add (FabArray<FAB>& dst, FabArray<FAB> const& src, int srccomp, int dstcomp, int numcomp, const IntVect& nghost)
{
BL_PROFILE("amrex::Add()");
#ifdef AMREX_USE_GPU
if (Gpu::inLaunchRegion() && dst.isFusingCandidate()) {
auto const& dstfa = dst.arrays();
auto const& srcfa = src.const_arrays();
ParallelFor(dst, nghost, numcomp,
[=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
{
dstfa[box_no](i,j,k,n+dstcomp) += srcfa[box_no](i,j,k,n+srccomp);
});
if (!Gpu::inNoSyncRegion()) {
Gpu::streamSynchronize();
}
} else
#endif
{
#ifdef AMREX_USE_OMP
#pragma omp parallel if (Gpu::notInLaunchRegion())
#endif
for (MFIter mfi(dst,TilingIfNotGPU()); mfi.isValid(); ++mfi)
{
const Box& bx = mfi.growntilebox(nghost);
if (bx.ok())
{
auto const srcFab = src.array(mfi);
auto dstFab = dst.array(mfi);
AMREX_HOST_DEVICE_PARALLEL_FOR_4D( bx, numcomp, i, j, k, n,
{
dstFab(i,j,k,n+dstcomp) += srcFab(i,j,k,n+srccomp);
});
}
}
}
}
/**
* \class amrex::FabArray
* \ingroup amrex_multifab_containers
* \brief An Array of FortranArrayBox(FAB)-like Objects
*
* The FabArray<FAB> class implements a collection (stored as an array) of
* Fortran array box-like ( \p FAB ) objects. The parameterized type \p FAB is intended to be
* any class derived from BaseFab<T>. For example, \p FAB may be a BaseFab of
* integers, so we could write:
*
* FabArray<BaseFab<int> > int_fabs;
*
* Then int_fabs is a FabArray that can hold a collection of BaseFab<int>
* objects.
*
* FabArray is not just a general container class for Fortran arrays. It is
* intended to hold "grid" data for use in finite difference calculations in
* which the data is defined on a union of (usually disjoint) rectangular
* regions embedded in a uniform index space. This region, called the valid
* region, is represented by a BoxArray. For the purposes of this discussion,
* the Kth Box in the BoxArray represents the interior region of the Kth grid.
*
* Since the intent is to be used with finite difference calculations a
* FabArray also includes the notion of a boundary region for each grid. The
* boundary region is specified by the ngrow parameter which tells the FabArray
* to allocate each \p FAB to be ngrow cells larger in all directions than the
* underlying Box. The larger region covered by the union of all the \p FABs is
* called the region of definition. The underlying notion is that the valid
* region contains the grid interior data and the region of definition includes
* the interior region plus the boundary areas.
*
* Operations are available to copy data from the valid regions into these
* boundary areas where the two overlap. The number of components, that is,
* the number of values that can be stored in each cell of a \p FAB, is either
* given as an argument to the constructor or is inherent in the definition of
* the underlying \p FAB. Each \p FAB in the FabArray will have the same number of
* components.
*
* In summary, a FabArray is an array of \p FABs. The Kth element contains a \p FAB
* that holds the data for the Kth grid, a Box that defines the valid region
* of the Kth grid.
*
* A typical use for a FabArray would be to hold the solution vector or
* right-hand-side when solving a linear system of equations on a union of
* rectangular grids. The copy operations would be used to copy data from the
* valid regions of neighboring grids into the boundary regions after each
* relaxation step of the iterative method. If a multigrid method is used, a
* FabArray could be used to hold the data at each level in the multigrid
* hierarchy.
*
* This class is a concrete class not a polymorphic one.
*
* This class does NOT provide a copy constructor or assignment operator.
*
* \tparam FAB FortranArrayBox-like object. Typically a derived class of BaseFab. Not to be confused with FabArrayBase.
*/
template <class FAB>
class FabArray
:
public FabArrayBase
{
public:
struct FABType {
using value_type = FAB;
};
/*
* if FAB is a BaseFab or its child, value_type = FAB::value_type
* else value_type = FAB;
*/
using value_type = typename std::conditional_t<IsBaseFab<FAB>::value, FAB, FABType>::value_type;
using fab_type = FAB;
//
//! Constructs an empty FabArray<FAB>.
FabArray () noexcept;
/**
* \brief Construct an empty FabArray<FAB> that has a default Arena.
*
* If `define` is called later with a nullptr as MFInfo's arena, the
* default Arena `a` will be used. If the arena in MFInfo is not a
* nullptr, the MFInfo's arena will be used.
*/
explicit FabArray (Arena* a) noexcept;
/**
* \brief Construct a FabArray<FAB> with a valid region defined by bxs
* and a region of definition defined by the grow factor ngrow
* and the number of components nvar.
*/
FabArray (const BoxArray& bxs,
const DistributionMapping& dm,
int nvar,
int ngrow,
#ifdef AMREX_STRICT_MODE
const MFInfo& info,
const FabFactory<FAB>& factory);
#else
const MFInfo& info = MFInfo(),
const FabFactory<FAB>& factory = DefaultFabFactory<FAB>());
#endif
FabArray (const BoxArray& bxs,
const DistributionMapping& dm,
int nvar,
const IntVect& ngrow,
#ifdef AMREX_STRICT_MODE
const MFInfo& info,
const FabFactory<FAB>& factory);
#else
const MFInfo& info = MFInfo(),
const FabFactory<FAB>& factory = DefaultFabFactory<FAB>());
#endif
FabArray (const FabArray<FAB>& rhs, MakeType maketype, int scomp, int ncomp);
//! The destructor -- deletes all FABs in the array.
~FabArray ();
FabArray (FabArray<FAB>&& rhs) noexcept;
FabArray<FAB>& operator= (FabArray<FAB>&& rhs) noexcept;
FabArray (const FabArray<FAB>& rhs) = delete;
FabArray<FAB>& operator= (const FabArray<FAB>& rhs) = delete;
/**
* \brief Define this FabArray identically to that performed by
* the constructor having an analogous function signature.
* This is only valid if this FabArray was defined using
* the default constructor.
*/
void define (const BoxArray& bxs,
const DistributionMapping& dm,
int nvar,
int ngrow,
#ifdef AMREX_STRICT_MODE
const MFInfo& info,
const FabFactory<FAB>& factory);
#else
const MFInfo& info = MFInfo(),
const FabFactory<FAB>& factory = DefaultFabFactory<FAB>());
#endif
void define (const BoxArray& bxs,
const DistributionMapping& dm,
int nvar,
const IntVect& ngrow,
#ifdef AMREX_STRICT_MODE
const MFInfo& info,
const FabFactory<FAB>& factory);
#else
const MFInfo& info = MFInfo(),
const FabFactory<FAB>& factory = DefaultFabFactory<FAB>());
#endif
const FabFactory<FAB>& Factory () const noexcept { return *m_factory; }
// Provides access to the Arena this FabArray was build with.
Arena* arena () const noexcept { return m_dallocator.arena(); }
const Vector<std::string>& tags () const noexcept { return m_tags; }
bool hasEBFabFactory () const noexcept {
#ifdef AMREX_USE_EB
const auto *const f = dynamic_cast<EBFArrayBoxFactory const*>(m_factory.get());
return (f != nullptr);
#else
return false;
#endif
}
//! Return the data pointer to the single chunk memory if this object
//! uses a single contiguous chunk of memory, nullptr otherwise.
[[nodiscard]] value_type* singleChunkPtr () noexcept {
return m_single_chunk_arena ? (value_type*)m_single_chunk_arena->data() : nullptr;
}
//! Return the data pointer to the single chunk memory if this object
//! uses a single contiguous chunk of memory, nullptr otherwise.
[[nodiscard]] value_type const* singleChunkPtr () const noexcept {
return m_single_chunk_arena ? (value_type const*)m_single_chunk_arena->data() : nullptr;
}
//! Return the size of the single chunk memory if this object uses a
//! single contiguous chunk of memory, 0 otherwise.
[[nodiscard]] std::size_t singleChunkSize () const noexcept { return m_single_chunk_size; }
bool isAllRegular () const noexcept {
#ifdef AMREX_USE_EB
const auto *const f = dynamic_cast<EBFArrayBoxFactory const*>(m_factory.get());
if (f) {
return f->isAllRegular();
} else {
return true;
}
#else
return true;
#endif
}
/**
* \brief Return true if the FabArray is well-defined. That is,
* the FabArray has a BoxArray and DistributionMapping, the
* FABs are allocated for each Box in the BoxArray and the
* sizes of the FABs and the number of components are consistent
* with the definition of the FabArray.
* \warning This routine performs an MPI collective, so every rank in the
* current active MPI communicator must participate.
*/
bool ok () const;
/** Has define() been called on this rank?
*
* \return true if `define` has been called on this `FabArray`. Note that all constructors except `FabArray ()`
* and `FabArray(Arena*a)` call `define`, even if the `MFInfo` argument has `alloc=false`. One could
* also use `FabArrayBase::empty()` to find whether `define` is called or not, although they are not exactly
* the same.
*/
bool isDefined () const;
//! Return a constant reference to the FAB associated with mfi.
const FAB& operator[] (const MFIter& mfi) const noexcept { return *(this->fabPtr(mfi)); }
//! Return a constant reference to the FAB associated with mfi.
const FAB& get (const MFIter& mfi) const noexcept { return *(this->fabPtr(mfi)); }
//! Returns a reference to the FAB associated mfi.
FAB& operator[] (const MFIter& mfi) noexcept { return *(this->fabPtr(mfi)); }
//! Returns a reference to the FAB associated mfi.
FAB& get (const MFIter& mfi) noexcept { return *(this->fabPtr(mfi)); }
//! Return a constant reference to the FAB associated with the Kth element.
const FAB& operator[] (int K) const noexcept { return *(this->fabPtr(K)); }
//! Return a constant reference to the FAB associated with the Kth element.
const FAB& get (int K) const noexcept { return *(this->fabPtr(K)); }
//! Return a reference to the FAB associated with the Kth element.
FAB& operator[] (int K) noexcept { return *(this->fabPtr(K)); }
//! Return a reference to the FAB associated with the Kth element.
FAB& get (int K) noexcept { return *(this->fabPtr(K)); }
//! Return a reference to the FAB associated with local index L
FAB& atLocalIdx (int L) noexcept { return *m_fabs_v[L]; }
const FAB& atLocalIdx (int L) const noexcept { return *m_fabs_v[L]; }
//! Return pointer to FAB
FAB * fabPtr (const MFIter& mfi) noexcept;
FAB const* fabPtr (const MFIter& mfi) const noexcept;
FAB * fabPtr (int K) noexcept; // Here K is global index
FAB const* fabPtr (int K) const noexcept;
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void prefetchToHost (const MFIter& mfi) const noexcept
{
#ifdef AMREX_USE_CUDA
this->fabPtr(mfi)->prefetchToHost();
#else
amrex::ignore_unused(mfi);
#endif
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void prefetchToDevice (const MFIter& mfi) const noexcept
{
#ifdef AMREX_USE_CUDA
this->fabPtr(mfi)->prefetchToDevice();
#else
amrex::ignore_unused(mfi);
#endif
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> array (const MFIter& mfi) const noexcept
{
return fabPtr(mfi)->const_array();
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type> array (const MFIter& mfi) noexcept
{
return fabPtr(mfi)->array();
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> array (int K) const noexcept
{
return fabPtr(K)->const_array();
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type> array (int K) noexcept
{
return fabPtr(K)->array();
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> const_array (const MFIter& mfi) const noexcept
{
return fabPtr(mfi)->const_array();
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> const_array (int K) const noexcept
{
return fabPtr(K)->const_array();
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> array (const MFIter& mfi, int start_comp) const noexcept
{
return fabPtr(mfi)->const_array(start_comp);
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type> array (const MFIter& mfi, int start_comp) noexcept
{
return fabPtr(mfi)->array(start_comp);
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> array (int K, int start_comp) const noexcept
{
return fabPtr(K)->const_array(start_comp);
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type> array (int K, int start_comp) noexcept
{
return fabPtr(K)->array(start_comp);
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> const_array (const MFIter& mfi, int start_comp) const noexcept
{
return fabPtr(mfi)->const_array(start_comp);
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Array4<typename FabArray<FAB>::value_type const> const_array (int K, int start_comp) const noexcept
{
return fabPtr(K)->const_array(start_comp);
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
MultiArray4<typename FabArray<FAB>::value_type> arrays () noexcept
{
build_arrays();
return m_arrays;
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
MultiArray4<typename FabArray<FAB>::value_type const> arrays () const noexcept
{
build_arrays();
return m_const_arrays;
}
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
MultiArray4<typename FabArray<FAB>::value_type const> const_arrays () const noexcept
{
build_arrays();
return m_const_arrays;
}
//! Explicitly set the Kth FAB in the FabArray to point to elem.
void setFab (int boxno, std::unique_ptr<FAB> elem);
//! Explicitly set the Kth FAB in the FabArray to point to elem.
template <class F=FAB, std::enable_if_t<std::is_move_constructible_v<F>,int> = 0>
void setFab (int boxno, FAB&& elem);
//! Explicitly set the FAB associated with mfi in the FabArray to point to elem.
void setFab (const MFIter&mfi, std::unique_ptr<FAB> elem);
//! Explicitly set the FAB associated with mfi in the FabArray to point to elem.
template <class F=FAB, std::enable_if_t<std::is_move_constructible_v<F>,int> = 0>
void setFab (const MFIter&mfi, FAB&& elem);
//! Release ownership of the FAB. This function is not thread safe.
AMREX_NODISCARD
FAB* release (int K);
//! Release ownership of the FAB. This function is not thread safe.
AMREX_NODISCARD
FAB* release (const MFIter& mfi);
//! Releases FAB memory in the FabArray.
void clear ();
/**
* \brief Perform local copy of FabArray data.
*
* The two FabArrays must have the same BoxArray and
* DistributionMapping, although they could have different data types.
* For example, this could be used to copy from FabArray<BaseFab<float>>
* to FabArray<BaseFab<double>>.
*
* \param src source FabArray
* \param scomp starting component of source
* \param dcomp starting component of this FabArray
* \param ncomp number of components
* \param nghost number of ghost cells
*/
template <typename SFAB, typename DFAB = FAB,
std::enable_if_t<std::conjunction_v<
IsBaseFab<DFAB>, IsBaseFab<SFAB>,
std::is_convertible<typename SFAB::value_type,
typename DFAB::value_type>>, int> = 0>
void LocalCopy (FabArray<SFAB> const& src, int scomp, int dcomp, int ncomp,
IntVect const& nghost);
/**
* \brief Perform local addition of FabArray data.
*
* The two FabArrays must have the same BoxArray and
* DistributionMapping.
*
* \param src source FabArray
* \param scomp starting component of source
* \param dcomp starting component of this FabArray
* \param ncomp number of components
* \param nghost number of ghost cells
*/
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void LocalAdd (FabArray<FAB> const& src, int scomp, int dcomp, int ncomp,
IntVect const& nghost);
//! Set all components in the entire region of each FAB to val.
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val);
//! Set all components in the entire region of each FAB to val.
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
FabArray<FAB>& operator= (value_type val);
/**
* \brief Set the value of num_comp components in the valid region of
* each FAB in the FabArray, starting at component comp to val.
* Also set the value of nghost boundary cells.
*/
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val,
int comp,
int ncomp,
int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val,
int comp,
int ncomp,
const IntVect& nghost);
/**
* \brief Set the value of num_comp components in the valid region of
* each FAB in the FabArray, starting at component comp, as well
* as nghost boundary cells, to val, provided they also intersect
* with the Box region.
*/
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val,
const Box& region,
int comp,
int ncomp,
int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val,
const Box& region,
int comp,
int ncomp,
const IntVect& nghost);
/**
* \brief Set all components in the valid region of each FAB in the
* FabArray to val, including nghost boundary cells.
*/
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val, int nghost);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val, const IntVect& nghost);
/**
* \brief Set all components in the valid region of each FAB in the
* FabArray to val, including nghost boundary cells, that also
* intersect the Box region.
*/
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val, const Box& region, int nghost);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setVal (value_type val, const Box& region, const IntVect& nghost);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void abs (int comp, int ncomp, int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void abs (int comp, int ncomp, const IntVect& nghost);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void plus (value_type val, int comp, int num_comp, int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void plus (value_type val, const Box& region, int comp, int num_comp, int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void mult (value_type val, int comp, int num_comp, int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void mult (value_type val, const Box& region, int comp, int num_comp, int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void invert (value_type numerator, int comp, int num_comp, int nghost = 0);
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void invert (value_type numerator, const Box& region, int comp, int num_comp, int nghost = 0);
//! Set all values in the boundary region to val.
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setBndry (value_type val);
//! Set ncomp values in the boundary region, starting at start_comp to val.
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setBndry (value_type val, int strt_comp, int ncomp);
//! Set all values outside the Geometry domain to val.
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setDomainBndry (value_type val, const Geometry& geom);
//! Set ncomp values outside the Geometry domain to val, starting at start_comp.
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setDomainBndry (value_type val, int strt_comp, int ncomp, const Geometry& geom);
//! Get capacity of the FabArray
template <typename I, class F=FAB, std::enable_if_t<IsBaseFab<F>::value && std::is_integral_v<I> && (sizeof(I) >= sizeof(Long)), int> = 0>
void capacityOfFabs (LayoutData<I>& mem) const;
/**
* \brief Returns the sum of component "comp"
*
* \param comp component
* \param nghost number of ghost cells
* \param local If true, MPI communication is skipped.
* \warning Unless \p local is true, this routine performs an MPI collective
* and every rank in the current active MPI communicator must participate.
*/
template <typename F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
typename F::value_type
sum (int comp, IntVect const& nghost, bool local = false) const;
/**
* \brief This function copies data from src to this FabArray. Each FAB
* in fa is intersected with all FABs in this FabArray and a copy
* is performed on the region of intersection. The intersection
* is restricted to the valid regions.
*/
void ParallelAdd (const FabArray<FAB>& src,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy(src,period,FabArray::ADD); }
void ParallelCopy (const FabArray<FAB>& src,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy(src,0,0,nComp(),0,0,period,op); }
[[deprecated("Use FabArray::ParallelCopy() instead.")]]
void copy (const FabArray<FAB>& src,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy(src,period,op); }
void ParallelAdd_nowait (const FabArray<FAB>& src,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy_nowait(src,period,FabArray::ADD); }
void ParallelCopy_nowait (const FabArray<FAB>& src,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy_nowait(src,0,0,nComp(),0,0,period,op); }
/**
* \brief This function copies data from src to this FabArray. Each FAB
* in src is intersected with all FABs in this FabArray and a copy
* is performed on the region of intersection. The intersection
* is restricted to the num_comp components starting at src_comp
* in the FabArray src, with the destination components in this
* FabArray starting at dest_comp.
*/
void ParallelAdd (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy(src,src_comp,dest_comp,num_comp, period, FabArrayBase::ADD); }
void ParallelCopy (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy(src,src_comp,dest_comp,num_comp,0,0,period,op); }
[[deprecated("Use FabArray::ParallelCopy() instead.")]]
void copy (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy(src,src_comp,dest_comp,num_comp, period, op); }
void ParallelAdd_nowait (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy_nowait(src,src_comp,dest_comp,num_comp, period, FabArrayBase::ADD); }
void ParallelCopy_nowait (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy_nowait(src,src_comp,dest_comp,num_comp,0,0,period,op); }
//! Similar to the above function, except that source and destination are grown by src_nghost and dst_nghost, respectively
void ParallelAdd (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
int src_nghost,
int dst_nghost,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy(src,src_comp,dest_comp,num_comp,IntVect(src_nghost),IntVect(dst_nghost),period,
FabArrayBase::ADD); }
void ParallelAdd (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const IntVect& src_nghost,
const IntVect& dst_nghost,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy(src,src_comp,dest_comp,num_comp,src_nghost,dst_nghost,period,FabArrayBase::ADD); }
void ParallelCopy (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
int src_nghost,
int dst_nghost,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy(src,src_comp,dest_comp,num_comp,IntVect(src_nghost),IntVect(dst_nghost),period,op); }
void ParallelCopy (const FabArray<FAB>& src,
int scomp,
int dcomp,
int ncomp,
const IntVect& snghost,
const IntVect& dnghost,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY,
const FabArrayBase::CPC* a_cpc = nullptr,
bool deterministic = false);
void ParallelAdd_nowait (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
int src_nghost,
int dst_nghost,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy_nowait(src,src_comp,dest_comp,num_comp,IntVect(src_nghost),
IntVect(dst_nghost),period,FabArrayBase::ADD); }
void ParallelAdd_nowait (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
const IntVect& src_nghost,
const IntVect& dst_nghost,
const Periodicity& period = Periodicity::NonPeriodic())
{ ParallelCopy_nowait(src,src_comp,dest_comp,num_comp,src_nghost,
dst_nghost,period,FabArrayBase::ADD); }
void ParallelCopy_nowait (const FabArray<FAB>& src,
int src_comp,
int dest_comp,
int num_comp,
int src_nghost,
int dst_nghost,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY)
{ ParallelCopy_nowait(src,src_comp,dest_comp,num_comp,IntVect(src_nghost),
IntVect(dst_nghost),period,op); }
void ParallelCopy_nowait (const FabArray<FAB>& src,
int scomp,
int dcomp,
int ncomp,
const IntVect& snghost,
const IntVect& dnghost,
const Periodicity& period = Periodicity::NonPeriodic(),
CpOp op = FabArrayBase::COPY,
const FabArrayBase::CPC* a_cpc = nullptr,
bool to_ghost_cells_only = false,
bool deterministic = false);
void ParallelCopy_nowait (const FabArray<FAB>& src,