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

added the possibility to create anonymous threads and tasks

parent 7d19ec4f
......@@ -3,6 +3,7 @@
#include <margo.h>
#include <thallium/abt.hpp>
#include <thallium/anonymous.hpp>
#include <thallium/bulk_mode.hpp>
#include <thallium/bulk.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 @@
#include <memory>
#include <functional>
#include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/task.hpp>
#include <thallium/thread.hpp>
#include <thallium/managed.hpp>
......@@ -438,6 +439,12 @@ class pool {
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
* into the pool.
......@@ -453,6 +460,12 @@ class pool {
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
* into the pool.
......@@ -468,6 +481,12 @@ class pool {
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);
}
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>
......
......@@ -9,6 +9,7 @@
#include <cstdint>
#include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/managed.hpp>
#include <thallium/exception.hpp>
#include <thallium/abt_errors.hpp>
......@@ -75,10 +76,18 @@ class task {
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) {
ABT_task t;
TL_TASK_ASSERT(ABT_task_create(p, f, arg, &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() {
......
......@@ -9,6 +9,7 @@
#include <cstdint>
#include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/managed.hpp>
#include <thallium/exception.hpp>
#include <thallium/abt_errors.hpp>
......@@ -202,24 +203,42 @@ class thread {
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) {
ABT_thread t;
TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, ABT_THREAD_ATTR_NULL, &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) {
ABT_thread t;
TL_THREAD_ASSERT(ABT_thread_create_on_xstream(es, f, arg, attr.native_handle(), &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) {
ABT_thread t;
TL_THREAD_ASSERT(ABT_thread_create(p, f, arg, attr.native_handle(), &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() {
if(m_thread != ABT_THREAD_NULL)
ABT_thread_free(&m_thread);
......
......@@ -11,6 +11,7 @@
#include <vector>
#include <abt.h>
#include <thallium/anonymous.hpp>
#include <thallium/scheduler.hpp>
#include <thallium/thread.hpp>
#include <thallium/pool.hpp>
......@@ -446,6 +447,12 @@ class xstream {
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
* into the pool.
......@@ -462,6 +469,12 @@ class xstream {
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
* into the pool.
......@@ -477,6 +490,12 @@ class xstream {
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.
*/
......
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