1#ifndef AMREX_ALG_VECTOR_H_
2#define AMREX_ALG_VECTOR_H_
3#include <AMReX_Config.H>
17template <
typename T,
typename Allocator = DefaultAllocator<T> >
38 void define (Long global_size);
80 void scale (T scale_factor);
83 [[nodiscard]] T
sum (
bool local =
false)
const;
85 [[nodiscard]] T
norminf (
bool local =
false)
const;
86 [[nodiscard]] T
norm2 (
bool local =
false)
const;
88 template <
typename FAB,
89 std::enable_if_t<amrex::IsBaseFab<FAB>::value &&
90 std::is_same_v<T,typename FAB::value_type>,
int> = 0>
93 template <
typename FAB,
94 std::enable_if_t<amrex::IsBaseFab<FAB>::value &&
95 std::is_same_v<T,typename FAB::value_type>,
int> = 0>
107template <
typename T,
typename Allocator>
109 : m_partition(global_size),
110 m_begin(m_partition[ParallelDescriptor::MyProc()]),
111 m_end(m_partition[ParallelDescriptor::MyProc()+1]),
112 m_data(m_end-m_begin)
114 static_assert(std::is_floating_point<T>::value,
"AlgVector is for floating point type only");
117template <
typename T,
typename Allocator>
119 : m_partition(std::move(partition)),
120 m_begin(m_partition[ParallelDescriptor::MyProc()]),
121 m_end(m_partition[ParallelDescriptor::MyProc()+1]),
122 m_data(m_end-m_begin)
124 static_assert(std::is_floating_point<T>::value,
"AlgVector is for floating point type only");
127template <
typename T,
typename Allocator>
130 m_partition.define(global_size);
133 m_data.resize(m_end-m_begin);
136template <
typename T,
typename Allocator>
139 m_partition = std::move(partition);
142 m_data.resize(m_end-m_begin);
145template <
typename T,
typename Allocator>
152template <
typename T,
typename Allocator>
155 Long n = m_data.size();
156 T* p = m_data.data();
160template <
typename T,
typename Allocator>
167template <
typename T,
typename Allocator>
170 Long n = m_data.size();
172 T* dst = m_data.data();
173 T
const* src = rhs.
data();
177 std::memcpy(dst, src, n*
sizeof(T));
181template <
typename T,
typename Allocator>
188template <
typename T,
typename Allocator>
191 Long n = m_data.size();
193 T* dst = m_data.data();
194 T
const* src = rhs.
data();
198template <
typename T,
typename Allocator>
201 scaleAsync(scale_factor);
205template <
typename T,
typename Allocator>
208 Long n = m_data.size();
209 T* p = m_data.data();
213template <
typename T,
typename Allocator>
216 Long n = m_data.size();
217 T
const* p = m_data.data();
228template <
typename T,
typename Allocator>
231 Long n = m_data.size();
232 T
const* p = m_data.data();
235 return amrex::Math::abs(p[i]);
243template <
typename T,
typename Allocator>
246 Long n = m_data.size();
247 T
const* p = m_data.data();
258template <
typename T,
typename Allocator>
259template <typename FAB, std::enable_if_t<amrex::IsBaseFab<FAB>::value &&
260 std::is_same_v<T,typename FAB::value_type>,
int> >
266 T* p = m_data.data();
269 p += mfi.validbox().numPts();
272#if defined(AMREX_USE_OMP) && !defined(AMREX_USE_GPU)
276 fa[mfi].template copyToMem<RunOn::Device>(mfi.validbox(), 0, 1, dptrs[mfi]);
280template <
typename T,
typename Allocator>
281template <typename FAB, std::enable_if_t<amrex::IsBaseFab<FAB>::value &&
282 std::is_same_v<T,typename FAB::value_type>,
int> >
288 T
const* p = m_data.data();
291 p += mfi.validbox().numPts();
294#if defined(AMREX_USE_OMP) && !defined(AMREX_USE_GPU)
298 fa[mfi].template copyFromMem<RunOn::Device>(mfi.validbox(), 0, 1, dptrs[mfi]);
302template <
typename T,
typename Allocator>
306 ofs << m_begin <<
" " << m_end <<
"\n";
311 T
const* p = hv.
data();
315 for (Long i = 0, N = m_data.size(); i < N; ++i) {
316 ofs << i+m_begin <<
" " << p[i] <<
"\n";
320template <
class V,
class Enable =
void>
struct IsAlgVector : std::false_type {};
323struct IsAlgVector<V, std::enable_if_t<std::is_same_v<AlgVector<typename V::value_type,
324 typename V::allocator_type>,
328template <
typename V1,
typename F>
329std::enable_if_t<IsAlgVector<std::decay_t<V1> >::value>
332 Long n =
x.numLocalRows();
340template <
typename V1,
typename V2,
typename F>
341std::enable_if_t<IsAlgVector<std::decay_t<V1> >::value &&
342 IsAlgVector<std::decay_t<V2> >::value>
346 Long n =
x.numLocalRows();
355template <
typename V1,
typename V2,
typename V3,
typename F>
356std::enable_if_t<IsAlgVector<std::decay_t<V1> >::value &&
357 IsAlgVector<std::decay_t<V2> >::value &&
358 IsAlgVector<std::decay_t<V3> >::value>
363 Long n =
x.numLocalRows();
369 f(px[i], py[i], pz[i]);
373template <
typename V1,
typename V2,
typename V3,
typename V4,
typename F>
374std::enable_if_t<IsAlgVector<std::decay_t<V1> >::value &&
375 IsAlgVector<std::decay_t<V2> >::value &&
376 IsAlgVector<std::decay_t<V3> >::value &&
377 IsAlgVector<std::decay_t<V4> >::value>
383 Long n =
x.numLocalRows();
390 f(px[i], py[i], pz[i], pa[i]);
394template <
typename V1,
typename V2,
typename V3,
typename V4,
typename V5,
typename F>
395std::enable_if_t<IsAlgVector<std::decay_t<V1> >::value &&
396 IsAlgVector<std::decay_t<V2> >::value &&
397 IsAlgVector<std::decay_t<V3> >::value &&
398 IsAlgVector<std::decay_t<V4> >::value &&
399 IsAlgVector<std::decay_t<V5> >::value>
406 Long n =
x.numLocalRows();
414 f(px[i], py[i], pz[i], pa[i], pb[i]);
422 Long n =
x.numLocalRows();
423 auto const* px =
x.data();
424 auto const* py = y.
data();
427 return px[i] * py[i];
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_RESTRICT
Definition AMReX_Extension.H:37
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Definition AMReX_AlgPartition.H:14
Long numGlobalRows() const
Definition AMReX_AlgPartition.H:28
bool empty() const
Definition AMReX_AlgPartition.H:25
Definition AMReX_AlgVector.H:19
void setVal(T val)
Definition AMReX_AlgVector.H:146
Long numLocalRows() const
Definition AMReX_AlgVector.H:45
AMREX_FORCE_INLINE Table1D< T const, Long > const_view() const
Definition AMReX_AlgVector.H:62
T norminf(bool local=false) const
Definition AMReX_AlgVector.H:229
AlgPartition const & partition() const
Definition AMReX_AlgVector.H:43
void setValAsync(T val)
Definition AMReX_AlgVector.H:153
Long globalBegin() const
Inclusive global index begin.
Definition AMReX_AlgVector.H:49
bool empty() const
Definition AMReX_AlgVector.H:41
void plus(AlgVector< T > const &rhs)
Definition AMReX_AlgVector.H:182
T const * data() const
Definition AMReX_AlgVector.H:53
AlgPartition m_partition
Definition AMReX_AlgVector.H:101
AlgVector(AlgVector< T, Allocator > &&) noexcept=default
Long m_begin
Definition AMReX_AlgVector.H:102
Long m_end
Definition AMReX_AlgVector.H:103
void scale(T scale_factor)
Definition AMReX_AlgVector.H:199
void copy(AlgVector< T > const &rhs)
Definition AMReX_AlgVector.H:161
Long globalEnd() const
Exclusive global index end.
Definition AMReX_AlgVector.H:51
void copyFrom(FabArray< FAB > const &fa)
Definition AMReX_AlgVector.H:261
T * data()
Definition AMReX_AlgVector.H:54
Long numGlobalRows() const
Definition AMReX_AlgVector.H:46
void plusAsync(AlgVector< T > const &rhs)
Definition AMReX_AlgVector.H:189
T norm2(bool local=false) const
Definition AMReX_AlgVector.H:244
AlgVector & operator=(AlgVector< T, Allocator > const &)=delete
void define(Long global_size)
Definition AMReX_AlgVector.H:128
void scaleAsync(T scale_factor)
Definition AMReX_AlgVector.H:206
Vec m_data
Definition AMReX_AlgVector.H:104
AlgVector(AlgVector< T, Allocator > const &)=delete
T sum(bool local=false) const
Definition AMReX_AlgVector.H:214
AMREX_FORCE_INLINE Table1D< T, Long > view()
Definition AMReX_AlgVector.H:67
Allocator allocator_type
Definition AMReX_AlgVector.H:22
void copyTo(FabArray< FAB > &fa) const
Definition AMReX_AlgVector.H:283
AMREX_FORCE_INLINE Table1D< T const, Long > view() const
Definition AMReX_AlgVector.H:57
void copyAsync(AlgVector< T > const &rhs)
Definition AMReX_AlgVector.H:168
T value_type
Definition AMReX_AlgVector.H:21
void printToFile(std::string const &file) const
Definition AMReX_AlgVector.H:303
bool is_cell_centered() const noexcept
This tests on whether the FabArray is cell-centered.
const DistributionMapping & DistributionMap() const noexcept
Return constant reference to associated DistributionMapping.
Definition AMReX_FabArrayBase.H:130
const BoxArray & boxArray() const noexcept
Return a constant reference to the BoxArray that defines the valid region associated with this FabArr...
Definition AMReX_FabArrayBase.H:94
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:344
a one-thingy-per-box distributed object
Definition AMReX_LayoutData.H:13
Definition AMReX_MFIter.H:57
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:141
Definition AMReX_PODVector.H:262
size_type size() const noexcept
Definition AMReX_PODVector.H:591
T * data() noexcept
Definition AMReX_PODVector.H:609
void dtod_memcpy_async(void *p_d_dst, const void *p_d_src, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:279
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:237
void dtoh_memcpy_async(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:265
void Sum(T &v, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:204
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:126
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
int MyProc() noexcept
return the rank number local to the current Parallel Context
Definition AMReX_ParallelDescriptor.H:125
Definition AMReX_Amr.cpp:49
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:191
void Axpy(AlgVector< T > &y, T a, AlgVector< T > const &x, bool async=false)
Definition AMReX_AlgVector.H:436
void LinComb(MF &dst, typename MF::value_type a, MF const &src_a, int acomp, typename MF::value_type b, MF const &src_b, int bcomp, int dcomp, int ncomp, IntVect const &nghost)
dst = a*src_a + b*src_b
Definition AMReX_FabArrayUtility.H:1863
constexpr void ForEach(TypeList< Ts... >, F &&f)
For each type t in TypeList, call f(t)
Definition AMReX_TypeList.H:78
FAB::value_type Dot(FabArray< FAB > const &x, int xcomp, FabArray< FAB > const &y, int ycomp, int ncomp, IntVect const &nghost, bool local=false)
Compute dot products of two FabArrays.
Definition AMReX_FabArrayUtility.H:1554
Definition AMReX_AlgVector.H:320
Definition AMReX_TableData.H:20