12#include <kernel/util/math.hpp>
13#include <kernel/util/random.hpp>
14#include <kernel/util/statistics.hpp>
15#include <kernel/util/time_stamp.hpp>
16#include <kernel/util/type_traits.hpp>
17#include <kernel/adjacency/permutation.hpp>
18#include <kernel/lafem/forward.hpp>
19#include <kernel/lafem/container.hpp>
20#include <kernel/lafem/arch/axpy_dense.hpp>
21#include <kernel/lafem/arch/component_invert_dense.hpp>
22#include <kernel/lafem/arch/component_product_dense.hpp>
23#include <kernel/lafem/arch/dot_product_dense.hpp>
24#include <kernel/lafem/arch/max_rel_diff_dense.hpp>
25#include <kernel/lafem/arch/min_max_index_dense.hpp>
26#include <kernel/lafem/arch/min_max_value_dense.hpp>
27#include <kernel/lafem/arch/norm2_dense.hpp>
28#include <kernel/lafem/arch/scale_dense.hpp>
29#include <kernel/lafem/arch/triple_dot_product_dense.hpp>
55 template <
typename DT_,
typename IT_ = Index>
66 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
70 template <
typename DataType2_,
typename IndexType2_>
96 if (size_in ==
Index(0))
134 if (size_in ==
Index(0))
137 this->
_elements.push_back(std::forward<Memory::Arbiter>(data));
155 XASSERTM(size_in + offset_in <= dv_in.
size(),
"Ranged vector part exceeds original vector size!");
157 this->
_elements.push_back(dv_in.
_elements.front().attach(offset_in *
sizeof(DT_), size_in *
sizeof(DT_)));
168 template <
int block_size_>
207 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
210 this->deserialize<DT2_, IT2_>(input);
226 this->
format(rng, min, max);
255 this->
move(std::forward<DenseVector>(other));
270 t.
clone(*
this, clone_mode);
282 template <
typename DT2_,
typename IT2_>
295 template <
typename DT2_,
typename IT2_>
308 template <
typename DT2_,
typename IT2_,
int BS2_>
321 template <
typename VT_>
326 this->
move(std::move(vec));
334 template <
typename VT_>
337 XASSERTM(this->
size_raw() == a.size_raw(),
"Vectors have not the same size!");
339 a.get_values(x.
get_w());
347 template <
typename VT_>
350 XASSERTM(this->
size_raw() == a.size_raw(),
"Vectors have not the same size!");
352 a.set_values(x.
get_r());
362 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
380 template <
typename DT2_ = DT_,
typename IT2_ = IT_>
393 template <
int block_size_>
399 auto vb = result.elements_view_w();
400 const auto vx = this->elements_view_r();
401 for(
Index i(0); i < n; ++i)
416 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
418 bin = std::ifstream::in;
419 std::ifstream file(filename.c_str(), bin);
420 if (! file.is_open())
421 XABORTM(
"Unable to open Vector file " + filename);
440 std::getline(file, line);
441 if (line.find(
"%%MatrixMarket matrix array real general") == String::npos)
443 XABORTM(
"Input-file is not a compatible mtx-vector-file");
447 std::getline(file, line);
449 XABORTM(
"Input-file is empty");
451 String::size_type begin(line.find_first_not_of(
" "));
452 if (line.at(begin) !=
'%')
456 String::size_type begin(line.find_first_not_of(
" "));
457 line.erase(0, begin);
458 String::size_type end(line.find_first_of(
" "));
459 String srows(line, 0, end);
460 rows = (
Index)atol(srows.c_str());
463 begin = line.find_first_not_of(
" ");
464 line.erase(0, begin);
465 end = line.find_first_of(
" ");
466 String scols(line, 0, end);
469 XASSERTM(cols == 1,
"Input-file is no dense-vector-file");
474 DT_* pval = tmp_view.
get_w();
478 std::getline(file, line);
482 String::size_type begin(line.find_first_not_of(
" "));
483 line.erase(0, begin);
484 String::size_type end(line.find_first_of(
" "));
485 String sval(line, 0, end);
486 DT_ tval((DT_)atof(sval.c_str()));
492 this->
move(std::move(tmp));
497 std::vector<DT_> data;
502 std::getline(file, line);
503 if (line.find(
"#", 0) < line.npos)
510 std::string::size_type first_digit(line.find_first_not_of(
" "));
511 line.erase(0, first_digit);
512 std::string::size_type eol(line.length());
513 for (std::string::size_type i(0); i < eol; ++i)
515 n_z_s.append(1, line[i]);
518 DT_ n_z((DT_)atof(n_z_s.c_str()));
529 this->
move(std::move(tmp));
537 this->
template _deserialize<double, std::uint64_t>(
FileMode::fm_dv, file);
541 XABORTM(
"Filemode not supported!");
553 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
555 bin = std::ofstream::out;
557 char* buff =
nullptr;
563 file.open(filename.c_str(), bin);
565 XABORTM(
"Unable to open Matrix file " + filename);
584 file <<
"%%MatrixMarket matrix array real general\n";
585 file << tsize <<
" " << 1 <<
"\n";
588 for (
Index i(0); i < tsize; ++i)
590 file << elem_view(i) <<
"\n";
600 for (
Index i(0); i < tsize; ++i)
602 file << elem_view(i) <<
"\n";
611 this->
template _serialize<double, std::uint64_t>(
FileMode::fm_dv, file);
615 XABORTM(
"Filemode not supported!");
666 return Memory::TypedView<DT_>();
673 return Memory::TypedView<DT_>();
674 return Memory::TypedView<DT_>(this->
_elements.at(0).view(loc, acc));
680 return Memory::TypedView<DT_>();
687 return Memory::TypedView<DT_>();
694 return Memory::TypedView<DT_>();
701 return Memory::TypedView<DT_>();
702 return Memory::TypedView<DT_>(this->
_elements.at(0).view(loc, acc));
712 return "DenseVector";
723 this->_copy_content(x, full);
737 const DT_ alpha = DT_(1))
739 XASSERTM(x.
size() == this->size(),
"Vector size does not match!");
745 FEAT_KERNEL_MARKER_START(
"DV_axpy");
749 FEAT_KERNEL_MARKER_STOP(
"DV_axpy");
753 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
777 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
803 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
814 XASSERTM(x.
size() == this->size(),
"Vector size does not match!");
826 Statistics::add_time_axpy(ts_stop.
elapsed(ts_start));
840 XASSERTM(x.
size() == this->size(),
"Vector size does not match!");
841 XASSERTM(y.
size() == this->size(),
"Vector size does not match!");
851 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
865 XASSERTM(x.
size() == this->size(),
"Vector size does not match!");
875 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
895 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
923 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->
elements_arbiter(), this->
size(),
false,
true);
926 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
942 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->
elements_arbiter(), this->
size(),
true,
true);
945 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
961 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->
elements_arbiter(), this->
size(),
false,
false);
964 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
980 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->
elements_arbiter(), this->
size(),
true,
false);
983 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
996 XASSERTM(x.
size() == this->size(),
"vector size mismatch!");
1004 Statistics::add_time_reduction(ts_stop.
elapsed(ts_start));
1030 XASSERTM(perm.
size() == this->size(),
"Container size does not match permutation size");
1035 perm.
apply(view.get_w());
1047 Index get_values(DT_ *
const pval_set)
const
1061 Index set_values(
const DT_ *
const pval_set)
1079 for (
Index i(0); i < n; ++i)
1081 lhs <<
" " << view[i];
1101 const Index _num_entries;
1106 _num_entries(vector.
size()),
1111 template <
typename LocalVector_,
typename Mapping_>
1112 void operator()(
const LocalVector_ & loc_vec,
const Mapping_ & mapping, DT_ alpha = DT_(1))
1115 for (
int i(0); i < mapping.get_num_local_dofs(); ++i)
1118 Index dof_idx = mapping.get_index(i);
1119 ASSERT(dof_idx < _num_entries);
1122 _data_view[dof_idx] += alpha * loc_vec[i];
1140 const Index _num_entries;
1145 _num_entries(vector.
size()),
1146 _data_view(vector.elements_view_r())
1150 template <
typename LocalVector_,
typename Mapping_>
1151 void operator()(LocalVector_ & loc_vec,
const Mapping_ & mapping, DT_ alpha = DT_(1))
1154 for (
int i(0); i < mapping.get_num_local_dofs(); ++i)
1157 Index dof_idx = mapping.get_index(i);
1158 ASSERT(dof_idx < _num_entries);
1161 loc_vec[i] += alpha * _data_view(dof_idx);
#define ASSERT(expr)
Debug-Assertion macro definition.
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Index size() const
returns the size of the permutation
bool empty() const
Checks whether the permutation is empty.
void apply(Tx_ *x, bool invert=false) const
Applies In-Situ permutation.
void format()
Reset all elements of the container to a given value or zero if missing.
void move(Container &&source)
Assignment move operation.
void clone(const Container &source, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
void assign(const Container< DT2_, IT2_ > &other)
Assignment operation.
std::vector< Memory::Arbiter > _elements
List of pointers to all datatype dependent arrays.
Gather-Axpy operation for DenseVector.
Scatter-Axpy operation for DenseVector.
Blocked Dense data vector class template.
Dense data vector class template.
void scale(const DenseVector &x, const DT_ alpha)
Calculate .
DT_ min_element() const
Retrieve the minimum value of this vector.
DenseVector(Index size_in, Memory::Arbiter &&data)
Constructor.
void write_out(FileMode mode, const String &filename) const
Write out vector to file.
const Memory::Arbiter & elements_arbiter() const
Returns a reference to the element array arbiter.
void convert(const DenseVector< DT2_, IT2_ > &other)
Conversion method.
void component_product(const DenseVector &x, const DenseVector &y)
Calculate .
DenseVectorBlocked< DT_, IT_, block_size_ > inflate_to_blocks()
Expand DenseVector to DenseVectorBlocked.
void copy(const DenseVector &x, bool full=false)
Performs .
void write_out(FileMode mode, std::ostream &file) const
Write out vector to file.
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
DenseVector & operator=(DenseVector &&other)
Assignment move operator.
DataType dot(const DenseVector &x) const
Calculate .
bool empty() const
Checks whether the vector is empty, i.e. if it has size 0.
DataType triple_dot(const DenseVector &x, const DenseVector &y) const
Calculate .
DT_ DataType
Our datatype.
void convert(const VT_ &a)
Conversion method.
void permute(Adjacency::Permutation &perm)
Permute vector according to the given Permutation.
DT_ ValueType
Our value type.
void convert(const DenseVectorBlocked< DT2_, IT2_, BS2_ > &other)
Conversion method.
bool same_layout(const DenseVector &x) const
Checks if the structural layout of this vector matches that of another vector. This excludes comparis...
IT_ IndexType
Our indextype.
std::vector< char > serialize(const LAFEM::SerialConfig &config=LAFEM::SerialConfig()) const
Serialization of complete container entity.
DenseVector(FileMode mode, std::istream &file)
Constructor.
DT_ norm2sqr() const
Calculates and returns the squared euclid norm of this vector.
void copy_to(VT_ &a) const
Performs .
DenseVector(DenseVector &&other)
Move Constructor.
DenseVector(Index size_in, DT_ value)
Constructor.
DT_ max_rel_diff(const DenseVector &x) const
Retrieve the maximum relative difference of this vector and another one y.max_rel_diff(x) returns .
DenseVector(Random &rng, Index size_in, DataType min, DataType max)
Constructor.
DenseVector(Index size_in)
Constructor.
void read_from(FileMode mode, const String &filename)
Read in vector from file.
DenseVector()=default
Constructor.
void component_invert(const DenseVector &x, const DT_ alpha=DT_(1))
Performs .
void axpy(const DenseVector &x, const DT_ alpha=DT_(1))
Calculate .
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
static String name()
Returns a descriptive string.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this vector.
virtual ~DenseVector()=default
Destructor.
DT_ max_element() const
Retrieve the maximum value of this vector.
void copy(const VT_ &a)
Performs .
DenseVector(const DenseVectorBlocked< DT_, IT_, block_size_ > &other)
Constructor.
DenseVector clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
DenseVector(FileMode mode, String filename)
Constructor.
DenseVector(std::vector< char > input)
Constructor.
DT_ norm2() const
Calculates and returns the euclid norm of this vector.
DT_ max_abs_element() const
Retrieve the absolute maximum value of this vector.
friend std::ostream & operator<<(std::ostream &lhs, const DenseVector &b)
DenseVector streaming operator.
Index size_raw() const
Returns the size of this vector in scalar data type entries.
void clone(const DenseVector< DT2_, IT2_ > &other, CloneMode clone_mode=CloneMode::Deep)
Clone operation.
DenseVector(const DenseVector &dv_in, Index size_in, Index offset_in)
Constructor.
void read_from(FileMode mode, std::istream &file)
Read in vector from stream.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Config class for serialize parameter.
void convert_from(const T_ *ptr_src)
overload of convert_from for the identical type
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
void release() const
Releases this view.
Pseudo-Random Number Generator.
static void add_flops(Index flops)
Add an amount of flops to the global flop counter.
String class implementation.
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
constexpr std::size_t file_out_stream_buffer_size
OutStreamBufferSize.
T_ sqr(T_ x)
Returns the square of a value.
Access
Memory access enumeration.
@ read_write
read-write access
@ overlap
explicitly allow overlapping writes (see Overlapping Memory Views)
@ write
write-only access (see attention note above)
Location
Memory location enumeration.
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.