16 #include "../general/forall.hpp"
18 #if defined(MFEM_USE_SUNDIALS) && defined(MFEM_USE_MPI)
19 #include <nvector/nvector_parallel.h>
20 #include <nvector/nvector_parhyp.h>
35 const int s = v.
Size();
38 MFEM_ASSERT(!v.
data.
Empty(),
"invalid source vector");
56 for (i = 0; i < np; i++)
64 for (i = 0; i < np; i++)
66 for (j = 0; j < dim[i]; j++)
77 for (
int i = 0; i <
size; i++)
96 #ifdef MFEM_USE_LEGACY_OPENMP
97 #pragma omp parallel for reduction(+:dot)
99 for (
int i = 0; i <
size; i++)
101 dot +=
data[i] * v[i];
123 if (use_dev) {
Write(); }
133 auto y =
Write(use_dev);
134 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = value;);
143 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] *= c;);
151 const double m = 1.0/c;
153 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] *= m;);
162 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] -= c;);
168 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
173 auto x = v.
Read(use_dev);
174 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] -= x[i];);
180 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
185 auto x = v.
Read(use_dev);
186 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] += x[i];);
192 MFEM_ASSERT(
size == Va.
size,
"incompatible Vectors!");
199 auto x = Va.
Read(use_dev);
200 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] += a * x[i];);
207 MFEM_ASSERT(
size == Va.
size,
"incompatible Vectors!");
211 auto x = Va.
Read(use_dev);
212 auto y =
Write(use_dev);
213 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = a * x[i];);
219 MFEM_ASSERT(v.
Size() + offset <=
size,
"invalid sub-vector");
221 const int vs = v.
Size();
222 const double *vp = v.
data;
223 double *p =
data + offset;
224 for (
int i = 0; i < vs; i++)
235 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = -y[i];);
241 "incompatible Vectors!");
243 #if !defined(MFEM_USE_LEGACY_OPENMP)
245 const int N = v.
size;
247 auto x1 = v1.
Read(use_dev);
248 auto x2 = v2.
Read(use_dev);
249 auto y = v.
Write(use_dev);
250 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = x1[i] + x2[i];);
252 #pragma omp parallel for
253 for (
int i = 0; i < v.
size; i++)
263 "incompatible Vectors!");
269 else if (alpha == 1.0)
275 #if !defined(MFEM_USE_LEGACY_OPENMP)
277 const int N = v.
size;
279 auto d_x = v1.
Read(use_dev);
280 auto d_y = v2.
Read(use_dev);
281 auto d_z = v.
Write(use_dev);
282 MFEM_FORALL_SWITCH(use_dev, i, N, d_z[i] = d_x[i] + alpha * d_y[i];);
284 const double *v1p = v1.
data, *v2p = v2.
data;
286 const int s = v.
size;
287 #pragma omp parallel for
288 for (
int i = 0; i < s; i++)
290 vp[i] = v1p[i] + alpha*v2p[i];
299 "incompatible Vectors!");
311 #if !defined(MFEM_USE_LEGACY_OPENMP)
313 const int N = x.
size;
315 auto xd = x.
Read(use_dev);
316 auto yd = y.
Read(use_dev);
317 auto zd = z.
Write(use_dev);
318 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = a * (xd[i] + yd[i]););
320 const double *xp = x.
data;
321 const double *yp = y.
data;
323 const int s = x.
size;
324 #pragma omp parallel for
325 for (
int i = 0; i < s; i++)
327 zp[i] = a * (xp[i] + yp[i]);
337 "incompatible Vectors!");
363 #if !defined(MFEM_USE_LEGACY_OPENMP)
365 const int N = x.
size;
367 auto xd = x.
Read(use_dev);
368 auto yd = y.
Read(use_dev);
369 auto zd = z.
Write(use_dev);
370 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = a * xd[i] + b * yd[i];);
372 const double *xp = x.
data;
373 const double *yp = y.
data;
375 const int s = x.
size;
376 #pragma omp parallel for
377 for (
int i = 0; i < s; i++)
379 zp[i] = a * xp[i] + b * yp[i];
388 "incompatible Vectors!");
390 #if !defined(MFEM_USE_LEGACY_OPENMP)
392 const int N = x.
size;
394 auto xd = x.
Read(use_dev);
395 auto yd = y.
Read(use_dev);
396 auto zd = z.
Write(use_dev);
397 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = xd[i] - yd[i];);
399 const double *xp = x.
data;
400 const double *yp = y.
data;
402 const int s = x.
size;
403 #pragma omp parallel for
404 for (
int i = 0; i < s; i++)
406 zp[i] = xp[i] - yp[i];
414 "incompatible Vectors!");
426 #if !defined(MFEM_USE_LEGACY_OPENMP)
428 const int N = x.
size;
430 auto xd = x.
Read(use_dev);
431 auto yd = y.
Read(use_dev);
432 auto zd = z.
Write(use_dev);
433 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = a * (xd[i] - yd[i]););
435 const double *xp = x.
data;
436 const double *yp = y.
data;
438 const int s = x.
size;
439 #pragma omp parallel for
440 for (
int i = 0; i < s; i++)
442 zp[i] = a * (xp[i] - yp[i]);
451 "incompatible Vectors!");
456 auto l = lo.
Read(use_dev);
457 auto h = hi.
Read(use_dev);
458 auto m =
Write(use_dev);
459 MFEM_FORALL_SWITCH(use_dev, i, N,
465 else if (m[i] > h[i])
474 const int n = dofs.
Size();
477 auto d_y = elemvect.
Write(use_dev);
478 auto d_X =
Read(use_dev);
479 auto d_dofs = dofs.
Read(use_dev);
480 MFEM_FORALL_SWITCH(use_dev, i, n,
482 const int dof_i = d_dofs[i];
483 d_y[i] = dof_i >= 0 ? d_X[dof_i] : -d_X[-dof_i-1];
490 const int n = dofs.
Size();
491 for (
int i = 0; i < n; i++)
493 const int j = dofs[i];
494 elem_data[i] = (j >= 0) ?
data[j] : -
data[-1-j];
501 const int n = dofs.
Size();
504 auto d_dofs = dofs.
Read(use_dev);
505 MFEM_FORALL_SWITCH(use_dev, i, n,
507 const int j = d_dofs[i];
521 MFEM_ASSERT(dofs.
Size() == elemvect.
Size(),
522 "Size mismatch: length of dofs is " << dofs.
Size()
523 <<
", length of elemvect is " << elemvect.
Size());
526 const int n = dofs.
Size();
529 auto d_y = elemvect.
Read(use_dev);
530 auto d_dofs = dofs.
Read(use_dev);
531 MFEM_FORALL_SWITCH(use_dev, i, n,
533 const int dof_i = d_dofs[i];
540 d_X[-1-dof_i] = -d_y[i];
549 const int n = dofs.
Size();
550 for (
int i = 0; i < n; i++)
552 const int j= dofs[i];
566 MFEM_ASSERT(dofs.
Size() == elemvect.
Size(),
"Size mismatch: "
567 "length of dofs is " << dofs.
Size() <<
568 ", length of elemvect is " << elemvect.
Size());
571 const int n = dofs.
Size();
572 auto d_y = elemvect.
Read(use_dev);
574 auto d_dofs = dofs.
Read(use_dev);
575 MFEM_FORALL_SWITCH(use_dev, i, n,
577 const int j = d_dofs[i];
592 const int n = dofs.
Size();
593 for (
int i = 0; i < n; i++)
595 const int j = dofs[i];
610 MFEM_ASSERT(dofs.
Size() == elemvect.
Size(),
"Size mismatch: "
611 "length of dofs is " << dofs.
Size() <<
612 ", length of elemvect is " << elemvect.
Size());
615 const int n = dofs.
Size();
617 auto d_x = elemvect.
Read(use_dev);
618 auto d_dofs = dofs.
Read(use_dev);
619 MFEM_FORALL_SWITCH(use_dev, i, n,
621 const int j = d_dofs[i];
624 d_y[j] += a * d_x[i];
628 d_y[-1-j] -= a * d_x[i];
636 const int n = dofs.
Size();
638 Vector dofs_vals(n, use_dev ?
642 auto d_dofs_vals = dofs_vals.
Write(use_dev);
643 auto d_dofs = dofs.
Read(use_dev);
644 MFEM_FORALL_SWITCH(use_dev, i, n, d_dofs_vals[i] = d_data[d_dofs[i]];);
645 MFEM_FORALL_SWITCH(use_dev, i, N, d_data[i] = val;);
646 MFEM_FORALL_SWITCH(use_dev, i, n, d_data[d_dofs[i]] = d_dofs_vals[i];);
651 if (!
size) {
return; }
661 if ( i % width == 0 )
676 std::ios::fmtflags old_fmt = out.flags();
677 out.setf(std::ios::scientific);
678 std::streamsize old_prec = out.precision(14);
683 for (i = 0; i <
size; i++)
685 out <<
data[i] <<
'\n';
688 out.precision(old_prec);
695 const double max = (double)(RAND_MAX) + 1.;
703 srand((
unsigned)seed);
705 for (
int i = 0; i <
size; i++)
707 data[i] = std::abs(rand()/max);
724 return std::abs(
data[0]);
732 for (
int i = 0; i <
size; i++)
734 max = std::max(std::abs(
data[i]), max);
742 for (
int i = 0; i <
size; i++)
744 sum += std::abs(
data[i]);
751 MFEM_ASSERT(p > 0.0,
"Vector::Normlp");
773 return std::abs(
data[0]);
779 for (
int i = 0; i <
size; i++)
783 const double absdata = std::abs(
data[i]);
784 if (scale <= absdata)
786 sum = 1.0 + sum * std::pow(scale / absdata, p);
790 sum += std::pow(absdata / scale, p);
793 return scale * std::pow(sum, 1.0/p);
803 double max =
data[0];
805 for (
int i = 1; i <
size; i++)
820 const double *h_data = this->
HostRead();
821 for (
int i = 0; i <
size; i++)
830 static __global__
void cuKernelMin(
const int N,
double *gdsr,
const double *x)
832 __shared__
double s_min[MFEM_CUDA_BLOCKS];
833 const int n = blockDim.x*blockIdx.x + threadIdx.x;
834 if (n>=N) {
return; }
835 const int bid = blockIdx.x;
836 const int tid = threadIdx.x;
837 const int bbd = bid*blockDim.x;
838 const int rid = bbd+tid;
840 for (
int workers=blockDim.x>>1; workers>0; workers>>=1)
843 if (tid >= workers) {
continue; }
844 if (rid >= N) {
continue; }
845 const int dualTid = tid + workers;
846 if (dualTid >= N) {
continue; }
847 const int rdd = bbd+dualTid;
848 if (rdd >= N) {
continue; }
849 if (dualTid >= blockDim.x) {
continue; }
850 s_min[tid] = fmin(s_min[tid], s_min[dualTid]);
852 if (tid==0) { gdsr[bid] = s_min[0]; }
855 static Array<double> cuda_reduce_buf;
857 static double cuVectorMin(
const int N,
const double *X)
859 const int tpb = MFEM_CUDA_BLOCKS;
860 const int blockSize = MFEM_CUDA_BLOCKS;
861 const int gridSize = (N+blockSize-1)/blockSize;
862 const int min_sz = (N%tpb)==0? (N/tpb) : (1+N/tpb);
863 cuda_reduce_buf.
SetSize(min_sz);
864 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
866 cuKernelMin<<<gridSize,blockSize>>>(N, d_min, X);
867 MFEM_GPU_CHECK(cudaGetLastError());
870 for (
int i = 0; i < min_sz; i++) { min = fmin(min, h_min[i]); }
874 static __global__
void cuKernelDot(
const int N,
double *gdsr,
875 const double *x,
const double *y)
877 __shared__
double s_dot[MFEM_CUDA_BLOCKS];
878 const int n = blockDim.x*blockIdx.x + threadIdx.x;
879 if (n>=N) {
return; }
880 const int bid = blockIdx.x;
881 const int tid = threadIdx.x;
882 const int bbd = bid*blockDim.x;
883 const int rid = bbd+tid;
884 s_dot[tid] = x[n] * y[n];
885 for (
int workers=blockDim.x>>1; workers>0; workers>>=1)
888 if (tid >= workers) {
continue; }
889 if (rid >= N) {
continue; }
890 const int dualTid = tid + workers;
891 if (dualTid >= N) {
continue; }
892 const int rdd = bbd+dualTid;
893 if (rdd >= N) {
continue; }
894 if (dualTid >= blockDim.x) {
continue; }
895 s_dot[tid] += s_dot[dualTid];
897 if (tid==0) { gdsr[bid] = s_dot[0]; }
900 static double cuVectorDot(
const int N,
const double *X,
const double *Y)
902 const int tpb = MFEM_CUDA_BLOCKS;
903 const int blockSize = MFEM_CUDA_BLOCKS;
904 const int gridSize = (N+blockSize-1)/blockSize;
905 const int dot_sz = (N%tpb)==0? (N/tpb) : (1+N/tpb);
907 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
909 cuKernelDot<<<gridSize,blockSize>>>(N, d_dot, X, Y);
910 MFEM_GPU_CHECK(cudaGetLastError());
913 for (
int i = 0; i < dot_sz; i++) { dot += h_dot[i]; }
916 #endif // MFEM_USE_CUDA
919 static __global__
void hipKernelMin(
const int N,
double *gdsr,
const double *x)
921 __shared__
double s_min[MFEM_CUDA_BLOCKS];
922 const int n = hipBlockDim_x*hipBlockIdx_x + hipThreadIdx_x;
923 if (n>=N) {
return; }
924 const int bid = hipBlockIdx_x;
925 const int tid = hipThreadIdx_x;
926 const int bbd = bid*hipBlockDim_x;
927 const int rid = bbd+tid;
929 for (
int workers=hipBlockDim_x>>1; workers>0; workers>>=1)
932 if (tid >= workers) {
continue; }
933 if (rid >= N) {
continue; }
934 const int dualTid = tid + workers;
935 if (dualTid >= N) {
continue; }
936 const int rdd = bbd+dualTid;
937 if (rdd >= N) {
continue; }
938 if (dualTid >= hipBlockDim_x) {
continue; }
939 s_min[tid] = fmin(s_min[tid], s_min[dualTid]);
941 if (tid==0) { gdsr[bid] = s_min[0]; }
944 static Array<double> cuda_reduce_buf;
946 static double hipVectorMin(
const int N,
const double *X)
948 const int tpb = MFEM_CUDA_BLOCKS;
949 const int blockSize = MFEM_CUDA_BLOCKS;
950 const int gridSize = (N+blockSize-1)/blockSize;
951 const int min_sz = (N%tpb)==0 ? (N/tpb) : (1+N/tpb);
952 cuda_reduce_buf.
SetSize(min_sz);
953 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
955 hipLaunchKernelGGL(hipKernelMin,gridSize,blockSize,0,0,N,d_min,X);
956 MFEM_GPU_CHECK(hipGetLastError());
959 for (
int i = 0; i < min_sz; i++) { min = fmin(min, h_min[i]); }
963 static __global__
void hipKernelDot(
const int N,
double *gdsr,
964 const double *x,
const double *y)
966 __shared__
double s_dot[MFEM_CUDA_BLOCKS];
967 const int n = hipBlockDim_x*hipBlockIdx_x + hipThreadIdx_x;
968 if (n>=N) {
return; }
969 const int bid = hipBlockIdx_x;
970 const int tid = hipThreadIdx_x;
971 const int bbd = bid*hipBlockDim_x;
972 const int rid = bbd+tid;
973 s_dot[tid] = x[n] * y[n];
974 for (
int workers=hipBlockDim_x>>1; workers>0; workers>>=1)
977 if (tid >= workers) {
continue; }
978 if (rid >= N) {
continue; }
979 const int dualTid = tid + workers;
980 if (dualTid >= N) {
continue; }
981 const int rdd = bbd+dualTid;
982 if (rdd >= N) {
continue; }
983 if (dualTid >= hipBlockDim_x) {
continue; }
984 s_dot[tid] += s_dot[dualTid];
986 if (tid==0) { gdsr[bid] = s_dot[0]; }
989 static double hipVectorDot(
const int N,
const double *X,
const double *Y)
991 const int tpb = MFEM_CUDA_BLOCKS;
992 const int blockSize = MFEM_CUDA_BLOCKS;
993 const int gridSize = (N+blockSize-1)/blockSize;
994 const int dot_sz = (N%tpb)==0 ? (N/tpb) : (1+N/tpb);
995 cuda_reduce_buf.
SetSize(dot_sz);
996 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
998 hipLaunchKernelGGL(hipKernelDot,gridSize,blockSize,0,0,N,d_dot,X,Y);
999 MFEM_GPU_CHECK(hipGetLastError());
1002 for (
int i = 0; i < dot_sz; i++) { dot += h_dot[i]; }
1005 #endif // MFEM_USE_HIP
1009 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
1012 #if defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP) || defined(MFEM_USE_OPENMP)
1013 auto m_data =
Read(use_dev);
1017 auto v_data = v.
Read(use_dev);
1019 if (!use_dev) {
goto vector_dot_cpu; }
1021 #ifdef MFEM_USE_OCCA
1024 return occa::linalg::dot<double,double,double>(
1029 #ifdef MFEM_USE_CUDA
1032 return cuVectorDot(
size, m_data, v_data);
1039 return hipVectorDot(
size, m_data, v_data);
1043 #ifdef MFEM_USE_OPENMP
1047 #pragma omp parallel for reduction(+:prod)
1048 for (
int i = 0; i <
size; i++)
1050 prod += m_data[i] * v_data[i];
1058 auto v_data = v.
Read();
1059 auto m_data =
Read();
1062 auto d_dot = dot.
Write();
1064 MFEM_FORALL(i, N, d_dot[0] += m_data[i] * v_data[i];);
1077 auto m_data =
Read(use_dev);
1079 if (!use_dev) {
goto vector_min_cpu; }
1081 #ifdef MFEM_USE_OCCA
1088 #ifdef MFEM_USE_CUDA
1091 return cuVectorMin(
size, m_data);
1098 return hipVectorMin(
size, m_data);
1102 #ifdef MFEM_USE_OPENMP
1105 double minimum = m_data[0];
1106 #pragma omp parallel for reduction(min:minimum)
1107 for (
int i = 0; i <
size; i++)
1109 minimum = std::min(minimum, m_data[i]);
1118 auto m_data =
Read();
1123 MFEM_FORALL(i, N, d_min[0] = (d_min[0]<m_data[i])?d_min[0]:m_data[i];);
1129 double minimum =
data[0];
1130 for (
int i = 1; i <
size; i++)
1132 if (m_data[i] < minimum)
1134 minimum = m_data[i];
1141 #ifdef MFEM_USE_SUNDIALS
1145 N_Vector_ID nvid = N_VGetVectorID(nv);
1148 case SUNDIALS_NVEC_SERIAL:
1152 case SUNDIALS_NVEC_PARALLEL:
1155 case SUNDIALS_NVEC_PARHYP:
1157 hypre_Vector *hpv_local = N_VGetVector_ParHyp(nv)->local_vector;
1163 MFEM_ABORT(
"N_Vector type " << nvid <<
" is not supported");
1169 MFEM_ASSERT(nv,
"N_Vector handle is NULL");
1170 N_Vector_ID nvid = N_VGetVectorID(nv);
1173 case SUNDIALS_NVEC_SERIAL:
1174 MFEM_ASSERT(NV_OWN_DATA_S(nv) == SUNFALSE,
"invalid serial N_Vector");
1175 NV_DATA_S(nv) =
data;
1176 NV_LENGTH_S(nv) =
size;
1179 case SUNDIALS_NVEC_PARALLEL:
1180 MFEM_ASSERT(NV_OWN_DATA_P(nv) == SUNFALSE,
"invalid parallel N_Vector");
1181 NV_DATA_P(nv) =
data;
1182 NV_LOCLENGTH_P(nv) =
size;
1184 case SUNDIALS_NVEC_PARHYP:
1186 hypre_Vector *hpv_local = N_VGetVector_ParHyp(nv)->local_vector;
1187 MFEM_ASSERT(hpv_local->owns_data ==
false,
"invalid hypre N_Vector");
1188 hpv_local->data =
data;
1189 hpv_local->size =
size;
1194 MFEM_ABORT(
"N_Vector type " << nvid <<
" is not supported");
1198 #endif // MFEM_USE_SUNDIALS
int Size() const
Logical size of the array.
void SetSubVector(const Array< int > &dofs, const double value)
Set the entries listed in dofs to the given value.
void SetVector(const Vector &v, int offset)
double * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
Vector()
Default constructor for Vector. Sets size = 0 and data = NULL.
Memory< T > & GetMemory()
Return a reference to the Memory object used by the Array.
double & Elem(int i)
Access Vector entries. Index i = 0 .. size-1.
Device memory; using CUDA or HIP *Malloc and *Free.
void SetSize(int s)
Resize the vector to size s.
double Norml2() const
Returns the l2 norm of the vector.
double & operator()(int i)
Access Vector entries using () for 0-based indexing.
Biwise-OR of all HIP backends.
void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
int Size() const
Returns the size of the vector.
T * Write(MemoryClass mc, int size)
Get write-only access to the memory with the given MemoryClass.
bool UseDevice() const
Return the device flag of the Memory object used by the Array.
double Normlinf() const
Returns the l_infinity norm of the vector.
void CopyFrom(const Memory &src, int size)
Copy size entries from src to *this.
void Randomize(int seed=0)
Set random values in the vector.
double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
void add(const Vector &v1, const Vector &v2, Vector &v)
double operator*(const double *) const
Dot product with a double * array.
MemoryType GetMemoryType() const
Return a MemoryType that is currently valid. If both the host and the device pointers are currently v...
unsigned flags
Bit flags defined from the FlagMask enum.
Vector & operator=(const double *v)
Copy Size() entries from v.
void Load(std::istream **in, int np, int *dim)
Reads a vector from multiple files.
const double * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
double Normlp(double p) const
Returns the l_p norm of the vector.
double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
void CopyFromHost(const T *src, int size)
Copy size entries from the host pointer src to *this.
bool DeviceCanUseOcca()
Function that determines if an OCCA kernel should be used, based on the current mfem::Device configur...
static MemoryType GetDeviceMemoryType()
Get the current Device MemoryType. This is the MemoryType used by most MFEM classes when allocating m...
const occa::memory OccaMemoryRead(const Memory< T > &mem, size_t size)
Wrap a Memory object as occa::memory for read only access with the mfem::Device MemoryClass. The returned occa::memory is associated with the default occa::device used by MFEM.
void median(const Vector &lo, const Vector &hi)
v = median(v,lo,hi) entrywise. Implementation assumes lo <= hi.
Biwise-OR of all OpenMP backends.
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
[device] Debug backend: host memory is READ/WRITE protected while a device is in use. It allows to test the "device" code-path (using separate host/device memory pools and host <-> device transfers) without any GPU hardware.
MFEM_HOST_DEVICE double Norml2(const int size, const T *data)
Returns the l2 norm of the Vector with given size and data.
void Reset()
Reset the memory to be empty, ensuring that Delete() will be a no-op.
void AddElementVector(const Array< int > &dofs, const Vector &elemvect)
Add (element) subvector to the vector.
Vector & operator/=(double c)
Biwise-OR of all CUDA backends.
void SetSubVectorComplement(const Array< int > &dofs, const double val)
Set all vector entries NOT in the 'dofs' array to the given 'val'.
Vector & operator*=(double c)
double Min() const
Returns the minimal element of the vector.
double Norml1() const
Returns the l_1 norm of the vector.
static MemoryType GetHostMemoryType()
Get the current Host MemoryType. This is the MemoryType used by most MFEM classes when allocating mem...
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
void subtract(const Vector &x, const Vector &y, Vector &z)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
void Print_HYPRE(std::ostream &out) const
Prints vector to stream out in HYPRE_Vector format.
static bool Allows(unsigned long b_mask)
Return true if any of the backends in the backend mask, b_mask, are allowed.
void SetDataAndSize(double *d, int s)
Set the Vector data and size.
Vector & Set(const double a, const Vector &x)
(*this) = a * x
Vector & Add(const double a, const Vector &Va)
(*this) += a * Va
Host memory; using new[] and delete[].
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
double Max() const
Returns the maximal element of the vector.
void New(int size)
Allocate host memory for size entries with the current host memory type returned by MemoryManager::Ge...
bool Empty() const
Return true if the Memory object is empty, see Reset().
T * ReadWrite(MemoryClass mc, int size)
Get read-write access to the memory with the given MemoryClass.
Vector & operator-=(double c)
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Vector & operator+=(const Vector &v)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
const T * Read(MemoryClass mc, int size) const
Get read-only access to the memory with the given MemoryClass.
double Sum() const
Return the sum of the vector entries.
virtual N_Vector ToNVector()
Return a new wrapper SUNDIALS N_Vector of type SUNDIALS_NVEC_SERIAL.
void Neg()
(*this) = -(*this)