1
#ifndef __tascel_SplitQueue_h__
2
#define __tascel_SplitQueue_h__
4
#include "TerminationDetector.h"
9
* A set of task queues shared among processes.
11
* Each process has a local queue with a maximum number of possible tasks.
12
* A process can steal tasks from any other process's queue and have
13
* tasks stolen from its own queue.
15
* This implementation splits the queue into a local and shared portion.
16
* This allows the local process to modify its queue without locking.
21
* The local queue state which other procs can modify.
24
int dirty; /**< whether a steal has occurred */
25
int split; /**< the split between head and tail */
26
int tail; /**< the tail of the queue */
27
int size_shared;/**< the number of shared tasks in the queue */
30
const int max_ntsks; /**< max number of tasks allowed in queue */
31
const int tsk_size; /**< size of a single task */
32
char **q; /**< addresses of queue data on all procs */
33
sq_state_t **sq_state; /**< addresses of queue state on all procs */
34
int *head; /**< pointer to this procs head_val */
35
int *tail; /**< pointer to this procs tail state */
36
int *size_local; /**< pointer to this procs size_local_val */
37
int *size_shared; /**< pointer to this procs size_shared state */
38
int *split; /**< pointer to this procs split state */
39
int *dirty; /**< pointer to this procs dirt state */
40
int size_local_val; /**< size of local portion of local queue */
41
int head_val; /**< index of the local queue's head */
42
TerminationDetector td; /**< the termination detector */
45
* Moves tasks from the shared portion to the local portion.
47
* @param[in] _nacquire number of tasks to move
49
int acquireFromShared(int _nacquire);
52
* Moves tasks from the local portion to the shared portion.
54
* @param[in] ndonate number of tasks to move
56
void releaseToShared(int ndonate);
60
* Constructs the SplitQueue instance.
62
* @param[in] tsk_size size of a single task
63
* @param[in] max_ntsks max number of tasks allowed in a queue
65
* @pre tsk_size must be the same value on all procs
66
* @pre max_ntsks must be the same value on all procs
68
SplitQueue(int tsk_size, int max_ntsks);
71
* Destroys the SplitQueue instance.
76
* Returns true if the local queue is empty.
81
* Returns true if the local queue is full.
86
* Retrieves a task from the private portion of the local queue.
88
* @param[out] dscr the retrieved task
89
* @param[in] dlen size of the retrieved task
91
* @pre dscr is not NULL
92
* @pre dlen == tsk_size
94
bool getTask(void *dscr, int dlen);
97
* Adds a task to the private portion of the local queue.
99
* @param[in] dscr the task to add
100
* @param[in] dlen size of the added task
102
* @pre dscr is not NULL
103
* @pre dlen == tsk_size
105
void addTask(void *dscr, int dlen);
108
* Steals one or more tasks from the given proc's shared portion.
110
* @param[in] proc to steal from
112
bool steal(int proc);
115
* Returns true if all of the tasks have been processed.
117
bool hasTerminated();
120
* Returns the number of tasks in the entire local queue.
122
int numTasks() const {
123
return *size_local + *size_shared;
127
* Runs the termination detector.
134
#endif /*__tascel_SplitQueue_h__*/