26 #ifndef TILEDARRAY_ELEMENTAL_H__INCLUDED 27 #define TILEDARRAY_ELEMENTAL_H__INCLUDED 29 #include <TiledArray/config.h> 31 #if TILEDARRAY_HAS_ELEMENTAL 36 # include <elemental.hpp> 40 template<
typename Tile>
41 elem::DistMatrix<typename Tile::value_type> array_to_elem(
const DistArray<Tile> &array,
42 const elem::Grid &grid){
45 "TiledArray::array_to_elem(): The array dimension must be 2.");
48 using T =
typename Tile::value_type;
49 auto sizes = array.trange().elements_range().extent_data();
50 elem::DistMatrix<T> mat(sizes[0], sizes[1], grid);
54 elem::AxpyInterface<T> interface;
56 interface.Attach(elem::LOCAL_TO_GLOBAL, mat);
62 for(; it != end; ++it){
67 const auto* MADNESS_RESTRICT
const tile_lower = tile.
range().lobound_data();
68 const auto* MADNESS_RESTRICT
const tile_extent = tile.range().extent_data();
69 const std::size_t tile_lower_0 = tile_lower[0];
70 const std::size_t tile_lower_1 = tile_lower[1];
71 const std::size_t tile_extent_0 = tile_extent[0];
72 const std::size_t tile_extent_1 = tile_extent[1];
77 Eigen::AutoAlign> eig_row_map =
eigen_map(tile, tile_extent_0, tile_extent_1);
83 elem::Matrix<T> ElemBlock;
84 ElemBlock.Attach(CMatrix.rows(), CMatrix.cols(), CMatrix.data(), CMatrix.rows());
87 interface.Axpy(1.0, ElemBlock, tile_lower_0, tile_lower_1);
94 template<
typename Tile>
95 void elem_to_array(DistArray<Tile> &array, elem::DistMatrix<typename Tile::value_type> &mat){
96 using T =
typename Tile::value_type;
97 TA_USER_ASSERT(array.range().rank()==2u,
"TiledArray::elem_to_array(): requires the array to have dimension 2");
98 TA_USER_ASSERT((array.trange().elements_range().extent()[0]==mat.Height()) &&
99 (array.trange().elements_range().extent()[1] == mat.Width()),
100 "TiledArray::elem_to_array(): requires the shape of the elem matrix and the array to be the same.");
103 elem::AxpyInterface<T> interface;
104 interface.Attach(elem::GLOBAL_TO_LOCAL, mat);
112 for(;it != end; ++it){
117 const auto* MADNESS_RESTRICT
const tile_lower = tile.
range().lobound_data();
118 const auto* MADNESS_RESTRICT
const tile_extent = tile.range().extent_data();
119 const std::size_t tile_lower_0 = tile_lower[0];
120 const std::size_t tile_lower_1 = tile_lower[1];
121 const std::size_t tile_extent_0 = tile_extent[0];
122 const std::size_t tile_extent_1 = tile_extent[1];
125 elem::Matrix<T> ElemBlock;
126 ElemBlock.Attach(tile_extent_0, tile_extent_1, tile.data(), tile_extent_0);
129 std::fill(ElemBlock.Buffer(), ElemBlock.Buffer()+tile_extent_0*tile_extent_1, 0.0);
132 interface.Axpy(1.0, ElemBlock, tile_lower_0, tile_lower_1);
138 for(;it != end; ++it){
143 const auto* MADNESS_RESTRICT
const tile_extent = tile.
range().extent_data();
144 const std::size_t tile_extent_0 = tile_extent[0];
145 const std::size_t tile_extent_1 = tile_extent[1];
150 Eigen::AutoAlign > (tile.data(),tile_extent_0,tile_extent_1);
153 std::copy(row_mat.data(), row_mat.data()+row_mat.size(), tile.data());
159 #elif HAVE_EL_H // end of HAVE_ELEMENTAL_H 163 #pragma clang diagnostic push 164 #pragma clang diagnostic ignored "-Wtautological-compare" 170 #pragma clang diagnostic pop 176 # error "TILEDARRAY_HAS_ELEMENTAL set but neither HAVE_EL_H nor HAVE_ELEMENTAL_H set: file an issue at " TILEDARRAY_PACKAGE_URL 179 #endif // TILEDARRAY_HAS_ELEMENTAL 181 #endif // TILEDARRAY_ELEMENTAL_H__INCLUDED
impl_type::const_iterator const_iterator
Local tile const iterator.
impl_type::value_type value_type
Tile type.
Eigen::Map< const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >, Eigen::AutoAlign > eigen_map(const Tensor< T, A > &tensor, const std::size_t m, const std::size_t n)
Construct a const Eigen::Map object for a given Tensor object.
impl_type::iterator iterator
Local tile iterator.
DistArray< Tile, Policy > copy(const DistArray< Tile, Policy > &a)
decltype(auto) range() const
Range accessor.
#define TA_USER_ASSERT(a, m)