8#ifndef OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_EIGEN_HPP_
9#define OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_EIGEN_HPP_
11#include "Vector/map_vector.hpp"
12#include <boost/mpl/int.hpp>
13#include "VCluster/VCluster.hpp"
15#define EIGEN_TRIPLET 1
26 Eigen::Triplet<T,long int> triplet_ei;
32 size_t ptr = (size_t)&triplet_ei.row();
34 return (
long int &)*(
long int *)ptr;
39 size_t ptr = (size_t)&triplet_ei.col();
41 return (
long int &)*(
long int *)ptr;
46 size_t ptr = (size_t)&triplet_ei.value();
48 return (T &)*(T *)ptr;
76template<
typename T,
typename id_t>
89 Eigen::SparseMatrix<T,0,id_t> mat;
108 mat.setFromTriplets(trpl_recv.begin(),trpl_recv.end());
111 mat.setFromTriplets(trpl.begin(),trpl.end());
165 const Eigen::SparseMatrix<T,0,id_t> &
getMat()
const
191 void resize(
size_t row,
size_t col,
size_t l_row,
size_t l_col)
203 return mat.coeffRef(i,j);
213 bool save(
const std::string & file)
const
230 std::ofstream dump (file, std::ios::out | std::ios::binary);
231 if (dump.is_open() ==
false)
245 bool load(
const std::string & file)
247 std::ifstream fs (file, std::ios::in | std::ios::binary | std::ios::ate );
248 if (fs.is_open() ==
false)
252 size_t sz = fs.tellg();
257 std::ifstream input (file, std::ios::in | std::ios::binary );
258 if (input.is_open() ==
false)
289 for (
size_t i = 0 ; i < trpl.
size() ; i++)
291 if (r == (
size_t)trpl.get(i).row() && c == (
size_t)trpl.get(i).col())
292 return trpl.get(i).value();
This class allocate, and destroy CPU memory.
virtual bool allocate(size_t sz)
allocate memory
virtual void * getPointer()
get a readable pointer with the data
virtual size_t size() const
the the size of the allocated memory
Eigen::SparseMatrix< T, 0, id_t > & getMat()
Get the Eigen Matrix object.
T operator()(id_t i, id_t j)
Get the row i and the colum j of the Matrix.
bool save(const std::string &file) const
Save this object into file.
bool load(const std::string &file)
Load this object from file.
triplet< T, EIGEN_BASE > triplet_type
Triplet type.
void collect()
Here we collect the full matrix on master.
void assemble()
Assemble the matrix.
SparseMatrix()
Create an empty Matrix.
const Eigen::SparseMatrix< T, 0, id_t > & getMat() const
Get the Eigen Matrix object.
SparseMatrix(size_t N1, size_t N2)
Create an empty Matrix.
T getValue(size_t r, size_t c)
Get the value from triplet.
openfpm::vector< triplet_type > & getMatrixTriplets()
Get the Matrix triplets bugger.
void resize(size_t row, size_t col, size_t l_row, size_t l_col)
Resize the Sparse Matrix.
boost::mpl::int_< EIGEN_BASE > triplet_impl
Triplet implementation id.
Sparse Matrix implementation.
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
bool SGather(T &send, S &recv, size_t root)
Semantic Gather, gather the data from all processors into one node.
Implementation of 1-D std::vector like structure.
triplet(long int i, long int j, T val)
Constructor from row, colum and value.
It store the non zero elements of the matrix.