ttg 1.0.0
Template Task Graph (TTG): flowgraph-based programming model for high-performance distributed-memory algorithms
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2#ifndef TTG_WORLD_H
3#define TTG_WORLD_H
4
5#include "ttg/impl_selector.h"
6
7#include <stdexcept>
8#include <algorithm>
9
10#include "ttg/base/world.h"
11#include "ttg/base/keymap.h"
12
13#include "ttg/fwd.h"
14
15namespace ttg {
16
17 /* Slim wrapper to allow for forward declaration */
18 class World : public ttg::base::World<TTG_IMPL_NS::WorldImpl> {
19 using ttg::base::World<TTG_IMPL_NS::WorldImpl>::World;
20 };
21
22 namespace detail {
23 template<typename WorldT>
24 WorldT& default_world_accessor() {
25 static WorldT world;
26 return world;
27 }
28
29 template<typename WorldT>
30 inline void set_default_world(WorldT& world) { detail::default_world_accessor<WorldT>() = world; }
31 template<typename WorldT>
32 inline void set_default_world(WorldT&& world) { detail::default_world_accessor<WorldT>() = std::move(world); }
33
34 template <typename keyT>
35 struct default_keymap : ttg::detail::default_keymap_impl<keyT> {
36 public:
37 default_keymap() = default;
38 default_keymap(const ttg::World& world) : ttg::detail::default_keymap_impl<keyT>(world.size()) {}
39 };
40
41 template <typename keyT>
42 struct default_priomap : ttg::detail::default_priomap_impl<keyT> {
43 public:
44 default_priomap() = default;
45 };
46
47 template<typename WorldImplT>
48 std::list<WorldImplT*>&
49 world_registry_accessor() {
50 static std::list<WorldImplT*> world_registry;
51 return world_registry;
52 }
53
54 /* TODO: how should the MADNESS and PaRSEC init/finalize play together? */
55 template<typename WorldImplT>
56 void register_world(WorldImplT& world)
57 {
58 world_registry_accessor<WorldImplT>().push_back(&world);
59 }
60
61 template<typename WorldImplT>
62 void deregister_world(WorldImplT& world) {
63 auto& world_registry = world_registry_accessor<WorldImplT>();
64 auto it = std::find(world_registry.begin(), world_registry.end(), &world);
65 if (it != world_registry.end()) {
66 world_registry.remove(&world);
67 }
68 }
69
70 template<typename WorldImplT>
71 void destroy_worlds(void) {
72 auto& world_registry = world_registry_accessor<WorldImplT>();
73 while (!world_registry.empty()) {
74 auto it = world_registry.begin();
75 (*it)->destroy();
76 }
77 }
78
79 } // namespace detail
80
82 if (detail::default_world_accessor<ttg::World>().is_valid()) {
83 return detail::default_world_accessor<ttg::World>();
84 } else {
85 throw std::runtime_error("ttg::set_default_world() must be called before use");
86 }
87 }
88
89} // namespace ttg
90
91#endif // TTG_WORLD_H
void deregister_world(ttg::base::WorldImplBase &world)
void register_world(ttg::base::WorldImplBase &world)
void destroy_worlds(void)
top-level TTG namespace contains runtime-neutral functionality
Definition keymap.h:9
int size(World world=default_execution_context())
Definition run.h:131
ttg::World & get_default_world()
Definition world.h:81
the default priority map implementation
Definition keymap.h:43