23 #ifndef TILEDARRAY_CONVERSIONS_BTAS_H__INCLUDED 24 #define TILEDARRAY_CONVERSIONS_BTAS_H__INCLUDED 51 template <
typename T,
typename Range_,
typename Storage_,
typename Allocator_>
55 const auto& src_range = src.range();
56 const auto& dst_range = dst.
range();
75 template <
typename T,
typename Allocator_,
typename Range_,
typename Storage_>
79 const auto& src_range = src.
range();
80 const auto& dst_range = dst.range();
98 template <
typename DistArray_,
typename BTAS_Tensor_>
100 DistArray_* dst,
const typename DistArray_::size_type i, madness::AtomicInt* counter)
102 typename DistArray_::value_type tensor(dst->trange().make_tile_range(i));
115 template <
typename TA_Tensor_,
typename BTAS_Tensor_>
117 BTAS_Tensor_* dst, madness::AtomicInt* counter)
123 template <
bool sparse>
181 template <
typename DistArray_,
187 const btas::Tensor<T, Range, Storage>& src,
bool replicated =
false)
192 "TiledArray::btas_tensor_to_array(): rank of destination trange does not match the rank of source BTAS tensor.");
194 for(std::remove_const_t<decltype(rank)> d=0; d!=rank; ++d) {
196 "TiledArray::btas_tensor_to_array(): source dimension does not match destination dimension.");
199 using Tensor_ = btas::Tensor<T,Range,Storage>;
200 using Policy_ =
typename DistArray_::policy_type;
201 const auto is_sparse = std::is_same<Policy_,TiledArray::SparsePolicy>::value;
206 "An array can be created from a btas::Tensor if the number of World ranks is greater than 1 only when replicated=true.");
209 using Shape_ =
typename DistArray_::shape_type;
210 Shape_ shape = detail::make_shape<is_sparse>(world, trange);
213 DistArray_ array = (replicated && (world.size() > 1)
214 ? DistArray_(world, trange, shape,
215 std::static_pointer_cast<typename DistArray_::pmap_interface>(
216 std::make_shared<detail::ReplicatedPmap>(
218 : DistArray_(world, trange, shape));
221 madness::AtomicInt counter;
224 for(std::size_t i = 0; i < array.size(); ++i) {
225 world.taskq.add(& detail::counted_btas_subtensor_to_tensor<DistArray_, Tensor_>,
226 &src, &array, i, &counter);
231 array.world().await([&counter,n] () {
return counter == n; });
257 template <
typename Tile,
typename Policy>
258 btas::Tensor<typename Tile::value_type>
262 if(! src.
pmap()->is_replicated())
264 "TiledArray::array_to_btas_tensor(): a non-replicated array can only be converted to a btas::Tensor if the number of World ranks is 1.");
267 using result_type = btas::Tensor<typename TiledArray::DistArray<Tile,Policy>::element_type>;
268 using result_range_type =
typename result_type::range_type;
270 result_type result(result_range_type(src.
trange().elements_range().extent()), 0.0);
273 madness::AtomicInt counter;
276 for(std::size_t i = 0; i < src.
size(); ++i) {
278 src.
world().taskq.add(
279 & detail::counted_tensor_to_btas_subtensor<Tile, result_type>,
280 src.
find(i), &result, &counter);
286 src.
world().await([&counter,n] () {
return counter == n; });
293 #endif // TILEDARRAY_CONVERSIONS_BTAS_H__INCLUDED size_array lobound() const
Range lower bound accessor.
auto data(T &t)
Container data pointer accessor.
Future< value_type > find(const Index &i) const
Find local or remote tile.
An N-dimensional tensor object.
void truncate(DistArray< Tile, DensePolicy > &array)
Truncate a dense Array.
const range_type & range() const
Tensor range object accessor.
const trange_type & trange() const
Tiled range accessor.
auto make_shape< false >(World &, const TiledArray::TiledRange &)
KroneckerDeltaTile< _N >::numeric_type max(const KroneckerDeltaTile< _N > &arg)
TensorMap< T > make_map(T *const data, const Index &lower_bound, const Index &upper_bound)
unsigned int rank() const
Rank accessor.
void btas_subtensor_to_tensor(const btas::Tensor< T, Range_, Storage_ > &src, Tensor< T, Allocator_ > &dst)
Copy a block of a btas::Tensor into a TiledArray::Tensor.
auto make_shape< true >(World &world, const TiledArray::TiledRange &trange)
void counted_tensor_to_btas_subtensor(const TA_Tensor_ &src, BTAS_Tensor_ *dst, madness::AtomicInt *counter)
Task function for assigning a tensor to an Eigen submatrix.
auto make_shape(World &world, const TiledArray::TiledRange &trange)
bool is_zero(const Index &i) const
Check for zero tiles.
ordinal_type volume() const
Range volume accessor.
void counted_btas_subtensor_to_tensor(const BTAS_Tensor_ *src, DistArray_ *dst, const typename DistArray_::size_type i, madness::AtomicInt *counter)
Task function for converting btas::Tensor subblock to a TiledArray::DistArray.
const range_type & tiles_range() const
Access the tile range.
TensorConstMap< T > make_const_map(const T *const data, const Index &lower_bound, const Index &upper_bound)
World & world() const
World accessor.
Range data of a tiled array.
void tensor_to_btas_subtensor(const Tensor< T, Allocator_ > &src, btas::Tensor< T, Range_, Storage_ > &dst)
Copy a block of a btas::Tensor into a TiledArray::Tensor.
DistArray_ btas_tensor_to_array(World &world, const TiledArray::TiledRange &trange, const btas::Tensor< T, Range, Storage > &src, bool replicated=false)
Convert a btas::Tensor object into a TiledArray::DistArray object.
Range that references a subblock of another range.
btas::Tensor< typename Tile::value_type > array_to_btas_tensor(const TiledArray::DistArray< Tile, Policy > &src)
Convert a TiledArray::DistArray object into a btas::Tensor object.
const TiledArray::Range & make_ta_range(const TiledArray::Range &range)
#define TA_USER_ASSERT(a, m)
extent_type extent() const
Range extent accessor.
const range_type & elements_range() const
Access the element range.
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.