14 #include "kernels.hpp"
16 #include "../general/forall.hpp"
18 #if defined(MFEM_USE_SUNDIALS)
20 #if defined(MFEM_USE_MPI)
21 #include <nvector/nvector_parallel.h>
25 #ifdef MFEM_USE_OPENMP
41 const int s = v.
Size();
44 MFEM_ASSERT(!v.
data.
Empty(),
"invalid source vector");
62 for (i = 0; i < np; i++)
70 for (i = 0; i < np; i++)
72 for (j = 0; j < dim[i]; j++)
77 if (!*in[i] && errno == ERANGE)
89 for (
int i = 0; i <
size; i++)
94 if (!in && errno == ERANGE)
114 #ifdef MFEM_USE_LEGACY_OPENMP
115 #pragma omp parallel for reduction(+:dot)
117 for (
int i = 0; i <
size; i++)
119 dot +=
data[i] * v[i];
139 const bool use_dev =
UseDevice() || vuse;
142 if (use_dev) {
Write(); }
153 auto y =
Write(use_dev);
154 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = value;);
163 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] *= c;);
169 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
174 auto x = v.
Read(use_dev);
175 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] *= x[i];);
183 const double m = 1.0/c;
185 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] *= m;);
191 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
196 auto x = v.
Read(use_dev);
197 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] /= x[i];);
206 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] -= c;);
212 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
217 auto x = v.
Read(use_dev);
218 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] -= x[i];);
227 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] += c;);
233 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
238 auto x = v.
Read(use_dev);
239 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] += x[i];);
245 MFEM_ASSERT(
size == Va.
size,
"incompatible Vectors!");
252 auto x = Va.
Read(use_dev);
253 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] += a * x[i];);
260 MFEM_ASSERT(
size == Va.
size,
"incompatible Vectors!");
264 auto x = Va.
Read(use_dev);
265 auto y =
Write(use_dev);
266 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = a * x[i];);
272 MFEM_ASSERT(v.
Size() + offset <=
size,
"invalid sub-vector");
274 const int vs = v.
Size();
275 const double *vp = v.
data;
276 double *
p =
data + offset;
277 for (
int i = 0; i < vs; i++)
288 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = -y[i];);
294 "incompatible Vectors!");
296 #if !defined(MFEM_USE_LEGACY_OPENMP)
298 const int N = v.
size;
300 auto x1 = v1.
Read(use_dev);
301 auto x2 = v2.
Read(use_dev);
302 auto y = v.
Write(use_dev);
303 MFEM_FORALL_SWITCH(use_dev, i, N, y[i] = x1[i] + x2[i];);
305 #pragma omp parallel for
306 for (
int i = 0; i < v.
size; i++)
316 "incompatible Vectors!");
322 else if (alpha == 1.0)
328 #if !defined(MFEM_USE_LEGACY_OPENMP)
330 const int N = v.
size;
332 auto d_x = v1.
Read(use_dev);
333 auto d_y = v2.
Read(use_dev);
334 auto d_z = v.
Write(use_dev);
335 MFEM_FORALL_SWITCH(use_dev, i, N, d_z[i] = d_x[i] + alpha * d_y[i];);
337 const double *v1p = v1.
data, *v2p = v2.
data;
339 const int s = v.
size;
340 #pragma omp parallel for
341 for (
int i = 0; i <
s; i++)
343 vp[i] = v1p[i] + alpha*v2p[i];
352 "incompatible Vectors!");
364 #if !defined(MFEM_USE_LEGACY_OPENMP)
366 const int N = x.
size;
368 auto xd = x.
Read(use_dev);
369 auto yd = y.
Read(use_dev);
370 auto zd = z.
Write(use_dev);
371 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = a * (xd[i] + yd[i]););
373 const double *xp = x.
data;
374 const double *yp = y.
data;
376 const int s = x.
size;
377 #pragma omp parallel for
378 for (
int i = 0; i <
s; i++)
380 zp[i] = a * (xp[i] + yp[i]);
390 "incompatible Vectors!");
416 #if !defined(MFEM_USE_LEGACY_OPENMP)
418 const int N = x.
size;
420 auto xd = x.
Read(use_dev);
421 auto yd = y.
Read(use_dev);
422 auto zd = z.
Write(use_dev);
423 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = a * xd[i] + b * yd[i];);
425 const double *xp = x.
data;
426 const double *yp = y.
data;
428 const int s = x.
size;
429 #pragma omp parallel for
430 for (
int i = 0; i <
s; i++)
432 zp[i] = a * xp[i] + b * yp[i];
441 "incompatible Vectors!");
443 #if !defined(MFEM_USE_LEGACY_OPENMP)
445 const int N = x.
size;
447 auto xd = x.
Read(use_dev);
448 auto yd = y.
Read(use_dev);
449 auto zd = z.
Write(use_dev);
450 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = xd[i] - yd[i];);
452 const double *xp = x.
data;
453 const double *yp = y.
data;
455 const int s = x.
size;
456 #pragma omp parallel for
457 for (
int i = 0; i <
s; i++)
459 zp[i] = xp[i] - yp[i];
467 "incompatible Vectors!");
479 #if !defined(MFEM_USE_LEGACY_OPENMP)
481 const int N = x.
size;
483 auto xd = x.
Read(use_dev);
484 auto yd = y.
Read(use_dev);
485 auto zd = z.
Write(use_dev);
486 MFEM_FORALL_SWITCH(use_dev, i, N, zd[i] = a * (xd[i] - yd[i]););
488 const double *xp = x.
data;
489 const double *yp = y.
data;
491 const int s = x.
size;
492 #pragma omp parallel for
493 for (
int i = 0; i <
s; i++)
495 zp[i] = a * (xp[i] - yp[i]);
504 "incompatible Vectors!");
509 auto l = lo.
Read(use_dev);
510 auto h = hi.
Read(use_dev);
511 auto m =
Write(use_dev);
512 MFEM_FORALL_SWITCH(use_dev, i, N,
518 else if (m[i] > h[i])
527 const int n = dofs.
Size();
530 auto d_y = elemvect.
Write(use_dev);
531 auto d_X =
Read(use_dev);
532 auto d_dofs = dofs.
Read(use_dev);
533 MFEM_FORALL_SWITCH(use_dev, i, n,
535 const int dof_i = d_dofs[i];
536 d_y[i] = dof_i >= 0 ? d_X[dof_i] : -d_X[-dof_i-1];
543 const int n = dofs.
Size();
544 for (
int i = 0; i < n; i++)
546 const int j = dofs[i];
547 elem_data[i] = (j >= 0) ?
data[j] : -
data[-1-j];
554 const int n = dofs.
Size();
557 auto d_dofs = dofs.
Read(use_dev);
558 MFEM_FORALL_SWITCH(use_dev, i, n,
560 const int j = d_dofs[i];
574 MFEM_ASSERT(dofs.
Size() == elemvect.
Size(),
575 "Size mismatch: length of dofs is " << dofs.
Size()
576 <<
", length of elemvect is " << elemvect.
Size());
579 const int n = dofs.
Size();
582 auto d_y = elemvect.
Read(use_dev);
583 auto d_dofs = dofs.
Read(use_dev);
584 MFEM_FORALL_SWITCH(use_dev, i, n,
586 const int dof_i = d_dofs[i];
593 d_X[-1-dof_i] = -d_y[i];
602 const int n = dofs.
Size();
603 for (
int i = 0; i < n; i++)
605 const int j= dofs[i];
619 MFEM_ASSERT(dofs.
Size() == elemvect.
Size(),
"Size mismatch: "
620 "length of dofs is " << dofs.
Size() <<
621 ", length of elemvect is " << elemvect.
Size());
624 const int n = dofs.
Size();
625 auto d_y = elemvect.
Read(use_dev);
627 auto d_dofs = dofs.
Read(use_dev);
628 MFEM_FORALL_SWITCH(use_dev, i, n,
630 const int j = d_dofs[i];
645 const int n = dofs.
Size();
646 for (
int i = 0; i < n; i++)
648 const int j = dofs[i];
663 MFEM_ASSERT(dofs.
Size() == elemvect.
Size(),
"Size mismatch: "
664 "length of dofs is " << dofs.
Size() <<
665 ", length of elemvect is " << elemvect.
Size());
668 const int n = dofs.
Size();
670 auto d_x = elemvect.
Read(use_dev);
671 auto d_dofs = dofs.
Read(use_dev);
672 MFEM_FORALL_SWITCH(use_dev, i, n,
674 const int j = d_dofs[i];
677 d_y[j] += a * d_x[i];
681 d_y[-1-j] -= a * d_x[i];
689 const int n = dofs.
Size();
691 Vector dofs_vals(n, use_dev ?
695 auto d_dofs_vals = dofs_vals.
Write(use_dev);
696 auto d_dofs = dofs.
Read(use_dev);
697 MFEM_FORALL_SWITCH(use_dev, i, n, d_dofs_vals[i] = d_data[d_dofs[i]];);
698 MFEM_FORALL_SWITCH(use_dev, i, N, d_data[i] = val;);
699 MFEM_FORALL_SWITCH(use_dev, i, n, d_data[d_dofs[i]] = d_dofs_vals[i];);
704 if (!
size) {
return; }
714 if ( i % width == 0 )
726 #ifdef MFEM_USE_ADIOS2
728 const std::string& variable_name)
const
730 if (!
size) {
return; }
732 out.engine.Put(variable_name, &
data[0] );
739 std::ios::fmtflags old_fmt = out.flags();
740 out.setf(std::ios::scientific);
741 std::streamsize old_prec = out.precision(14);
746 for (i = 0; i <
size; i++)
751 out.precision(old_prec);
757 out <<
"size: " <<
size <<
'\n';
760 out <<
"hash: " << hf.
GetHash() <<
'\n';
766 const double max = (double)(RAND_MAX) + 1.;
774 srand((
unsigned)seed);
777 for (
int i = 0; i <
size; i++)
779 data[i] = std::abs(rand()/max);
796 return std::abs(
data[0]);
805 for (
int i = 0; i <
size; i++)
807 max = std::max(std::abs(
data[i]), max);
816 for (
int i = 0; i <
size; i++)
818 sum += std::abs(
data[i]);
825 MFEM_ASSERT(p > 0.0,
"Vector::Normlp");
847 return std::abs(
data[0]);
853 for (
int i = 0; i <
size; i++)
857 const double absdata = std::abs(
data[i]);
858 if (scale <= absdata)
860 sum = 1.0 + sum * std::pow(scale / absdata, p);
864 sum += std::pow(absdata / scale, p);
867 return scale * std::pow(sum, 1.0/p);
878 double max =
data[0];
880 for (
int i = 1; i <
size; i++)
895 const double *h_data = this->
HostRead();
896 for (
int i = 0; i <
size; i++)
905 static __global__
void cuKernelMin(
const int N,
double *gdsr,
const double *x)
907 __shared__
double s_min[MFEM_CUDA_BLOCKS];
908 const int n = blockDim.x*blockIdx.x + threadIdx.x;
909 if (n>=N) {
return; }
910 const int bid = blockIdx.x;
911 const int tid = threadIdx.x;
912 const int bbd = bid*blockDim.x;
913 const int rid = bbd+tid;
915 for (
int workers=blockDim.x>>1; workers>0; workers>>=1)
918 if (tid >= workers) {
continue; }
919 if (rid >= N) {
continue; }
920 const int dualTid = tid + workers;
921 if (dualTid >= N) {
continue; }
922 const int rdd = bbd+dualTid;
923 if (rdd >= N) {
continue; }
924 if (dualTid >= blockDim.x) {
continue; }
925 s_min[tid] = fmin(s_min[tid], s_min[dualTid]);
927 if (tid==0) { gdsr[bid] = s_min[0]; }
930 static Array<double> cuda_reduce_buf;
932 static double cuVectorMin(
const int N,
const double *X)
934 const int tpb = MFEM_CUDA_BLOCKS;
935 const int blockSize = MFEM_CUDA_BLOCKS;
936 const int gridSize = (N+blockSize-1)/blockSize;
937 const int min_sz = (N%tpb)==0? (N/tpb) : (1+N/tpb);
938 cuda_reduce_buf.
SetSize(min_sz);
939 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
941 cuKernelMin<<<gridSize,blockSize>>>(N, d_min, X);
942 MFEM_GPU_CHECK(cudaGetLastError());
945 for (
int i = 0; i < min_sz; i++) { min = fmin(min, h_min[i]); }
949 static __global__
void cuKernelDot(
const int N,
double *gdsr,
950 const double *x,
const double *y)
952 __shared__
double s_dot[MFEM_CUDA_BLOCKS];
953 const int n = blockDim.x*blockIdx.x + threadIdx.x;
954 if (n>=N) {
return; }
955 const int bid = blockIdx.x;
956 const int tid = threadIdx.x;
957 const int bbd = bid*blockDim.x;
958 const int rid = bbd+tid;
959 s_dot[tid] = x[n] * y[n];
960 for (
int workers=blockDim.x>>1; workers>0; workers>>=1)
963 if (tid >= workers) {
continue; }
964 if (rid >= N) {
continue; }
965 const int dualTid = tid + workers;
966 if (dualTid >= N) {
continue; }
967 const int rdd = bbd+dualTid;
968 if (rdd >= N) {
continue; }
969 if (dualTid >= blockDim.x) {
continue; }
970 s_dot[tid] += s_dot[dualTid];
972 if (tid==0) { gdsr[bid] = s_dot[0]; }
975 static double cuVectorDot(
const int N,
const double *X,
const double *Y)
977 const int tpb = MFEM_CUDA_BLOCKS;
978 const int blockSize = MFEM_CUDA_BLOCKS;
979 const int gridSize = (N+blockSize-1)/blockSize;
980 const int dot_sz = (N%tpb)==0? (N/tpb) : (1+N/tpb);
982 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
984 cuKernelDot<<<gridSize,blockSize>>>(N, d_dot, X, Y);
985 MFEM_GPU_CHECK(cudaGetLastError());
988 for (
int i = 0; i < dot_sz; i++) { dot += h_dot[i]; }
991 #endif // MFEM_USE_CUDA
994 static __global__
void hipKernelMin(
const int N,
double *gdsr,
const double *x)
996 __shared__
double s_min[MFEM_HIP_BLOCKS];
997 const int n = hipBlockDim_x*hipBlockIdx_x + hipThreadIdx_x;
998 if (n>=N) {
return; }
999 const int bid = hipBlockIdx_x;
1000 const int tid = hipThreadIdx_x;
1001 const int bbd = bid*hipBlockDim_x;
1002 const int rid = bbd+tid;
1004 for (
int workers=hipBlockDim_x>>1; workers>0; workers>>=1)
1007 if (tid >= workers) {
continue; }
1008 if (rid >= N) {
continue; }
1009 const int dualTid = tid + workers;
1010 if (dualTid >= N) {
continue; }
1011 const int rdd = bbd+dualTid;
1012 if (rdd >= N) {
continue; }
1013 if (dualTid >= hipBlockDim_x) {
continue; }
1014 s_min[tid] = fmin(s_min[tid], s_min[dualTid]);
1016 if (tid==0) { gdsr[bid] = s_min[0]; }
1019 static Array<double> cuda_reduce_buf;
1021 static double hipVectorMin(
const int N,
const double *X)
1023 const int tpb = MFEM_HIP_BLOCKS;
1024 const int blockSize = MFEM_HIP_BLOCKS;
1025 const int gridSize = (N+blockSize-1)/blockSize;
1026 const int min_sz = (N%tpb)==0 ? (N/tpb) : (1+N/tpb);
1027 cuda_reduce_buf.
SetSize(min_sz);
1028 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
1030 hipLaunchKernelGGL(hipKernelMin,gridSize,blockSize,0,0,N,d_min,X);
1031 MFEM_GPU_CHECK(hipGetLastError());
1034 for (
int i = 0; i < min_sz; i++) { min = fmin(min, h_min[i]); }
1038 static __global__
void hipKernelDot(
const int N,
double *gdsr,
1039 const double *x,
const double *y)
1041 __shared__
double s_dot[MFEM_HIP_BLOCKS];
1042 const int n = hipBlockDim_x*hipBlockIdx_x + hipThreadIdx_x;
1043 if (n>=N) {
return; }
1044 const int bid = hipBlockIdx_x;
1045 const int tid = hipThreadIdx_x;
1046 const int bbd = bid*hipBlockDim_x;
1047 const int rid = bbd+tid;
1048 s_dot[tid] = x[n] * y[n];
1049 for (
int workers=hipBlockDim_x>>1; workers>0; workers>>=1)
1052 if (tid >= workers) {
continue; }
1053 if (rid >= N) {
continue; }
1054 const int dualTid = tid + workers;
1055 if (dualTid >= N) {
continue; }
1056 const int rdd = bbd+dualTid;
1057 if (rdd >= N) {
continue; }
1058 if (dualTid >= hipBlockDim_x) {
continue; }
1059 s_dot[tid] += s_dot[dualTid];
1061 if (tid==0) { gdsr[bid] = s_dot[0]; }
1064 static double hipVectorDot(
const int N,
const double *X,
const double *Y)
1066 const int tpb = MFEM_HIP_BLOCKS;
1067 const int blockSize = MFEM_HIP_BLOCKS;
1068 const int gridSize = (N+blockSize-1)/blockSize;
1069 const int dot_sz = (N%tpb)==0 ? (N/tpb) : (1+N/tpb);
1070 cuda_reduce_buf.
SetSize(dot_sz);
1071 Memory<double> &buf = cuda_reduce_buf.
GetMemory();
1073 hipLaunchKernelGGL(hipKernelDot,gridSize,blockSize,0,0,N,d_dot,X,Y);
1074 MFEM_GPU_CHECK(hipGetLastError());
1077 for (
int i = 0; i < dot_sz; i++) { dot += h_dot[i]; }
1080 #endif // MFEM_USE_HIP
1084 MFEM_ASSERT(
size == v.
size,
"incompatible Vectors!");
1085 if (
size == 0) {
return 0.0; }
1088 #if defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP) || defined(MFEM_USE_OPENMP)
1089 auto m_data =
Read(use_dev);
1093 auto v_data = v.
Read(use_dev);
1095 if (!use_dev) {
goto vector_dot_cpu; }
1097 #ifdef MFEM_USE_OCCA
1100 return occa::linalg::dot<double,double,double>(
1105 #ifdef MFEM_USE_CUDA
1108 return cuVectorDot(
size, m_data, v_data);
1115 return hipVectorDot(
size, m_data, v_data);
1119 #ifdef MFEM_USE_OPENMP
1122 #define MFEM_USE_OPENMP_DETERMINISTIC_DOT
1123 #ifdef MFEM_USE_OPENMP_DETERMINISTIC_DOT
1126 #pragma omp parallel
1128 const int nt = omp_get_num_threads();
1131 const int tid = omp_get_thread_num();
1132 const int stride = (
size + nt - 1)/nt;
1133 const int start = tid*stride;
1134 const int stop = std::min(start + stride,
size);
1135 double my_dot = 0.0;
1136 for (
int i = start; i < stop; i++)
1138 my_dot += m_data[i] * v_data[i];
1141 th_dot(tid) = my_dot;
1143 return th_dot.
Sum();
1147 #pragma omp parallel for reduction(+:prod)
1148 for (
int i = 0; i <
size; i++)
1150 prod += m_data[i] * v_data[i];
1153 #endif // MFEM_USE_OPENMP_DETERMINISTIC_DOT
1155 #endif // MFEM_USE_OPENMP
1159 auto v_data = v.
Read();
1160 auto m_data =
Read();
1163 auto d_dot = dot.
Write();
1165 MFEM_FORALL(i, N, d_dot[0] += m_data[i] * v_data[i];);
1178 auto m_data =
Read(use_dev);
1180 if (!use_dev) {
goto vector_min_cpu; }
1182 #ifdef MFEM_USE_OCCA
1189 #ifdef MFEM_USE_CUDA
1192 return cuVectorMin(
size, m_data);
1199 return hipVectorMin(
size, m_data);
1203 #ifdef MFEM_USE_OPENMP
1206 double minimum = m_data[0];
1207 #pragma omp parallel for reduction(min:minimum)
1208 for (
int i = 0; i <
size; i++)
1210 minimum = std::min(minimum, m_data[i]);
1219 auto m_data =
Read();
1224 MFEM_FORALL(i, N, d_min[0] = (d_min[0]<m_data[i])?d_min[0]:m_data[i];);
1230 double minimum =
data[0];
1231 for (
int i = 1; i <
size; i++)
1233 if (m_data[i] < minimum)
1235 minimum = m_data[i];
1242 #ifdef MFEM_USE_SUNDIALS
1246 N_Vector_ID nvid = N_VGetVectorID(nv);
1250 case SUNDIALS_NVEC_SERIAL:
1254 case SUNDIALS_NVEC_PARALLEL:
1259 MFEM_ABORT(
"N_Vector type " << nvid <<
" is not supported");
1265 MFEM_ASSERT(nv,
"N_Vector handle is NULL");
1266 N_Vector_ID nvid = N_VGetVectorID(nv);
1270 case SUNDIALS_NVEC_SERIAL:
1271 MFEM_ASSERT(NV_OWN_DATA_S(nv) == SUNFALSE,
"invalid serial N_Vector");
1272 NV_DATA_S(nv) =
data;
1273 NV_LENGTH_S(nv) =
size;
1276 case SUNDIALS_NVEC_PARALLEL:
1277 MFEM_ASSERT(NV_OWN_DATA_P(nv) == SUNFALSE,
"invalid parallel N_Vector");
1278 NV_DATA_P(nv) =
data;
1279 NV_LOCLENGTH_P(nv) =
size;
1280 if (global_length == 0)
1282 global_length = NV_GLOBLENGTH_P(nv);
1284 if (global_length == 0 && global_length !=
size)
1286 MPI_Comm sundials_comm = NV_COMM_P(nv);
1287 long local_size =
size;
1288 MPI_Allreduce(&local_size, &global_length, 1, MPI_LONG,
1289 MPI_SUM,sundials_comm);
1292 NV_GLOBLENGTH_P(nv) = global_length;
1296 MFEM_ABORT(
"N_Vector type " << nvid <<
" is not supported");
1300 #endif // MFEM_USE_SUNDIALS
Hash function for data sequences.
int Size() const
Return the 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)
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 GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
virtual double * HostWrite()
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), false).
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.
std::string GetHash() const
Return the hash string for the current sequence and reset (clear) the sequence.
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.
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
void add(const Vector &v1, const Vector &v2, Vector &v)
HashFunction & AppendDoubles(const double *doubles, size_t num_doubles)
Add a sequence of doubles for hashing, given as a c-array.
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...
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.
double Normlp(double p) const
Returns the l_p norm of 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...
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
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).
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 elements of the elemvect Vector to the entries listed in dofs. Negative dof values cause the -dof...
virtual const double * HostRead() const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), false).
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.
Vector & operator+=(double c)
double Norml1() const
Returns the l_1 norm of the vector.
double p(const Vector &x, double t)
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 the 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
virtual double * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Vector & Add(const double a, const Vector &Va)
(*this) += a * Va
Host memory; using new[] and delete[].
virtual MFEM_DEPRECATED N_Vector ToNVector()
(DEPRECATED) Return a new wrapper SUNDIALS N_Vector of type SUNDIALS_NVEC_SERIAL. ...
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()
virtual bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
void PrintHash(std::ostream &out) const
Print the Vector size and hash of its data.
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 const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
virtual double * HostReadWrite()
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), false).
[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. As 'DEBUG' is sometimes used as a macro, _DEVICE has been added to avoid conflicts.
void Neg()
(*this) = -(*this)