1 #ifndef TTG_BASE_WORLD_H
2 #define TTG_BASE_WORLD_H
36 std::function<void(
void*)> make_deleter() {
37 return {[](
void* p) {
delete static_cast<T*
>(p); }};
40 std::list<ttg::TTBase*> m_op_register;
41 std::vector<std::shared_ptr<std::promise<void>>> m_statuses;
42 std::vector<std::function<void()>> m_callbacks;
43 std::vector<std::shared_ptr<void>> m_ptrs;
44 std::vector<std::unique_ptr<void, std::function<void(
void*)>>> m_unique_ptrs;
47 bool m_is_valid =
true;
55 while (!m_op_register.empty()) {
56 (*m_op_register.begin())->release();
86 m_ptrs.emplace_back(
ptr);
91 m_unique_ptrs.emplace_back(
ptr.release(), make_deleter<T>());
95 m_statuses.emplace_back(status_ptr);
98 template <
typename Callback>
100 m_callbacks.emplace_back(callback);
111 for (
auto& status : m_statuses) {
115 for (
auto&& callback : m_callbacks) {
137 m_op_register.push_back(op);
146 m_op_register.remove(op);
162 virtual void dag_on(
const std::string &filename) { }
173 template <
typename WorldImplT>
176 std::shared_ptr<ttg::base::WorldImplBase> m_impl;
181 World(std::shared_ptr<ttg::base::WorldImplBase> world_impl) : m_impl(world_impl) {}
200 return m_impl->size();
206 return m_impl->rank();
211 bool is_valid(
void)
const {
return static_cast<bool>(m_impl); }
218 return *
reinterpret_cast<WorldImplT*
>(m_impl.get());
221 const WorldImplT&
impl(
void)
const {
223 return *
reinterpret_cast<WorldImplT*
>(m_impl.get());
230 void dag_on(
const std::string &filename) { m_impl->dag_on(filename); }
A base class for all template tasks.
World & operator=(World &&other)=default
void dag_on(const std::string &filename)
virtual void final_task()
const WorldImplT & impl(void) const
World(std::shared_ptr< ttg::base::WorldImplBase > world_impl)
World(World &&other)=default
World(const World &other)=default
bool is_valid(void) const
World & operator=(const World &other)=default
Base class for implementation-specific Worlds.
virtual void destroy(void)=0
virtual void final_task()
virtual void dag_on(const std::string &filename)
virtual void fence_impl(void)=0
void register_op(ttg::TTBase *op)
virtual void profile_off()
virtual void profile_on()
void deregister_op(ttg::TTBase *op)
void register_ptr(std::unique_ptr< T > &&ptr)
virtual ~WorldImplBase(void)
WorldImplBase(int size, int rank)
void register_status(const std::shared_ptr< std::promise< void >> &status_ptr)
void register_callback(Callback &&callback)
virtual bool dag_profiling()
bool is_valid(void) const
void register_ptr(const std::shared_ptr< T > &ptr)
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