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 if (not (v_batch.size()==
size_t(this->size()) or this->is_full_size())) {
109 print(
"error in insert_batch");
112 print(
"v.size()",
v.size());
113 print(
"v_batch.size()",v_batch.size());
116 std::copy(v_batch.begin(), v_batch.end(),
v.begin()+
begin);
121 template<
typename vecT>
124 long end1 = (
end > 0) ?
end :
v.end() -
v.begin();
125 std::copy(
v.begin() +
begin,
v.begin() + end1, std::back_inserter(result_batch));
130 std::stringstream ss;
132 else ss <<
"[" << std::setw(3) << batch.
begin <<
", " << std::setw(3) << batch.
end <<
")";
150 if (
this==&other)
return *
this;
167 template<
typename tupleT>
170 tupleT arg1=
input[0].template copy_batch<tupleT,0>(
arg);
171 if (
input.size()>1) arg1=
input[1].template copy_batch<tupleT,1>(arg1);
177 template<
typename vecT>
179 return result.template insert_batch(
v,v_batch);
184 std::stringstream ss;
185 ss << batch.
result<<
" <-- ";
186 if (batch.
input.size()>0) ss << batch.
input[0];
187 if (batch.
input.size()>1) ss <<
", " << batch.
input[1];
234 template<
typename tupleT>
237 constexpr std::size_t I1 = get_index_of_first_vector_argument<tupleT, 0>();
238 constexpr std::size_t I2 = get_index_of_second_vector_argument<tupleT, 1>();
239 std::size_t vsize1=1,vsize2=1;
240 if constexpr (I2 < std::tuple_size_v<tupleT>) {
241 constexpr std::size_t I2 = get_index_of_second_vector_argument<tupleT, 0>();
242 vsize2 = std::get<I2>(argtuple).size();
244 if constexpr (I1 < std::tuple_size_v<tupleT>) {
245 constexpr std::size_t I1 = get_index_of_first_vector_argument<tupleT, 0>();
246 vsize1 = std::get<I1>(argtuple).size();
248 std::string msg=
"confused partitioning dimension: "+std::to_string(
dimension) +
" typeid " +
typeid(tupleT).
name();
257 const std::string
policy)
const {
271 while (end <
long(vsize)) {
273 end = std::min(end,
long(vsize));
276 result.push_back(std::make_pair(batch,priority));
280 std::string msg =
"unknown partitioning policy: " +
policy;
293 for (
auto p1 : partition1) {
294 for (
auto p2 : partition2) {
295 Batch batch(p1.first.input[0],p2.first.input[0],p1.first.result);
297 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:129
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:122
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:139
friend std::ostream & operator<<(std::ostream &os, const Batch &batch)
pretty print this batch
Definition macrotaskpartitioner.h:183
Batch(Batch_1D input1, Batch_1D input2, Batch_1D result)
Definition macrotaskpartitioner.h:157
Batch_1D result
Definition macrotaskpartitioner.h:143
vecT insert_result_batch(vecT v, const vecT &v_batch) const
copy v_batch into the result vector
Definition macrotaskpartitioner.h:178
Batch()
Definition macrotaskpartitioner.h:145
Batch(Batch_1D input1, Batch_1D result)
Definition macrotaskpartitioner.h:156
tupleT copy_input_batch(const tupleT &arg) const
select the relevant vector elements from the argument tuple
Definition macrotaskpartitioner.h:168
Batch(const Batch &other)
Definition macrotaskpartitioner.h:146
Batch & operator=(const Batch &other)
Definition macrotaskpartitioner.h:149
std::size_t size_of_input() const
Definition macrotaskpartitioner.h:160
std::vector< Batch_1D > input
Definition macrotaskpartitioner.h:142
partition one (two) vectors into 1D (2D) batches.
Definition macrotaskpartitioner.h:197
std::string policy
how to partition the batches
Definition macrotaskpartitioner.h:205
MacroTaskPartitioner & set_min_batch_size(const long &n)
Definition macrotaskpartitioner.h:224
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:256
std::size_t nsubworld
number of worlds (try to have enough batches for all worlds)
Definition macrotaskpartitioner.h:204
std::list< std::pair< Batch, double > > partitionT
Definition macrotaskpartitioner.h:201
MacroTaskPartitioner & set_policy(const std::string &n)
Definition macrotaskpartitioner.h:216
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:235
MacroTaskPartitioner & set_dimension(const std::size_t &n)
Definition macrotaskpartitioner.h:220
virtual ~MacroTaskPartitioner()
Definition macrotaskpartitioner.h:210
MacroTaskPartitioner & set_max_batch_size(const long &n)
Definition macrotaskpartitioner.h:228
std::size_t dimension
partition one or two vectors
Definition macrotaskpartitioner.h:206
MacroTaskPartitioner & set_nsubworld(const long &n)
Definition macrotaskpartitioner.h:212
MacroTaskPartitioner()
Definition macrotaskpartitioner.h:208
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:289
partitionT do_1d_partition(const std::size_t vsize, const std::string policy) const
Definition macrotaskpartitioner.h:266
virtual double compute_priority(const Batch &batch) const
Definition macrotaskpartitioner.h:303
std::size_t min_batch_size
minimum batch size
Definition macrotaskpartitioner.h:202
std::size_t max_batch_size
maximum batch size (for memory management)
Definition macrotaskpartitioner.h:203
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
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
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
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:225
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