GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
task.h
Go to the documentation of this file.
1 
7 #ifndef GHOST_TASK_H
8 #define GHOST_TASK_H
9 
10 #include <pthread.h>
11 #include <semaphore.h>
12 #include <hwloc.h>
13 #include "error.h"
14 
15 #define GHOST_TASK_LD_UNDEFINED -2 // initializer
16 //#define GHOST_TASK_LD_ANY -1 // execute task on any LD
17 
18 
19 typedef enum {
39 }
41 
42 
46 #define GHOST_TASK_FILL_LD -1
47 
50 #define GHOST_TASK_FILL_ALL -2
51 
52 typedef enum {
74 
84 typedef struct ghost_task {
88  int nThreads;
93  int LD;
97  int flags;
101  void *(*func)(void *);
105  void *arg;
109  struct ghost_task ** depends;
113  int ndepends;
117  sem_t *progressSem;
118 
119  // set by the library
127 // int *cores;
131  hwloc_bitmap_t coremap;
135  hwloc_bitmap_t childusedmap;
139  void *ret;
143  struct ghost_task *next;
147  struct ghost_task *prev;
156  pthread_cond_t *finishedCond;
160  pthread_mutex_t *mutex;
161  pthread_mutex_t *finishedMutex;
162  pthread_mutex_t *stateMutex;
169  int freed;
170 } ghost_task;
171 
172 #ifdef __cplusplus
173 extern "C" {
174 #endif
175 
190  ghost_error ghost_task_create(ghost_task **task, int nThreads, int LD, void *(*func)(void *), void *arg, ghost_task_flags flags, ghost_task **depends, int ndepends);
220  void ghost_task_destroy(ghost_task *t);
249  ghost_error ghost_task_string(char **str, ghost_task *t);
250 
252 
258  bool ghost_tasking_enabled();
259 
260 
261 #ifdef __cplusplus
262 }// extern "C"
263 #endif
264 
265 #endif
266 
This structure represents a GHOST task.
Definition: task.h:84
struct ghost_task * parent
The enqueueing task if the task has been enqueued from within a task. (set by the library...
Definition: task.h:152
int flags
Optional flags for the task. (user-defined)
Definition: task.h:97
pthread_cond_t * finishedCond
Indicator that the task is finished. (set by the library)
Definition: task.h:156
The task will be treated as high-priority.
Definition: task.h:27
ghost_error ghost_task_string(char **str, ghost_task *t)
Stringify a task.
Definition: task.c:49
Task is invalid (e.g., not yet created).
Definition: task.h:56
ghost_error ghost_task_cur(ghost_task **task)
Definition: task.c:279
hwloc_bitmap_t childusedmap
Map of cores a child of this task is using. (set by the library)
Definition: task.h:135
ghost_task_state ghost_taskest(ghost_task *t)
Test the task's current state.
Definition: task.c:104
int freed
Set to one as soon as the task's resources have been free'd. This can be the case when the task waits...
Definition: task.h:169
struct ghost_task * next
Pointer to the next task in the queue. (set by the library)
Definition: task.h:143
pthread_mutex_t * mutex
Protect accesses to the task's members. (set by the library)
Definition: task.h:160
ghost_error ghost_task_create(ghost_task **task, int nThreads, int LD, void *(*func)(void *), void *arg, ghost_task_flags flags, ghost_task **depends, int ndepends)
Create a task.
Definition: task.c:205
The task must be executed in the given NUMA node.
Definition: task.h:31
bool ghost_tasking_enabled()
Check whether tasking is globally enabled.
Definition: task.c:299
ghost_error ghost_task_unpin(ghost_task *task)
Unpin a task's threads.
Definition: task.c:26
A child task must not use this task's resources.
Definition: task.h:35
void * ret
The return value of the task's funtion. (set by the library)
Definition: task.h:139
int LD
The index of the queue in which the task should be present and (preferrably) running. (user-defined)
Definition: task.h:93
void *(* func)(void *)
The function to be executed by the task. (user-defined)
Definition: task.h:101
ghost_error ghost_task_enqueue(ghost_task *t)
Enqueue a task.
Definition: task.c:64
hwloc_bitmap_t coremap
The list of cores where the task's threads are running. (set by the library)
Definition: task.h:131
int nThreads
The number of threads the task should use. (user-defined)
Definition: task.h:88
Types, functions and macros for error handling.
ghost_task_flags
Definition: task.h:19
Definition: task.h:36
void * arg
The arguments to the task's function. (user-defined)
Definition: task.h:105
ghost_error
Error return type.
Definition: error.h:23
void ghost_task_destroy(ghost_task *t)
Destroy a task.
Definition: task.c:181
The default task.
Definition: task.h:23
pthread_mutex_t * stateMutex
Definition: task.h:162
struct ghost_task ** depends
A list of tasks which have to be finished before this task can start. (user-defined) ...
Definition: task.h:109
Task has finished.
Definition: task.h:72
int ndepends
The number of dependencies. (user-defined)
Definition: task.h:113
struct ghost_task * prev
Pointer to the previous task in the queue. (set by the library)
Definition: task.h:147
Definition: task.h:37
struct ghost_task ghost_task
This structure represents a GHOST task.
pthread_mutex_t * finishedMutex
Definition: task.h:161
Task is running.
Definition: task.h:68
ghost_task_state
Definition: task.h:52
Definition: task.h:38
ghost_task_state state
The current state of the task. (set by the library)
Definition: task.h:123
const char * ghost_task_state_string(ghost_task_state state)
Return a string representing the task's state.
Definition: task.c:155
sem_t * progressSem
A semaphore for the user to mark progress in this thread. (set by the library)
Definition: task.h:117
Task has been enqueued.
Definition: task.h:64
ghost_error ghost_task_wait(ghost_task *t)
Wait for a task to finish.
Definition: task.c:119
Task has been created.
Definition: task.h:60