5#ifndef MADNESS_MACROTASKPARTITIONER_H
6#define MADNESS_MACROTASKPARTITIONER_H
17template<
typename ... Ts>
19-> std::tuple<std::remove_cv_t<std::remove_reference_t<Ts>>...>;
28template<
typename T, std::
size_t NDIM>
32template<
typename Q>
struct is_vector : std::false_type { };
33template<
typename Q>
struct is_vector<
std::vector<Q>> : std::true_type { };
36template<
typename tupleT, std::
size_t I>
39 typedef decay_tuple <tupleT> argtupleT;
41 if constexpr(
I >= std::tuple_size_v<tupleT>) {
46 using typeT =
typename std::tuple_element<I, argtupleT>::type;
51 return get_index_of_first_vector_argument<tupleT,I+1>();
57template<
typename tupleT, std::
size_t I>
59 constexpr std::size_t index0=get_index_of_first_vector_argument<tupleT,0>();
60 return get_index_of_first_vector_argument<tupleT,index0+1>();
88 template<
typename tupleT, std::
size_t appearance>
91 constexpr std::size_t index = (appearance==0) ? get_index_of_first_vector_argument<tupleT,0>() :
92 get_index_of_second_vector_argument<tupleT,0>();
93 if constexpr (index>=std::tuple_size<tupleT>::value) {
97 auto v = std::get<index>(
arg);
99 tupleT batched_arg =
arg;
100 std::get<index>(batched_arg) = v_batch;
106 template<
typename vecT>
108 MADNESS_CHECK(v_batch.size()==
size_t(this->size()) or this->is_full_size());
109 std::copy(v_batch.begin(), v_batch.end(),
v.begin()+
begin);
114 template<
typename vecT>
117 long end1 = (
end > 0) ?
end :
v.end() -
v.begin();
118 std::copy(
v.begin() +
begin,
v.begin() + end1, std::back_inserter(result_batch));
123 std::stringstream ss;
125 else ss <<
"[" << std::setw(3) << batch.
begin <<
", " << std::setw(3) << batch.
end <<
")";
143 if (
this==&other)
return *
this;
160 template<
typename tupleT>
163 tupleT arg1=
input[0].template copy_batch<tupleT,0>(
arg);
164 if (
input.size()>1) arg1=
input[1].template copy_batch<tupleT,1>(arg1);
170 template<
typename vecT>
172 return result.template insert_batch(
v,v_batch);
177 std::stringstream ss;
178 ss << batch.
result<<
" <-- ";
179 if (batch.
input.size()>0) ss << batch.
input[0];
180 if (batch.
input.size()>1) ss <<
", " << batch.
input[1];
227 template<
typename tupleT>
230 constexpr std::size_t I1 = get_index_of_first_vector_argument<tupleT, 0>();
231 constexpr std::size_t I2 = get_index_of_second_vector_argument<tupleT, 1>();
232 std::size_t vsize1=1,vsize2=1;
233 if constexpr (I2 < std::tuple_size_v<tupleT>) {
234 constexpr std::size_t I2 = get_index_of_second_vector_argument<tupleT, 0>();
235 vsize2 = std::get<I2>(argtuple).size();
237 if constexpr (I1 < std::tuple_size_v<tupleT>) {
238 constexpr std::size_t I1 = get_index_of_first_vector_argument<tupleT, 0>();
239 vsize1 = std::get<I1>(argtuple).size();
241 std::string msg=
"confused partitioning dimension: "+std::to_string(
dimension) +
" typeid " +
typeid(tupleT).
name();
250 const std::string
policy)
const {
264 while (end <
long(vsize)) {
266 end = std::min(end,
long(vsize));
269 result.push_back(std::make_pair(batch,priority));
273 std::string msg =
"unknown partitioning policy: " +
policy;
286 for (
auto p1 : partition1) {
287 for (
auto p2 : partition2) {
288 Batch batch(p1.first.input[0],p2.first.input[0],p1.first.result);
290 result.push_back(std::make_pair(batch,priority));
Definition macrotaskpartitioner.h:63
friend std::ostream & operator<<(std::ostream &os, const Batch_1D &batch)
Definition macrotaskpartitioner.h:122
Batch_1D(const long &begin, const long &end)
Definition macrotaskpartitioner.h:73
bool is_full_size() const
Definition macrotaskpartitioner.h:83
tupleT copy_batch(const tupleT &arg) const
select the relevant vector elements from the argument tuple
Definition macrotaskpartitioner.h:89
long size() const
Definition macrotaskpartitioner.h:79
vecT copy_batch(const vecT v) const
given vector v, return those vector elements inside this batch
Definition macrotaskpartitioner.h:115
long end
first and first past last index [begin,end)
Definition macrotaskpartitioner.h:67
Batch_1D(const Slice &s)
Definition macrotaskpartitioner.h:70
vecT insert_batch(vecT v, const vecT &v_batch) const
given vector v, copy vector elements of v_batch into vector
Definition macrotaskpartitioner.h:107
Batch_1D()
Definition macrotaskpartitioner.h:69
long begin
Definition macrotaskpartitioner.h:67
bool operator==(const Batch_1D &other) const
Definition macrotaskpartitioner.h:75
a batch consists of a 2D-input batch and a 1D-output batch: K-batch <- (I-batch, J-batch)
Definition macrotaskpartitioner.h:132
friend std::ostream & operator<<(std::ostream &os, const Batch &batch)
pretty print this batch
Definition macrotaskpartitioner.h:176
Batch(Batch_1D input1, Batch_1D input2, Batch_1D result)
Definition macrotaskpartitioner.h:150
Batch_1D result
Definition macrotaskpartitioner.h:136
vecT insert_result_batch(vecT v, const vecT &v_batch) const
copy v_batch into the result vector
Definition macrotaskpartitioner.h:171
Batch()
Definition macrotaskpartitioner.h:138
Batch(Batch_1D input1, Batch_1D result)
Definition macrotaskpartitioner.h:149
tupleT copy_input_batch(const tupleT &arg) const
select the relevant vector elements from the argument tuple
Definition macrotaskpartitioner.h:161
Batch(const Batch &other)
Definition macrotaskpartitioner.h:139
Batch & operator=(const Batch &other)
Definition macrotaskpartitioner.h:142
std::size_t size_of_input() const
Definition macrotaskpartitioner.h:153
std::vector< Batch_1D > input
Definition macrotaskpartitioner.h:135
partition one (two) vectors into 1D (2D) batches.
Definition macrotaskpartitioner.h:190
std::string policy
how to partition the batches
Definition macrotaskpartitioner.h:198
MacroTaskPartitioner & set_min_batch_size(const long &n)
Definition macrotaskpartitioner.h:217
virtual partitionT do_partitioning(const std::size_t &vsize1, const std::size_t &vsize2, const std::string policy) const
override this if you want your own partitioning
Definition macrotaskpartitioner.h:249
std::size_t nsubworld
number of worlds (try to have enough batches for all worlds)
Definition macrotaskpartitioner.h:197
std::list< std::pair< Batch, double > > partitionT
Definition macrotaskpartitioner.h:194
MacroTaskPartitioner & set_policy(const std::string &n)
Definition macrotaskpartitioner.h:209
partitionT partition_tasks(const tupleT &argtuple) const
this will be called by MacroTask, it will always partition first (and possibly second) vector of argu...
Definition macrotaskpartitioner.h:228
MacroTaskPartitioner & set_dimension(const std::size_t &n)
Definition macrotaskpartitioner.h:213
virtual ~MacroTaskPartitioner()
Definition macrotaskpartitioner.h:203
MacroTaskPartitioner & set_max_batch_size(const long &n)
Definition macrotaskpartitioner.h:221
std::size_t dimension
partition one or two vectors
Definition macrotaskpartitioner.h:199
MacroTaskPartitioner & set_nsubworld(const long &n)
Definition macrotaskpartitioner.h:205
MacroTaskPartitioner()
Definition macrotaskpartitioner.h:201
partitionT do_2d_partition(const std::size_t vsize, const std::size_t v2size, const std::string policy) const
outer product of 2 1d-partitionings – result batches correspond to first input batches
Definition macrotaskpartitioner.h:282
partitionT do_1d_partition(const std::size_t vsize, const std::string policy) const
Definition macrotaskpartitioner.h:259
virtual double compute_priority(const Batch &batch) const
Definition macrotaskpartitioner.h:296
std::size_t min_batch_size
minimum batch size
Definition macrotaskpartitioner.h:195
std::size_t max_batch_size
maximum batch size (for memory management)
Definition macrotaskpartitioner.h:196
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition tensor.h:2502
static const double v
Definition hatom_sf_dirac.cc:20
Defines madness::MadnessException for exception handling.
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
constexpr auto decay_types(std::tuple< Ts... > const &) -> std::tuple< std::remove_cv_t< std::remove_reference_t< Ts > >... >
constexpr std::size_t get_index_of_first_vector_argument()
given a tuple return the index of the first argument that is a vector of Function<T,...
Definition macrotaskpartitioner.h:37
decltype(decay_types(std::declval< T >())) decay_tuple
Definition macrotaskpartitioner.h:22
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
constexpr std::size_t get_index_of_second_vector_argument()
given a tuple return the index of the second argument that is a vector of Function<T,...
Definition macrotaskpartitioner.h:58
Definition macrotaskpartitioner.h:25
Definition macrotaskpartitioner.h:32
static const double_complex I
Definition tdse1d.cc:164