40#ifndef SRC_MADNESS_MRA_MACROTASKQ_H_
41#define SRC_MADNESS_MRA_MACROTASKQ_H_
79 gaxpy(1.0, x, 1.0,
true);
84 void gaxpy(
const double a,
const T& right,
double b,
const bool fence=
true) {
91 template<
typename Archive>
113template<
typename T=
double>
140 void gaxpy(
const double a,
const T& right,
double b,
const bool fence=
true) {
141 impl->gaxpy(
a,right,
b,fence);
144 template<
typename Archive>
156 return impl->get_local();
164 std::vector<ScalarResult<T>>
v;
217template<
typename>
struct is_tuple : std::false_type { };
221template<
typename tupleT, std::
size_t I>
226 if constexpr(
I >= std::tuple_size_v<tupleT>) {
230 using typeT =
typename std::tuple_element<I, argtupleT>::type;
245 left.
gaxpy(
a, right,
b, fence);
248template <
class Archive,
typename T>
251 bool exists=(ptr) ?
true :
false;
253 if (exists) ar & ptr->id();
258template <
class Archive,
typename T>
270 MADNESS_EXCEPTION(
"ScalarResultImpl: remote operation attempting to use a locally uninitialized object",0);
273 MADNESS_EXCEPTION(
"ScalarResultImpl<T> operation attempting to use an unregistered object",0);
315 if (
name==
"default") {
319 }
else if (
name==
"node_replicated_target") {
323 }
else if (
name==
"small_memory") {
327 }
else if (
name==
"small_memory_owner") {
334 }
else if (
name==
"large_memory") {
339 std::string msg=
"MacroTaskQFactory::preset: unknown preset "+
name;
346 return {
"default",
"node_replicated_target",
"small_memory",
"small_memory_owner",
"large_memory"};
351 std::vector<MacroTaskInfo> result;
382 std::string msg=
"expected 3 policies, got "+std::to_string(
vec.size());
386 std::string result=s;
387 if (s.size()>=2
and s.front()==
'"' and s.back()==
'"') {
388 result=s.substr(1,s.size()-2);
398 std::string msg=
"unknown storage policy: "+
sstorage;
408 std::string msg=
"unknown cloud distribution policy: "+
scloud;
418 std::string msg=
"unknown ptr target distribution policy: "+
sptrtarget;
439 std::ostringstream os;
449 std::string msg=
"unknown policy: "+policy;
465template<
typename T=
double>
477 typedef std::vector<std::shared_ptr<MacroTaskBase> >
taskqT;
511 print(
"nothing to print");
514 std::stringstream
ss;
536template<
typename macrotaskT>
614 std::shared_ptr< WorldDCPmapInterface< Key<1> > >
pmap1;
615 std::shared_ptr< WorldDCPmapInterface< Key<2> > >
pmap2;
616 std::shared_ptr< WorldDCPmapInterface< Key<3> > >
pmap3;
617 std::shared_ptr< WorldDCPmapInterface< Key<4> > >
pmap4;
618 std::shared_ptr< WorldDCPmapInterface< Key<5> > >
pmap5;
619 std::shared_ptr< WorldDCPmapInterface< Key<6> > >
pmap6;
748 [](
const std::shared_ptr<MacroTaskBase>& t) {
return t->get_owner_slot() >= 0; });
762 printf(
"rank %3d (subworld %3lu) finished its task queue at time %6.1fs (own tasktime %4.1fs)\n",
822 and taskq.front()->wants_node_local_reduction();
839 print(
"number of tasks in taskq",
taskq.size());
840 print(
"redirecting output to files task.#####");
876 print(
"all tasks complete");
912 for (
const auto& t :
vtask) {
922 print(
"total number of tasks: ",
taskq.size());
923 print(
" task batch priority status");
924 for (
const auto& t :
taskq) t->print_me_as_table();
937 if (subworld.
rank()==0) {
953 if (it!=
taskq.end()) {
954 it->get()->set_running();
990template<
typename taskT>
1016 template<
typename Q>
1018 decltype(std::declval<Q&>().prepare_owner_assignment(
1019 std::declval<const MacroTaskPartitioner::partitionT&>(), 0
L));
1020 template<
typename Q>
1022 madness::meta::is_detected_v<has_prepare_owner_assignment_t, Q>;
1025 template<
typename Q,
typename ArgTuple>
1027 decltype(std::declval<Q&>().store_batches(
1028 std::declval<World&>(), std::declval<World&>(), std::declval<Cloud&>(),
1029 std::declval<const ArgTuple&>(), 0
L));
1030 template<
typename Q,
typename ArgTuple>
1032 madness::meta::is_detected_v<has_store_batches_t, Q, ArgTuple>;
1035 template<
typename Q,
typename VecT>
1037 decltype(std::declval<Q&>().sym_pipeline_advance(
1038 std::declval<World&>(), std::declval<const VecT&>(),
1039 std::declval<const Batch_1D&>(), std::declval<const Batch_1D&>(),
true));
1040 template<
typename Q,
typename VecT>
1042 madness::meta::is_detected_v<has_sym_pipeline_advance_t, Q, VecT>;
1045 template<
typename Q,
typename ResT>
1047 decltype(std::declval<Q&>().accumulate_locally(
1048 std::declval<World&>(), std::declval<const ResT&>()));
1049 template<
typename Q,
typename ResT>
1051 madness::meta::is_detected_v<has_accumulate_locally_t, Q, ResT>;
1054 template<
typename Q>
1056 decltype(std::declval<const Q&>().wants_node_local_reduction());
1057 template<
typename Q>
1059 madness::meta::is_detected_v<has_wants_node_local_reduction_t, Q>;
1062 template<
typename Q>
1064 decltype(std::declval<Q&>().finalize_stage1(std::declval<World&>(),
1065 std::declval<World*>()));
1066 template<
typename Q>
1068 madness::meta::is_detected_v<has_finalize_stage1_t, Q>;
1071 template<
typename Q,
typename ResT>
1073 decltype(std::declval<Q&>().finalize_stage2(std::declval<World&>(),
1074 std::declval<World*>(),
1075 std::declval<ResT&>()));
1076 template<
typename Q,
typename ResT>
1078 madness::meta::is_detected_v<has_finalize_stage2_t, Q, ResT>;
1110 if (this->taskq_ptr==0) {
1115 if (
debug) this->taskq_ptr->set_printlevel(20);
1119 this->taskq_ptr->cloud.set_replication_policy(this->taskq_ptr->get_policy().cloud_distribution_policy);
1137 template<
typename ... Ts>
1141 static_assert(std::is_same<
decltype(
argtuple),
argtupleT>::value,
"type or number of arguments incorrect");
1144 auto partitioner=
task.partitioner;
1146 partitioner->set_nsubworld(
world.
size());
1151 task.prepare_owner_assignment(partition,
taskq_ptr->get_nsubworld());
1182 "tuple has invalid result type in prepare_output_records");
1187 if (
debug)
print(
"storing pointers to output in cloud");
1191 typedef std::decay_t<
decltype(result)> argT;
1193 outputrecords += cloud.
store(
world, result.get_impl().get());
1197 outputrecords += cloud.
store(
world, result.get_impl());
1201 std::vector<std::shared_ptr<typename argT::value_type::implT>>
v;
1202 for (
const auto& ptr : result)
v.push_back(ptr.get_impl());
1210 return outputrecords;
1216 std::apply([&](
auto &&... args) {
1222 return outputrecords;
1235 if (
task.name==
"unknown_task")
return typeid(
task).
name();
1245 "tuple has invalid result type in prepare_output_records");
1260 std::stringstream
ss;
1262 std::size_t
namesize=std::min(std::size_t(28),
name.size());
1278 template<
typename resultT1, std::
size_t I=0>
1279 typename std::enable_if<is_tuple<resultT1>::value,
void>
::type
1282 using elementT =
typename std::tuple_element<I, resultT>::type;
1291 template<
typename resultT1>
1292 typename std::enable_if<not is_tuple<resultT1>::value,
void>
::type
1297 result_tmp.change_tree_state(operating_state);
1313 std::size_t sz=result.size();
1314 for (
size_t i=0; i<sz; ++i) {
1331 if (
not task.accumulates_own_output())
return;
1336 if (
not task.accumulates_own_output())
return;
1350 if (owner_slot < 0)
return {-1,
nullptr};
1351 for (
long next =
element + 1; next <
long(taskq.size()); ++next) {
1353 auto next_task = std::dynamic_pointer_cast<MacroTaskInternal>(taskq[next]);
1356 return {-1,
nullptr};
1376 if constexpr (std::tuple_size<argtupleT>::value >= 3) {
1377 using ketT = std::decay_t<std::tuple_element_t<2, argtupleT>>;
1379 task.sym_pipeline_advance(subworld, std::get<2>(
argtuple),
1409 typedef std::decay_t<
decltype(
arg)> argT;
1439 task.subworld_ptr=&subworld;
1441 task.cloud_ptr=&cloud;
1450 constexpr std::size_t
bufsize=256;
1453 print(std::string(buffer));
1474 if (
task.accumulates_own_output()) {
1482 }
catch (std::exception&
e) {
1508 template<
typename T, std::
size_t NDIM>
1515 template<
typename T, std::
size_t NDIM>
1517 std::vector<Function<T,NDIM>>
vresult;
1523 template<
typename T>
1528 template<
typename T>
1531 for (
size_t i=0; i<
v_sr_impl.size(); ++i) {
1553 typedef typename elementT::value_type::implT implT;
1559 typedef typename elementT::implT implT;
1565 typedef typename ScalarResultT::implT implT;
1566 typedef std::vector<std::shared_ptr<implT>>
vptrT;
1582 "invalid tuple task result -- must be vectors of functions");
Wrapper around MPI_Comm. Has a shallow copy constructor; use Create(Get_group()) for deep copy.
Definition safempi.h:497
static const int SHARED_SPLIT_TYPE
Definition safempi.h:657
Intracomm Split_type(int Type, int Key=0) const
Definition safempi.h:674
Intracomm Split(int Color, int Key=0) const
Definition safempi.h:642
Definition macrotaskpartitioner.h:55
a batch consists of a 2D-input batch and a 1D-output batch: K-batch <- (I-batch, J-batch)
Definition macrotaskpartitioner.h:124
cloud class
Definition cloud.h:338
void clear()
Definition cloud.h:676
void replicate_per_node(const std::size_t chunk_size=INT_MAX)
Definition cloud.h:859
nlohmann::json get_statistics(World &world) const
return a json object with the cloud settings and statistics
Definition cloud.h:504
recordlistT store(madness::World &world, const T &source)
Definition cloud.h:819
std::atomic< long > target_replication_time
Definition cloud.h:950
nlohmann::json gather_timings(World &universe) const
Definition cloud.h:573
void replicate(const std::size_t chunk_size=INT_MAX)
Definition cloud.h:879
void print_size(World &universe)
Definition cloud.h:478
T load(madness::World &world, const recordlistT recordlist) const
load a single object from the cloud, recordlist is kept unchanged
Definition cloud.h:739
std::list< WorldObjectBase * > world_object_base_list
Definition cloud.h:397
static void print_memory_statistics(const nlohmann::json stats)
Definition cloud.h:642
DistributionType get_replication_policy() const
is the cloud container replicated: per rank, per node, or distributed
Definition cloud.h:453
void clear_cache(World &subworld)
Definition cloud.h:670
std::atomic< long > copy_time
Definition cloud.h:949
void set_replication_policy(const DistributionType value)
is the cloud container replicated: per rank, per node, or distributed
Definition cloud.h:446
void distribute_targets(const DistributionType dt=Distributed)
distribute/node/rank replicate the targets of all world objects stored in the cloud
Definition cloud.h:722
void print_timings(World &universe) const
backwards compatibility
Definition cloud.h:612
void set_storing_policy(const StoragePolicy value)
storing policy refers to storing functions or pointers to functions
Definition cloud.h:469
StoragePolicy
Definition cloud.h:355
@ StoreFunctionPointer
Definition cloud.h:358
@ StoreFunction
Definition cloud.h:356
T consuming_load(madness::World &world, recordlistT &recordlist) const
similar to load, but will consume the recordlist
Definition cloud.h:752
static void set_default_pmap(World &world)
Definition mraimpl.h:3772
static std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > & get_pmap()
Returns the default process map that was last initialized via set_default_pmap()
Definition funcdefaults.h:415
static void set_pmap(const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &value)
Sets the default process map (does not redistribute existing functions)
Definition funcdefaults.h:446
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition funcimpl.h:982
A multiresolution adaptive numerical function.
Definition mra.h:144
void set_impl(const std::shared_ptr< FunctionImpl< T, NDIM > > &impl)
Replace current FunctionImpl with provided new one.
Definition mra.h:731
A future is a possibly yet unevaluated value.
Definition future.h:370
T & get(bool dowork=true) &
Gets the value, waiting if necessary.
Definition future.h:571
base class
Definition macrotaskq.h:474
virtual void finalize_stage1(World &, World *, Cloud &)
Definition macrotaskq.h:504
void set_running()
Definition macrotaskq.h:487
bool is_owned_by(const long slot) const
an unowned task may be run by any subworld, an owned one only by its own
Definition macrotaskq.h:524
virtual ~MacroTaskBase()
Definition macrotaskq.h:480
void set_waiting()
Definition macrotaskq.h:488
MacroTaskBase()
Definition macrotaskq.h:479
virtual void print_me(std::string s="") const
Definition macrotaskq.h:507
std::string print_priority_and_status_to_string() const
Definition macrotaskq.h:513
virtual bool wants_node_local_reduction() const
Finalize, for tasks that accumulate their own output.
Definition macrotaskq.h:503
void set_complete()
Definition macrotaskq.h:486
double priority
Definition macrotaskq.h:482
bool is_complete() const
Definition macrotaskq.h:490
Status
Definition macrotaskq.h:484
@ Complete
Definition macrotaskq.h:484
@ Running
Definition macrotaskq.h:484
@ Unknown
Definition macrotaskq.h:484
@ Waiting
Definition macrotaskq.h:484
void set_owner_slot(const long owner)
Definition macrotaskq.h:522
bool is_running() const
Definition macrotaskq.h:491
long get_owner_slot() const
Definition macrotaskq.h:521
enum madness::MacroTaskBase::Status stat
virtual void finalize_stage2(World &, World *, Cloud &)
Definition macrotaskq.h:505
long owner_slot
the subworld that should run this task; -1 means any
Definition macrotaskq.h:483
double get_priority() const
Definition macrotaskq.h:519
void set_priority(const double p)
Definition macrotaskq.h:520
virtual void print_me_as_table(std::string s="") const
Definition macrotaskq.h:510
virtual void run(World &world, Cloud &cloud, taskqT &taskq, const long element, const bool debug, const MacroTaskInfo policy)=0
std::vector< std::shared_ptr< MacroTaskBase > > taskqT
Definition macrotaskq.h:477
friend std::ostream & operator<<(std::ostream &os, const MacroTaskBase::Status s)
Definition macrotaskq.h:526
bool is_waiting() const
Definition macrotaskq.h:492
Definition macrotaskq.h:1604
Cloud * cloud_ptr
Definition macrotaskq.h:1610
MacroTaskOperationBase()
Definition macrotaskq.h:1613
Batch batch
Definition macrotaskq.h:1606
World * subworld_ptr
Definition macrotaskq.h:1607
virtual bool accumulates_own_output() const
Definition macrotaskq.h:1624
virtual long owner_hint(const Batch &, const long) const
which subworld should run this batch; -1 leaves the choice to the queue
Definition macrotaskq.h:1620
virtual ~MacroTaskOperationBase()
Definition macrotaskq.h:1614
std::shared_ptr< MacroTaskPartitioner > partitioner
Definition macrotaskq.h:1612
virtual bool handles_own_data_movement() const
true if the task moves its operand coefficients into the subworld itself
Definition macrotaskq.h:1627
virtual void cleanup()
release whatever the task kept across its batches, called once the queue has run
Definition macrotaskq.h:1636
std::string name
Definition macrotaskq.h:1611
partition one (two) vectors into 1D (2D) batches.
Definition macrotaskpartitioner.h:182
std::list< std::pair< Batch, double > > partitionT
Definition macrotaskpartitioner.h:186
Factory for the MacroTaskQ.
Definition macrotaskq.h:550
MacroTaskQFactory & set_storage_policy(const MacroTaskInfo::StoragePolicy sp)
Definition macrotaskq.h:579
World & world
Definition macrotaskq.h:553
MacroTaskQFactory & set_policy(const MacroTaskInfo p)
Definition macrotaskq.h:574
MacroTaskQFactory & set_nworld(const long n)
Definition macrotaskq.h:560
MacroTaskQFactory & preset(const std::string name)
Definition macrotaskq.h:570
MacroTaskQFactory & set_cloud_distribution_policy(const DistributionType dp)
Definition macrotaskq.h:584
MacroTaskQFactory & set_printlevel(const long p)
Definition macrotaskq.h:565
long printlevel
Definition macrotaskq.h:552
MacroTaskQFactory & set_ptr_target_distribution_policy(const DistributionType dp)
Definition macrotaskq.h:589
long nworld
Definition macrotaskq.h:554
MacroTaskInfo policy
Definition macrotaskq.h:556
MacroTaskQFactory(World &universe)
Definition macrotaskq.h:558
Definition macrotaskq.h:598
long nsubworld
Definition macrotaskq.h:607
std::mutex taskq_mutex
Definition macrotaskq.h:605
bool printdebug() const
Definition macrotaskq.h:621
static void set_pmap(World &world)
Definition macrotaskq.h:974
bool printtimings_detail() const
Definition macrotaskq.h:624
void run_all()
Definition macrotaskq.h:834
void set_complete(const long task_number) const
scheduler is located on rank==0
Definition macrotaskq.h:963
World & universe
Definition macrotaskq.h:600
std::shared_ptr< WorldDCPmapInterface< Key< 1 > > > pmap1
set the process map for the subworld
Definition macrotaskq.h:614
std::shared_ptr< WorldDCPmapInterface< Key< 3 > > > pmap3
Definition macrotaskq.h:616
MacroTaskBase::taskqT taskq
Definition macrotaskq.h:604
MacroTaskInfo get_policy() const
Definition macrotaskq.h:633
nlohmann::json cloud_statistics
save cloud statistics after run_all()
Definition macrotaskq.h:608
void add_tasks(MacroTaskBase::taskqT &vtask)
Definition macrotaskq.h:911
long get_scheduled_task_number(World &subworld)
scheduler is located on universe.rank==0
Definition macrotaskq.h:935
void set_complete_local(const long task_number) const
scheduler is located on rank==0
Definition macrotaskq.h:968
World & get_subworld()
Definition macrotaskq.h:629
MacroTaskQ(const MacroTaskQFactory factory)
create an empty taskq and initialize the subworlds
Definition macrotaskq.h:646
static std::shared_ptr< World > create_node_world(World &universe)
a World spanning the ranks that share memory with this one
Definition macrotaskq.h:684
void drain_own_output_buffers()
Move the results of tasks that accumulated their own output into the universe result.
Definition macrotaskq.h:803
std::shared_ptr< WorldDCPmapInterface< Key< 4 > > > pmap4
Definition macrotaskq.h:617
nlohmann::json get_taskq_statistics() const
Definition macrotaskq.h:641
std::size_t size() const
Definition macrotaskq.h:983
std::shared_ptr< WorldDCPmapInterface< Key< 5 > > > pmap5
Definition macrotaskq.h:618
std::shared_ptr< World > nodeworld_ptr
node-scoped World for the two-stage finalize; created on first use, reused after
Definition macrotaskq.h:603
void print_taskq() const
Definition macrotaskq.h:918
std::shared_ptr< World > subworld_ptr
Definition macrotaskq.h:601
bool printtimings() const
Definition macrotaskq.h:623
std::shared_ptr< WorldDCPmapInterface< Key< 2 > > > pmap2
Definition macrotaskq.h:615
double execute_tasks()
Run this rank's share of the queue.
Definition macrotaskq.h:737
bool printprogress() const
Definition macrotaskq.h:622
void replicate_inputs()
run all tasks
Definition macrotaskq.h:698
std::shared_ptr< WorldDCPmapInterface< Key< 6 > > > pmap6
Definition macrotaskq.h:619
nlohmann::json get_cloud_statistics() const
Definition macrotaskq.h:637
void set_printlevel(const long p)
Definition macrotaskq.h:631
long printlevel
Definition macrotaskq.h:606
madness::Cloud cloud
Definition macrotaskq.h:628
long get_nsubworld() const
Definition macrotaskq.h:630
void add_replicated_task(const std::shared_ptr< MacroTaskBase > &task)
Definition macrotaskq.h:930
~MacroTaskQ()
Definition macrotaskq.h:664
static std::shared_ptr< World > create_worlds(World &universe, const std::size_t nsubworld)
Definition macrotaskq.h:668
nlohmann::json taskq_statistics
save taskq statistics after run_all()
Definition macrotaskq.h:609
long get_scheduled_task_number_local()
Definition macrotaskq.h:947
const MacroTaskInfo policy
storage and distribution policy
Definition macrotaskq.h:611
Definition macrotaskq.h:1226
void run(World &subworld, Cloud &cloud, MacroTaskBase::taskqT &taskq, const long element, const bool debug, const MacroTaskInfo policy) override
Definition macrotaskq.h:1426
void finalize_stage2(World &subworld, World *nodeworld, Cloud &cloud) override
Definition macrotaskq.h:1335
void finalize_stage1(World &subworld, World *nodeworld, Cloud &) override
Definition macrotaskq.h:1330
taskT task
Definition macrotaskq.h:1233
void prefetch_for_next_task(World &subworld, const argtupleT &argtuple, MacroTaskBase::taskqT &taskq, const long element)
called by the MacroTaskQ when the task is scheduled
Definition macrotaskq.h:1366
void copy_operands_into_subworld(World &subworld, Cloud &cloud, argtupleT &batched_argtuple, const MacroTaskInfo &policy, const bool debug)
Bring the operand coefficients into the subworld, unless the task does that itself.
Definition macrotaskq.h:1386
std::enable_if< notis_tuple< resultT1 >::value, void >::type accumulate_into_final_result(World &subworld, resultT1 &result, const resultT1 &result_tmp, const argtupleT &argtuple)
accumulate the result of the task into the final result living in the universe
Definition macrotaskq.h:1293
resultT get_output(World &subworld, Cloud &cloud) const
return the WorldObjects or the result functions living in the universe
Definition macrotaskq.h:1541
static ScalarResult< T > pointer2WorldObject(const std::shared_ptr< ScalarResultImpl< T > > sr_impl)
Definition macrotaskq.h:1524
decay_tuple< typename taskT::argtupleT > argtupleT
Definition macrotaskq.h:1228
static std::vector< Function< T, NDIM > > pointer2WorldObject(const std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > v_impl)
Definition macrotaskq.h:1516
void cleanup() override
Definition macrotaskq.h:1504
taskT::resultT resultT
Definition macrotaskq.h:1229
recordlistT outputrecords
Definition macrotaskq.h:1231
std::string get_name() const
Definition macrotaskq.h:1234
static Function< T, NDIM > pointer2WorldObject(const std::shared_ptr< FunctionImpl< T, NDIM > > impl)
Definition macrotaskq.h:1509
static std::vector< ScalarResult< T > > pointer2WorldObject(const std::vector< std::shared_ptr< ScalarResultImpl< T > > > v_sr_impl)
Definition macrotaskq.h:1529
void print_me_as_table(std::string s="") const override
Definition macrotaskq.h:1259
bool wants_node_local_reduction() const override
Bridge the framework's virtual finalize to the task's hooks.
Definition macrotaskq.h:1325
void print_me(std::string s="") const override
Definition macrotaskq.h:1255
std::enable_if< is_tuple< resultT1 >::value, void >::type accumulate_into_final_result(World &subworld, resultT1 &final_result, const resultT1 &tmp_result, const argtupleT &argtuple)
accumulate the result of the task into the final result living in the universe
Definition macrotaskq.h:1280
MacroTaskInternal(const taskT &task, const std::pair< Batch, double > &batch_prio, const recordlistT &inputrecords, const recordlistT &outputrecords, const long owner_slot=-1)
Definition macrotaskq.h:1239
std::pair< long, MacroTaskInternal * > find_next_owned_task(const MacroTaskBase::taskqT &taskq, const long element) const
the next task in taskq that this task's subworld also owns, or {-1, nullptr}
Definition macrotaskq.h:1347
recordlistT inputrecords
Definition macrotaskq.h:1230
Definition macrotaskq.h:991
decltype(std::declval< Q & >().sym_pipeline_advance(std::declval< World & >(), std::declval< const VecT & >(), std::declval< const Batch_1D & >(), std::declval< const Batch_1D & >(), true)) has_sym_pipeline_advance_t
true if: task.sym_pipeline_advance(subworld, ket, next_col, next_row, has_next)
Definition macrotaskq.h:1039
MacroTask & set_debug(const bool value)
Definition macrotaskq.h:1123
MacroTask(World &world, taskT &task)
constructor takes the task, but no arguments to the task
Definition macrotaskq.h:1093
MacroTask(World &world, taskT &task, const MacroTaskQFactory factory)
constructor takes task and a taskq factory for customization, immediate execution
Definition macrotaskq.h:1099
taskT::resultT resultT
Definition macrotaskq.h:1080
static constexpr bool has_finalize_stage2_v
Definition macrotaskq.h:1077
std::shared_ptr< MacroTaskQ > taskq_ptr
Definition macrotaskq.h:1088
taskT::argtupleT argtupleT
Definition macrotaskq.h:1081
bool immediate_execution
Definition macrotaskq.h:1086
decltype(std::declval< Q & >().finalize_stage1(std::declval< World & >(), std::declval< World * >())) has_finalize_stage1_t
true if: task.finalize_stage1(subworld, nodeworld)
Definition macrotaskq.h:1065
static constexpr bool has_wants_node_local_reduction_v
Definition macrotaskq.h:1058
static constexpr bool has_finalize_stage1_v
Definition macrotaskq.h:1067
World & world
Definition macrotaskq.h:1087
std::shared_ptr< MacroTaskQ > get_taskq() const
Definition macrotaskq.h:1128
resultT operator()(const Ts &... args)
this mimicks the original call to the task functor, called from the universe
Definition macrotaskq.h:1138
static constexpr bool has_accumulate_locally_v
Definition macrotaskq.h:1050
static constexpr bool has_sym_pipeline_advance_v
Definition macrotaskq.h:1041
decltype(std::declval< Q & >().accumulate_locally(std::declval< World & >(), std::declval< const ResT & >())) has_accumulate_locally_t
true if: task.accumulate_locally(subworld, result_subworld)
Definition macrotaskq.h:1048
bool debug
Definition macrotaskq.h:1085
taskT task
Definition macrotaskq.h:1084
MacroTaskPartitioner::partitionT partitionT
Definition macrotaskq.h:992
decltype(std::declval< Q & >().store_batches(std::declval< World & >(), std::declval< World & >(), std::declval< Cloud & >(), std::declval< const ArgTuple & >(), 0L)) has_store_batches_t
true if: task.store_batches(world, subworld, cloud, argtuple, nsubworld)
Definition macrotaskq.h:1029
decltype(std::declval< Q & >().finalize_stage2(std::declval< World & >(), std::declval< World * >(), std::declval< ResT & >())) has_finalize_stage2_t
true if: task.finalize_stage2(subworld, nodeworld, universe_result)
Definition macrotaskq.h:1075
Cloud::recordlistT recordlistT
Definition macrotaskq.h:1082
static constexpr bool has_store_batches_v
Definition macrotaskq.h:1031
static constexpr bool has_prepare_owner_assignment_v
Definition macrotaskq.h:1021
recordlistT prepare_output_records(Cloud &cloud, resultT &result)
store pointers to the result WorldObject in the cloud and return the recordlist
Definition macrotaskq.h:1179
decltype(std::declval< Q & >().prepare_owner_assignment(std::declval< const MacroTaskPartitioner::partitionT & >(), 0L)) has_prepare_owner_assignment_t
true if: task.prepare_owner_assignment(partition, nsubworld)
Definition macrotaskq.h:1019
MacroTask(World &world, taskT &task, std::shared_ptr< MacroTaskQ > taskq_ptr)
constructor takes the task, and a taskq, execution is not immediate
Definition macrotaskq.h:1105
decltype(std::declval< const Q & >().wants_node_local_reduction()) has_wants_node_local_reduction_t
true if: task.wants_node_local_reduction()
Definition macrotaskq.h:1056
static std::map< MemKey, MemInfo > measure_and_print(World &world)
measure the memory usage of all objects of all worlds
Definition memory_measurement.h:24
helper class for returning the result of a task, which is not a madness Function, but a simple scalar
Definition macrotaskq.h:55
void gaxpy(const double a, const T &right, double b, const bool fence=true)
accumulate, optional fence
Definition macrotaskq.h:84
void serialize(Archive &ar)
Definition macrotaskq.h:92
T get()
after completion of the taskq get the final value
Definition macrotaskq.h:97
ScalarResultImpl< T > & operator=(const T &x)
simple assignment of the scalar value
Definition macrotaskq.h:73
ScalarResultImpl(const ScalarResultImpl &other)=delete
Disable the default copy constructor.
ScalarResultImpl< T > & operator=(const ScalarResultImpl< T > &other)=delete
disable assignment operator
ScalarResultImpl< T > & operator+=(const T &x)
Definition macrotaskq.h:78
~ScalarResultImpl()
Definition macrotaskq.h:69
T value
the scalar value
Definition macrotaskq.h:110
T get_local() const
Definition macrotaskq.h:104
T value_type
Definition macrotaskq.h:57
ScalarResultImpl(World &world)
Definition macrotaskq.h:58
Definition macrotaskq.h:114
void serialize(Archive &ar)
Definition macrotaskq.h:145
ScalarResult(const std::shared_ptr< implT > &impl)
Definition macrotaskq.h:121
void gaxpy(const double a, const T &right, double b, const bool fence=true)
accumulate, optional fence
Definition macrotaskq.h:140
ScalarResultImpl< T > implT
Definition macrotaskq.h:116
T get()
after completion of the taskq get the final value
Definition macrotaskq.h:150
ScalarResult(World &world)
Definition macrotaskq.h:120
std::shared_ptr< implT > impl
Definition macrotaskq.h:117
ScalarResult & operator=(const T &x)
Definition macrotaskq.h:122
std::shared_ptr< implT > get_impl() const
Definition macrotaskq.h:127
void set_impl(const std::shared_ptr< implT > &newimpl)
Definition macrotaskq.h:131
T get_local() const
after completion of the taskq get the final value
Definition macrotaskq.h:155
uniqueidT id() const
Definition macrotaskq.h:135
void broadcast_serializable(objT &obj, ProcessID root)
Broadcast a serializable object.
Definition worldgop.h:774
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:177
bool set_forbid_fence(bool value)
Set forbid_fence flag to new value and return old value.
Definition worldgop.h:677
void sum(T *buf, size_t nelem)
Inplace global sum while still processing AM & tasks.
Definition worldgop.h:890
SafeMPI::Intracomm & comm()
Returns the associated SafeMPI communicator.
Definition worldmpi.h:286
Implements most parts of a globally addressable object (via unique ID).
Definition world_object.h:491
void process_pending()
To be called from derived constructor to process pending messages.
Definition world_object.h:787
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn) const
Definition world_object.h:858
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method returnT (this->*memfn)().
Definition world_object.h:1132
A parallel world class.
Definition world.h:134
static World * world_from_id(std::uint64_t id)
Convert a World ID to a World pointer.
Definition world.h:516
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
WorldMpiInterface & mpi
MPI interface.
Definition world.h:213
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:354
unsigned long id() const
Definition world.h:324
WorldGopInterface & gop
Global operations.
Definition world.h:216
std::optional< T * > ptr_from_id(uniqueidT id) const
Look up a local pointer from a world-wide unique ID.
Definition world.h:440
Class for unique global IDs.
Definition uniqueid.h:53
Declares the Cloud class for storing data and transfering them between worlds.
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
const std::size_t bufsize
Definition derivatives.cc:16
static bool debug
Definition dirac-hatom.cc:16
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:2757
static const double v
Definition hatom_sf_dirac.cc:20
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
#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 DFConvergence.h:9
std::vector< ScalarResult< T > > scalar_result_vector(World &world, std::size_t n)
helper function to create a vector of ScalarResultImpl, circumventing problems with the constructors
Definition macrotaskq.h:163
std::ostream & operator<<(std::ostream &os, const particle< PDIM > &p)
Definition lowrankfunction.h:401
double get_rss_usage_in_GB()
Definition ranks_and_hosts.cpp:18
static double cpu_time()
Returns the cpu time in seconds relative to an arbitrary origin.
Definition timers.h:128
DistributionType
some introspection of how data is distributed
Definition worlddc.h:84
@ NodeReplicated
even if there are several ranks per node
Definition worlddc.h:87
@ Distributed
no replication of the container, the container is distributed over the world
Definition worlddc.h:85
@ RankReplicated
replicate the container over all world ranks
Definition worlddc.h:86
void set_impl(std::vector< Function< T, NDIM > > &v, const std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > vimpl)
Definition vmra.h:739
std::vector< std::shared_ptr< FunctionImpl< T, NDIM > > > get_impl(const std::vector< Function< T, NDIM > > &v)
Definition vmra.h:732
TreeState
Definition funcdefaults.h:60
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:61
@ compressed
d coeffs in internal nodes, s and d coeffs at the root, empty leaves may be present
Definition funcdefaults.h:62
constexpr bool check_tuple_is_valid_task_result()
given a tuple check recursively if all elements are valid task results
Definition macrotaskq.h:222
static const Slice _(0,-1, 1)
static void binary_tuple_loop(tupleT &tuple1, tupleR &tuple2, opT &op)
loop over the tuple elements of both tuples and execute the operation op on each element pair
Definition type_traits.h:742
static void unary_tuple_loop(tupleT &tuple, opT &op)
loop over a tuple and apply unary operator op to each element
Definition type_traits.h:732
@ TT_FULL
Definition gentensor.h:120
NDIM & f
Definition mra.h:2668
constexpr bool is_valid_task_result_v
check if type is a valid task result: it must be a WorldObject and must implement gaxpy
Definition macrotaskq.h:208
const Function< T, NDIM > & change_tree_state(const Function< T, NDIM > &f, const TreeState finalstate, bool fence=true)
change tree state of a function
Definition mra.h:2994
decltype(decay_types(std::declval< T >())) decay_tuple
Definition macrotaskpartitioner.h:22
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
void print(const T &t, Ts &&... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:232
std::string type(const PairType &n)
Definition PNOParameters.h:18
constexpr Vector< T, sizeof...(Ts)+1 > vec(T t, Ts... ts)
Factory function for creating a madness::Vector.
Definition vector.h:750
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
std::string name(const FuncType &type, const int ex=-1)
Definition ccpairfunction.h:28
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2233
void gaxpy(const double a, ScalarResult< T > &left, const double b, const T &right, const bool fence=true)
the result type of a macrotask must implement gaxpy
Definition macrotaskq.h:244
static const double b
Definition nonlinschro.cc:119
static const double a
Definition nonlinschro.cc:118
static const double L
Definition rk.cc:46
Definition macrotaskq.h:280
friend std::string to_string(const MacroTaskInfo::StoragePolicy sp)
Definition macrotaskq.h:438
StoragePolicy
Definition macrotaskq.h:281
@ StoreFunction
store a madness function in the cloud – can have a large memory impact
Definition macrotaskq.h:282
@ StorePointerToFunction
Definition macrotaskq.h:283
@ StoreFunctionViaPointer
coefficients to the subworlds when the task is started. This is the default policy.
Definition macrotaskq.h:286
static std::vector< MacroTaskInfo > get_all_presets()
helper function to return all presets
Definition macrotaskq.h:350
StoragePolicy storage_policy
Definition macrotaskq.h:426
DistributionType ptr_target_distribution_policy
Definition macrotaskq.h:428
static MacroTaskInfo preset(const std::string name)
Definition macrotaskq.h:313
static std::vector< std::string > get_all_preset_names()
Definition macrotaskq.h:345
static Cloud::StoragePolicy to_cloud_storage_policy(MacroTaskInfo::StoragePolicy policy)
given the MacroTask's storage policy return the corresponding Cloud storage policy
Definition macrotaskq.h:298
DistributionType cloud_distribution_policy
Definition macrotaskq.h:427
friend std::ostream & operator<<(std::ostream &os, const MacroTaskInfo policy)
Definition macrotaskq.h:430
bool check_consistency() const
make sure the policies are consistent
Definition macrotaskq.h:359
friend std::ostream & operator<<(std::ostream &os, const StoragePolicy sp)
Definition macrotaskq.h:290
static StoragePolicy policy_to_string(const std::string policy)
Definition macrotaskq.h:444
nlohmann::json to_json() const
Definition macrotaskq.h:454
void from_vector_of_strings(const std::vector< std::string > &vec)
set policy from a vector of strings, assuming the order is storage policy, cloud distribution policy,...
Definition macrotaskq.h:380
Definition macrotaskq.h:995
World & world
Memoized reference to the world to which this object belongs.
Definition world_object.h:348
World & get_world() const
Definition world_object.h:446
Default load of an object via serialize(ar, t).
Definition archive.h:667
Default store of an object via serialize(ar, t).
Definition archive.h:612
static std::string tolower(std::string s)
make lower case
Definition commandlineparser.h:128
class to temporarily redirect output to cout
Definition print.h:305
RAII class to redirect cout to a file or to /dev/null.
Definition print.h:257
Definition type_traits.h:756
Definition macrotaskq.h:193
Definition macrotaskq.h:178
Definition macrotaskq.h:172
Definition macrotaskq.h:199
Definition macrotaskq.h:187
Definition macrotaskq.h:217
static void load(const Archive &ar, std::shared_ptr< ScalarResultImpl< T > > &ptr)
Definition macrotaskq.h:260
static void store(const Archive &ar, const std::shared_ptr< ScalarResultImpl< T > > &ptr)
Definition macrotaskq.h:250
Definition timing_utilities.h:9
static const double_complex I
Definition tdse1d.cc:164
void doit(World &world)
Definition tdse.cc:921
void e()
Definition test_sig.cc:75
Declares the World class for the parallel runtime environment.
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43