28 #ifndef MPQC_CHEMISTRY_QC_BASIS_TASKINTEGRALS_HPP_
29 #define MPQC_CHEMISTRY_QC_BASIS_TASKINTEGRALS_HPP_
31 #include <tiledarray.h>
33 #include <chemistry/qc/basis/tiledbasisset.hpp>
34 #include <mpqc/integrals/integrals.hpp>
35 #include <chemistry/qc/basis/integral.h>
43 using PoolPtrType =
typename std::pointer_traits<T>::element_type;
47 template<
typename IntegralEngine>
48 struct EngineTypeTraits;
49 template<>
struct EngineTypeTraits<
sc::Ref<sc::TwoBodyInt> > {
50 static const size_t ncenters = 4u;
52 template<>
struct EngineTypeTraits<
sc::Ref<sc::TwoBodyThreeCenterInt> > {
53 static const size_t ncenters = 3u;
55 template<>
struct EngineTypeTraits<
sc::Ref<sc::TwoBodyTwoCenterInt> > {
56 static const size_t ncenters = 2u;
58 template<>
struct EngineTypeTraits<
sc::Ref<sc::OneBodyInt> > {
59 static const size_t ncenters = 2u;
61 template<>
struct EngineTypeTraits<
sc::Ref<sc::OneBodyOneCenterInt> > {
62 static const size_t ncenters = 1u;
68 namespace int_details {
72 template<
typename RefEngine>
73 void get_integrals(
const std::vector<shell_range> &s, RefEngine &engine,
74 TensorRef<double, 2, TensorRowMajor> &tile_map) {
78 template<
typename RefEngine>
79 void get_integrals(
const std::vector<shell_range> &s, RefEngine &engine,
80 TensorRef<double, 3, TensorRowMajor> &tile_map) {
84 template<
typename RefEngine>
85 void get_integrals(
const std::vector<shell_range> &s, RefEngine &engine,
86 TensorRef<double, 4, TensorRowMajor> &tile_map) {
95 template<
typename Tile,
typename RefEngine>
96 void get_integrals(Tile &tile, RefEngine &engine) {
99 constexpr std::size_t rank = EngineTypeTraits<RefEngine>::ncenters;
102 std::vector<shell_range> ranges(rank);
105 for (std::size_t i = 0; i < rank; ++i) {
109 const std::size_t first_func = tile.range().lobound()[i];
110 const std::size_t last_func = tile.range().upbound()[i] - 1;
113 const std::size_t first_shell = engine->basis(i)->function_to_shell(
115 const std::size_t last_shell = engine->basis(i)->function_to_shell(
119 for (
auto j = first_shell; j < last_shell + 1; ++j) {
120 ranges[i].push_back(j);
125 const std::size_t (&dim)[rank] =
126 *reinterpret_cast<const std::size_t (*)[rank]>(tile.range().extent_data());
128 TensorRef<double, rank, TensorRowMajor> tile_map(tile.data(), dim);
130 int_details::get_integrals(ranges, engine, tile_map);
134 template<
typename ShrPtrPool,
typename It,
class A>
135 void make_integral_task(It first, It last,
const A &array, ShrPtrPool pool);
141 template<
typename ShrPtrPool,
typename It,
class A>
142 void integral_task(It first, It last, A &array, ShrPtrPool &pool) {
148 while (last - first > 10) {
150 std::advance(middle, std::distance(first, last) / 2);
151 make_integral_task(middle, last, array, pool);
157 typename PoolPtrType<ShrPtrPool>::engine_type engine = pool->instance();
161 for (; first != last; ++first) {
162 typename A::value_type tile(array.trange().make_tile_range(*first));
163 get_integrals(tile, engine);
165 array.set(*first, tile);
172 template<
typename ShrPtrPool,
typename It,
class A>
173 void make_integral_task(It first, It last,
const A &array, ShrPtrPool pool){
174 array.world().taskq.add(&integral_task<ShrPtrPool, It, A>, first, last,
184 template<
typename ShrPtrPool,
class A>
188 auto begin = array.pmap()->begin();
189 auto end = array.pmap()->end();
194 make_integral_task(begin, end, array, pool);
200 template<
typename ShrPtrPool>
201 ::TiledArray::Array<double,
202 EngineTypeTraits<typename PoolPtrType<ShrPtrPool>::engine_type>::ncenters >
204 madness::World &world,
const ShrPtrPool &pool,
207 namespace TA = ::TiledArray;
210 typedef typename PoolPtrType<ShrPtrPool>::engine_type engine_type;
212 constexpr
size_t rank = EngineTypeTraits<engine_type>::ncenters;
216 std::array<TiledArray::TiledRange1, rank> blocking;
217 for (
auto i = 0; i < rank; ++i) {
218 blocking[i] = tbasis->
trange1();
222 TA::TiledRange trange(blocking.begin(), blocking.end());
225 TA::Array<double, rank> array(world, trange);
234 template<
typename ShrPtrPool>
235 ::TiledArray::Array<double,
236 EngineTypeTraits<typename PoolPtrType<ShrPtrPool>::engine_type>::ncenters >
237 Integrals( madness::World &world,
const ShrPtrPool &pool,
241 namespace TA = ::TiledArray;
244 typedef typename PoolPtrType<ShrPtrPool>::engine_type engine_type;
246 constexpr
size_t rank = EngineTypeTraits<engine_type>::ncenters;
250 std::array<TiledArray::TiledRange1, rank> blocking;
251 for (
auto i = 0; i < (rank - 1); ++i) {
252 blocking[i] = tbasis->
trange1();
254 blocking.back() = dftbasis->
trange1();
257 TA::TiledRange trange(blocking.begin(), blocking.end());
260 TA::Array<double, rank> array(world, trange);