Commit 3ef5521e authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added the possibility to create anonymous threads and tasks

parent 7d19ec4f
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <margo.h> #include <margo.h>
#include <thallium/abt.hpp> #include <thallium/abt.hpp>
#include <thallium/anonymous.hpp>
#include <thallium/bulk_mode.hpp> #include <thallium/bulk_mode.hpp>
#include <thallium/bulk.hpp> #include <thallium/bulk.hpp>
#include <thallium/engine.hpp> #include <thallium/engine.hpp>
......
/*
* Copyright (c) 2017 UChicago Argonne, LLC
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __THALLIUM_ANONYMOUS_HPP
#define __THALLIUM_ANONYMOUS_HPP
namespace thallium {
struct anonymous {};
}
#endif
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <abt.h> #include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/task.hpp> #include <thallium/task.hpp>
#include <thallium/thread.hpp> #include <thallium/thread.hpp>
#include <thallium/managed.hpp> #include <thallium/managed.hpp>
...@@ -438,6 +439,12 @@ class pool { ...@@ -438,6 +439,12 @@ class pool {
return task::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp)); return task::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp));
} }
template<typename F>
void make_task(F&& f, const anonymous& a) {
auto fp = new std::function<void(void)>(std::forward<F>(f));
return task::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp), a);
}
/** /**
* @brief Create a thread running the specified function and push it * @brief Create a thread running the specified function and push it
* into the pool. * into the pool.
...@@ -453,6 +460,12 @@ class pool { ...@@ -453,6 +460,12 @@ class pool {
return thread::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp)); return thread::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp));
} }
template<typename F>
void make_thread(F&& f, const anonymous& a) {
auto fp = new std::function<void(void)>(std::forward<F>(f));
return thread::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp), a);
}
/** /**
* @brief Create a thread running the specified function and push it * @brief Create a thread running the specified function and push it
* into the pool. * into the pool.
...@@ -468,6 +481,12 @@ class pool { ...@@ -468,6 +481,12 @@ class pool {
auto fp = new std::function<void(void)>(std::forward<F>(f)); auto fp = new std::function<void(void)>(std::forward<F>(f));
return thread::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp), attr); return thread::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp), attr);
} }
template<typename F>
managed<thread> make_thread(F&& f, const thread::attribute& attr, const anonymous& a) {
auto fp = new std::function<void(void)>(std::forward<F>(f));
return thread::create_on_pool(m_pool, forward_work_unit, static_cast<void*>(fp), attr, a);
}
}; };
template<typename P, typename U, typename Palloc, typename Ualloc> template<typename P, typename U, typename Palloc, typename Ualloc>
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <cstdint> #include <cstdint>
#include <abt.h> #include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/managed.hpp> #include <thallium/managed.hpp>
#include <thallium/exception.hpp> #include <thallium/exception.hpp>
#include <thallium/abt_errors.hpp> #include <thallium/abt_errors.hpp>
...@@ -75,12 +76,20 @@ class task { ...@@ -75,12 +76,20 @@ class task {
return managed<task>(t); return managed<task>(t);
} }
static void create_on_xstream(ABT_xstream es, void(*f)(void*), void* arg, const anonymous&) {
TL_TASK_ASSERT(ABT_task_create_on_xstream(es, f, arg, NULL));
}
static managed<task> create_on_pool(ABT_pool p, void(*f)(void*), void* arg) { static managed<task> create_on_pool(ABT_pool p, void(*f)(void*), void* arg) {
ABT_task t; ABT_task t;
TL_TASK_ASSERT(ABT_task_create(p, f, arg, &t)); TL_TASK_ASSERT(ABT_task_create(p, f, arg, &t));
return managed<task>(t); return managed<task>(t);
} }
static void create_on_pool(ABT_pool p, void(*f)(void*), void* arg, const anonymous&) {
TL_TASK_ASSERT(ABT_task_create(p, f, arg, NULL));
}
void destroy() { void destroy() {
if(m_task != ABT_TASK_NULL) if(m_task != ABT_TASK_NULL)
ABT_task_free(&m_task); ABT_task_free(&m_task);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <cstdint> #include <cstdint>
#include <abt.h> #include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/managed.hpp> #include <thallium/managed.hpp>
#include <thallium/exception.hpp> #include <thallium/exception.hpp>
#include <thallium/abt_errors.hpp> #include <thallium/abt_errors.hpp>
...@@ -202,24 +203,42 @@ class thread { ...@@ -202,24 +203,42 @@ class thread {
return managed<thread>(t); return managed<thread>(t);
} }
static void create_on_xstream(ABT_xstream es, void(*f)(void*), void* arg, const anonymous&) {
TL_THREAD_ASSERT(ABT_thread_create_on_xstream(es, f, arg, ABT_THREAD_ATTR_NULL, NULL));
}
static managed<thread> create_on_pool(ABT_pool p, void(*f)(void*), void* arg) { static managed<thread> create_on_pool(ABT_pool p, void(*f)(void*), void* arg) {
ABT_thread t; ABT_thread t;
TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, ABT_THREAD_ATTR_NULL, &t)); TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, ABT_THREAD_ATTR_NULL, &t));
return managed<thread>(t); return managed<thread>(t);
} }
static void create_on_pool(ABT_pool p, void(*f)(void*), void* arg, const anonymous&) {
TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, ABT_THREAD_ATTR_NULL, NULL));
}
static managed<thread> create_on_xstream(ABT_xstream es, void(*f)(void*), void* arg, const attribute& attr) { static managed<thread> create_on_xstream(ABT_xstream es, void(*f)(void*), void* arg, const attribute& attr) {
ABT_thread t; ABT_thread t;
TL_THREAD_ASSERT(ABT_thread_create_on_xstream(es, f, arg, attr.native_handle(), &t)); TL_THREAD_ASSERT(ABT_thread_create_on_xstream(es, f, arg, attr.native_handle(), &t));
return managed<thread>(t); return managed<thread>(t);
} }
static void create_on_xstream(ABT_xstream es, void(*f)(void*), void* arg,
const attribute& attr, const anonymous&) {
TL_THREAD_ASSERT(ABT_thread_create_on_xstream(es, f, arg, attr.native_handle(), NULL));
}
static managed<thread> create_on_pool(ABT_pool p, void(*f)(void*), void* arg, const attribute& attr) { static managed<thread> create_on_pool(ABT_pool p, void(*f)(void*), void* arg, const attribute& attr) {
ABT_thread t; ABT_thread t;
TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, attr.native_handle(), &t)); TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, attr.native_handle(), &t));
return managed<thread>(t); return managed<thread>(t);
} }
static void create_on_pool(ABT_pool p, void(*f)(void*), void* arg,
const attribute& attr, const anonymous&) {
TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, attr.native_handle(), NULL));
}
void destroy() { void destroy() {
if(m_thread != ABT_THREAD_NULL) if(m_thread != ABT_THREAD_NULL)
ABT_thread_free(&m_thread); ABT_thread_free(&m_thread);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include <abt.h> #include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/scheduler.hpp> #include <thallium/scheduler.hpp>
#include <thallium/thread.hpp> #include <thallium/thread.hpp>
#include <thallium/pool.hpp> #include <thallium/pool.hpp>
...@@ -446,6 +447,12 @@ class xstream { ...@@ -446,6 +447,12 @@ class xstream {
return thread::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp)); return thread::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp));
} }
template<typename F>
managed<thread> make_thread(F&& f, const anonymous& a) {
auto fp = new std::function<void(void)>(std::forward<F>(f));
return thread::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp), a);
}
/** /**
* @brief Create a thread running the specified function and push it * @brief Create a thread running the specified function and push it
* into the pool. * into the pool.
...@@ -462,6 +469,12 @@ class xstream { ...@@ -462,6 +469,12 @@ class xstream {
return thread::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp), attr); return thread::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp), attr);
} }
template<typename F>
managed<thread> make_thread(F&& f, const thread::attribute& attr, const anonymous& a) {
auto fp = new std::function<void(void)>(std::forward<F>(f));
return thread::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp), attr, a);
}
/** /**
* @brief Create a task running the specified function and push it * @brief Create a task running the specified function and push it
* into the pool. * into the pool.
...@@ -477,6 +490,12 @@ class xstream { ...@@ -477,6 +490,12 @@ class xstream {
return task::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp)); return task::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp));
} }
template<typename F>
managed<task> make_task(F&& f, const anonymous& a) {
auto fp = new std::function<void(void)>(std::forward<F>(f));
return task::create_on_xstream(m_xstream, forward_work_unit, static_cast<void*>(fp), a);
}
/** /**
* @brief Terminate the ES associated with the calling ULT. * @brief Terminate the ES associated with the calling ULT.
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment