27 #ifndef EMBB_MTAPI_NODE_H_ 28 #define EMBB_MTAPI_NODE_H_ 30 #include <embb/base/memory_allocation.h> 31 #include <embb/base/function.h> 32 #include <embb/mtapi/c/mtapi.h> 33 #include <embb/mtapi/c/mtapi_ext.h> 34 #include <embb/mtapi/execution_policy.h> 35 #include <embb/mtapi/status_exception.h> 36 #include <embb/mtapi/node_attributes.h> 37 #include <embb/mtapi/group.h> 38 #include <embb/mtapi/queue.h> 39 #include <embb/mtapi/task.h> 40 #include <embb/mtapi/task_attributes.h> 41 #include <embb/mtapi/job.h> 42 #include <embb/mtapi/action.h> 43 #include <embb/mtapi/task_context.h> 49 #ifdef MTAPI_CPP_AUTOMATIC_INITIALIZE 50 #define MTAPI_CPP_AUTOMATIC_DOMAIN_ID 1 51 #define MTAPI_CPP_AUTOMATIC_NODE_ID 1 53 #define EMBB_MTAPI_FUNCTION_JOB_ID 2 82 function_action_.Delete();
100 static void Initialize(
101 mtapi_domain_t domain_id,
112 static void Initialize(
113 mtapi_domain_t domain_id,
114 mtapi_node_t node_id,
125 return NULL != node_instance_;
133 static Node & GetInstance();
140 static void Finalize();
157 return worker_thread_count_;
194 SMPFunction
const & func
196 Job job = GetJob(EMBB_MTAPI_FUNCTION_JOB_ID);
199 job, embb::base::Allocation::New<SMPFunction>(func), res);
209 SMPFunction
const & func,
213 Job job = GetJob(EMBB_MTAPI_FUNCTION_JOB_ID);
218 job, embb::base::Allocation::New<SMPFunction>(func), res, task_attr);
227 template <
typename ARGS,
typename RES>
229 mtapi_task_id_t task_id,
231 const ARGS * arguments,
235 return Start(task_id,
237 arguments, internal::SizeOfType<ARGS>(),
238 results, internal::SizeOfType<RES>(),
248 template <
typename ARGS,
typename RES>
250 mtapi_task_id_t task_id,
252 const ARGS * arguments,
255 return Start(task_id,
257 arguments, internal::SizeOfType<ARGS>(),
258 results, internal::SizeOfType<RES>(),
259 MTAPI_DEFAULT_TASK_ATTRIBUTES);
268 template <
typename ARGS,
typename RES>
271 const ARGS * arguments,
275 return Start(MTAPI_TASK_ID_NONE,
277 arguments, internal::SizeOfType<ARGS>(),
278 results, internal::SizeOfType<RES>(),
288 template <
typename ARGS,
typename RES>
291 const ARGS * arguments,
294 return Start(MTAPI_TASK_ID_NONE,
296 arguments, internal::SizeOfType<ARGS>(),
297 results, internal::SizeOfType<RES>(),
298 MTAPI_DEFAULT_TASK_ATTRIBUTES);
309 mtapi_job_id_t job_id
311 return Job(job_id, domain_id_);
321 mtapi_job_id_t job_id,
322 mtapi_domain_t domain_id
324 return Job(job_id, domain_id);
334 mtapi_job_id_t job_id,
336 const void * node_local_data,
338 mtapi_size_t node_local_data_size,
342 return Action(job_id, func, node_local_data, node_local_data_size,
353 mtapi_job_id_t job_id,
355 const void * node_local_data,
357 mtapi_size_t node_local_data_size
359 return Action(job_id, func, node_local_data, node_local_data_size,
360 MTAPI_DEFAULT_ACTION_ATTRIBUTES);
370 mtapi_job_id_t job_id,
385 mtapi_job_id_t job_id,
388 return Action(job_id, func, MTAPI_NULL, 0, MTAPI_DEFAULT_ACTION_ATTRIBUTES);
398 return Group(MTAPI_GROUP_ID_NONE, MTAPI_DEFAULT_GROUP_ATTRIBUTES);
410 return Group(
id, MTAPI_DEFAULT_GROUP_ATTRIBUTES);
447 return Queue(MTAPI_QUEUE_ID_NONE, job, MTAPI_DEFAULT_QUEUE_ATTRIBUTES);
472 mtapi_task_id_t task_id,
473 mtapi_job_hndl_t job,
474 const void * arguments,
475 mtapi_size_t arguments_size,
477 mtapi_size_t results_size,
478 mtapi_task_attributes_t
const * attributes
481 mtapi_status_t status;
482 mtapi_task_hndl_t task_hndl =
484 results, results_size, attributes, MTAPI_GROUP_NONE,
486 internal::CheckStatus(status);
487 return Task(task_hndl);
501 Node const & operator=(
Node const & other);
504 mtapi_domain_t domain_id,
505 mtapi_node_t node_id,
507 mtapi_status_t status;
513 internal::CheckStatus(status);
515 core_count_ = info.hardware_concurrency;
519 domain_id_ = domain_id;
522 CreateAction(EMBB_MTAPI_FUNCTION_JOB_ID, ActionFunction);
525 static void ActionFunction(
532 mtapi_task_context_t * context) {
536 const_cast<void*
>(args));
537 (*func)(task_context);
543 mtapi_domain_t domain_id_;
544 mtapi_uint_t core_count_;
545 mtapi_uint_t worker_thread_count_;
546 mtapi_uint_t queue_count_;
547 mtapi_uint_t group_count_;
548 mtapi_uint_t task_limit_;
555 #endif // EMBB_MTAPI_NODE_H_ Definition: lock_free_mpmc_queue.h:40
embb::base::Function< void, TaskContext & > SMPFunction
Function type for simple SMP interface.
Definition: node.h:75
Action CreateAction(mtapi_job_id_t job_id, mtapi_action_function_t func)
Constructs an Action.
Definition: node.h:384
void mtapi_ext_yield()
This function yields execution to the MTAPI scheduler for at most one task.
Contains attributes of a Node.
Definition: node_attributes.h:42
Action CreateAction(mtapi_job_id_t job_id, mtapi_action_function_t func, const void *node_local_data, mtapi_size_t node_local_data_size)
Constructs an Action.
Definition: node.h:352
Contains attributes of an Action.
Definition: action_attributes.h:42
A singleton representing the MTAPI runtime.
Definition: node.h:70
Action CreateAction(mtapi_job_id_t job_id, mtapi_action_function_t func, const void *node_local_data, mtapi_size_t node_local_data_size, ActionAttributes const &attributes)
Constructs an Action.
Definition: node.h:333
Job GetJob(mtapi_job_id_t job_id)
Retrieves a handle to the Job identified by job_id within the domain of the local Node...
Definition: node.h:308
static bool IsInitialized()
Checks if runtime is initialized.
Definition: node.h:124
~Node()
Destroys the runtime singleton.
Definition: node.h:81
Queue CreateQueue(Job const &job, QueueAttributes const &attr)
Constructs a Queue with the given Job and QueueAttributes.
Definition: node.h:456
Task Start(SMPFunction const &func)
Starts a new Task.
Definition: node.h:193
void mtapi_initialize(const mtapi_domain_t domain_id, const mtapi_node_t node_id, const mtapi_node_attributes_t *attributes, mtapi_info_t *mtapi_info, mtapi_status_t *status)
Initializes the MTAPI environment on a given MTAPI node in a given MTAPI domain.
Task Start(mtapi_task_id_t task_id, mtapi_job_hndl_t job, const void *arguments, mtapi_size_t arguments_size, void *results, mtapi_size_t results_size, mtapi_task_attributes_t const *attributes)
Starts a new Task.
Definition: node.h:471
Task Start(mtapi_task_id_t task_id, Job const &job, const ARGS *arguments, RES *results)
Starts a new Task.
Definition: node.h:249
Task Start(mtapi_task_id_t task_id, Job const &job, const ARGS *arguments, RES *results, TaskAttributes const &attributes)
Starts a new Task.
Definition: node.h:228
mtapi_task_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: task_attributes.h:148
mtapi_action_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: action_attributes.h:114
mtapi_uint_t GetGroupCount() const
Returns the number of available groups.
Definition: node.h:174
Contains attributes of a Group.
Definition: group_attributes.h:41
mtapi_uint_t GetQueueCount() const
Returns the number of available queues.
Definition: node.h:165
Represents a collection of Actions.
Definition: job.h:41
Task Start(Job const &job, const ARGS *arguments, RES *results)
Starts a new Task.
Definition: node.h:289
Wraps function pointers, member function pointers, and functors with up to five arguments.
Definition: function.h:94
Allows for stream processing, either ordered or unordered.
Definition: queue.h:52
mtapi_node_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: node_attributes.h:261
Queue CreateQueue(Job &job)
Constructs a Queue with the given Job and default attributes.
Definition: node.h:444
Group CreateGroup(GroupAttributes const &group_attr)
Constructs a Group object using the given Attributes.
Definition: node.h:419
Contains attributes of a Task.
Definition: task_attributes.h:42
mtapi_task_hndl_t mtapi_task_start(const mtapi_task_id_t task_id, const mtapi_job_hndl_t job, const void *arguments, const mtapi_size_t arguments_size, void *result_buffer, const mtapi_size_t result_size, const mtapi_task_attributes_t *attributes, const mtapi_group_hndl_t group, mtapi_status_t *status)
This function schedules a task for execution.
mtapi_queue_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: queue_attributes.h:166
void mtapi_finalize(mtapi_status_t *status)
Finalizes the MTAPI environment on a given MTAPI node and domain.
Group CreateGroup(mtapi_group_id_t id, GroupAttributes const &group_attr)
Constructs a Group object with given attributes and ID.
Definition: node.h:431
Task Start(Job const &job, const ARGS *arguments, RES *results, TaskAttributes const &attributes)
Starts a new Task.
Definition: node.h:269
mtapi_uint_t GetTaskLimit() const
Returns the number of available tasks.
Definition: node.h:183
unsigned int embb_core_set_count(const embb_core_set_t *core_set)
Returns the number of cores contained in the specified set.
Describes the execution policy of a parallel algorithm.
Definition: execution_policy.h:48
TaskAttributes & SetPolicy(ExecutionPolicy const &policy)
Sets the ExecutionPolicy of a Task.
Definition: task_attributes.h:114
Task Start(SMPFunction const &func, ExecutionPolicy const &policy)
Starts a new Task with a given affinity and priority.
Definition: node.h:208
mtapi_uint_t GetWorkerThreadCount() const
Returns the number of worker threads.
Definition: node.h:156
Group CreateGroup(mtapi_group_id_t id)
Constructs a Group object with default attributes and the given ID.
Definition: node.h:407
Group CreateGroup()
Constructs a Group object with default attributes.
Definition: node.h:397
static void Delete(Type *to_delete)
Destructs an instance of type Type and frees the allocated memory.
Definition: memory_allocation.h:176
Represents a facility to wait for multiple related Tasks.
Definition: group.h:52
mtapi_uint_t GetCoreCount() const
Returns the number of available cores.
Definition: node.h:147
Action CreateAction(mtapi_job_id_t job_id, mtapi_action_function_t func, ActionAttributes const &attributes)
Constructs an Action.
Definition: node.h:369
mtapi_group_attributes_t const & GetInternal() const
Returns the internal representation of this object.
Definition: group_attributes.h:60
void(* mtapi_action_function_t)(const void *args, mtapi_size_t args_size, void *result_buffer, mtapi_size_t result_buffer_size, const void *node_local_data, mtapi_size_t node_local_data_size, mtapi_task_context_t *context)
An action function is the executable software function that implements an action. ...
Definition: mtapi.h:941
void YieldToScheduler()
This function yields execution to the MTAPI scheduler for at most one task.
Definition: node.h:494
Job GetJob(mtapi_job_id_t job_id, mtapi_domain_t domain_id)
Retrieves a handle to the Job identified by job_id and domain_id.
Definition: node.h:320
Common (static) functionality for unaligned and aligned memory allocation.
Definition: memory_allocation.h:55
Holds the actual worker function used to execute a Task.
Definition: action.h:42
Provides information about the status of the currently running Task.
Definition: task_context.h:41
Contains attributes of a Queue.
Definition: queue_attributes.h:41
A Task represents a running Action of a specific Job.
Definition: task.h:41
mtapi_job_hndl_t GetInternal() const
Returns the internal representation of this object.
Definition: job.h:80