GHOST  1.1.2
General, Hybrid, and Optimized Sparse Toolkit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
taskq.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#include <errno.h>
#include <unistd.h>
#include "ghost/config.h"
#include "ghost/types.h"
#include "ghost/core.h"
#include "ghost/locality.h"
#include "ghost/task.h"
#include "ghost/taskq.h"
#include "ghost/thpool.h"
#include "ghost/pumap.h"
#include "ghost/util.h"
#include "ghost/machine.h"
#include "ghost/log.h"
#include "ghost/omp.h"
#include "ghost/bitmap.h"
Include dependency graph for taskq.c:

Macros

#define _XOPEN_SOURCE   500
 

Functions

static void * thread_main (void *arg)
 The main routine of each thread in the thread pool. More...
 
ghost_error ghost_taskq_create ()
 Initializes a task queues. More...
 
static int taskq_deleteTask (ghost_taskq *q, ghost_task *t)
 Deletes a given task from a given queue. More...
 
static ghost_tasktaskq_findDeleteAndPinTask (ghost_taskq *q, int nthreads)
 Try to find a task in the given queue. If there is a suited task, delete it from the queue, reserve enough cores in order to execute the task and pin the task's threads to the reserved cores. More...
 
ghost_error ghost_taskq_startroutine (void *(**func)(void *))
 
ghost_error ghost_taskq_add (ghost_task *t)
 Helper function to add a task to a queue. More...
 
ghost_error ghost_taskq_destroy ()
 Execute all outstanding threads and free the task queues' resources. More...
 
ghost_error ghost_taskq_waitall ()
 Wait for all tasks in all queues to be finished. More...
 
ghost_error ghost_taskq_waitsome (ghost_task **tasks, int nt, int *index)
 Wait for some tasks out of a given list of tasks. More...
 

Variables

ghost_taskqtaskq = NULL
 The task queue created by ghost_taskq_create(). More...
 
static int killed = 0
 This is set to 1 if the tasqs are about to be killed. The threads will exit their infinite loops in this case. More...
 
static pthread_mutex_t globalMutex
 Protects access to global variables. More...
 
static pthread_cond_t anyTaskFinishedCond
 This is waited for in ghost_task_waitsome() and broadcasted in ghost_task_wait() when the task has finished. More...
 
static pthread_mutex_t anyTaskFinishedMutex
 The mutex to protect anyTaskFinishedCond. More...
 
static int num_pending_tasks = 0
 
static int nthreadcount = 0
 Holds the number of valid thread counts for tasks. This is usually the number of PUs+1 (for zero-PU tasks) More...
 
static pthread_cond_t ** newTaskCond_by_threadcount
 
static pthread_mutex_t * newTaskMutex_by_threadcount
 
static int * num_shep_by_threadcount
 
static int * waiting_shep_by_threadcount
 
static int * num_tasks_by_threadcount
 
static pthread_key_t threadcount_key
 
static pthread_key_t mutex_key
 

Macro Definition Documentation

#define _XOPEN_SOURCE   500

Function Documentation

ghost_error ghost_taskq_add ( ghost_task t)

Helper function to add a task to a queue.

Parameters
tThe task
Returns
GHOST_SUCCESS on success or GHOST_FAILURE on failure.

Here is the call graph for this function:

ghost_error ghost_taskq_create ( )

Initializes a task queues.

Returns
GHOST_SUCCESS on success or GHOST_FAILURE on failure.

Here is the call graph for this function:

ghost_error ghost_taskq_destroy ( )

Execute all outstanding threads and free the task queues' resources.

Returns
GHOST_SUCCESS on success or GHOST_FAILURE on failure.
ghost_error ghost_taskq_startroutine ( void *(**)(void *)  func)

Here is the call graph for this function:

ghost_error ghost_taskq_waitall ( )

Wait for all tasks in all queues to be finished.

Returns
GHOST_SUCCESS on success or GHOST_FAILURE on failure.

Here is the call graph for this function:

ghost_error ghost_taskq_waitsome ( ghost_task **  tasks,
int  nt,
int *  index 
)

Wait for some tasks out of a given list of tasks.

Parameters
tasksThe list of task pointers that should be waited for.
ntThe length of the list.
indexIndicating which tasks of the list are now finished.
Returns
GHOST_SUCCESS on success or GHOST_FAILURE on failure.
static int taskq_deleteTask ( ghost_taskq q,
ghost_task t 
)
static

Deletes a given task from a given queue.

Parameters
q
t
Returns
GHOST_SUCCESS on success or GHOST_FAILURE on failure.
static ghost_task* taskq_findDeleteAndPinTask ( ghost_taskq q,
int  nthreads 
)
static

Try to find a task in the given queue. If there is a suited task, delete it from the queue, reserve enough cores in order to execute the task and pin the task's threads to the reserved cores.

Parameters
q
Returns
A pointer to the selected task or NULL if no suited task could be found.

Here is the call graph for this function:

static void * thread_main ( void *  arg)
static

The main routine of each thread in the thread pool.

Parameters
argThe core at which the thread is running.
Returns
NULL

Here is the call graph for this function:

Variable Documentation

pthread_cond_t anyTaskFinishedCond
static

This is waited for in ghost_task_waitsome() and broadcasted in ghost_task_wait() when the task has finished.

pthread_mutex_t anyTaskFinishedMutex
static

The mutex to protect anyTaskFinishedCond.

pthread_mutex_t globalMutex
static

Protects access to global variables.

int killed = 0
static

This is set to 1 if the tasqs are about to be killed. The threads will exit their infinite loops in this case.

pthread_key_t mutex_key
static
pthread_cond_t** newTaskCond_by_threadcount
static
pthread_mutex_t* newTaskMutex_by_threadcount
static
int nthreadcount = 0
static

Holds the number of valid thread counts for tasks. This is usually the number of PUs+1 (for zero-PU tasks)

int num_pending_tasks = 0
static
int* num_shep_by_threadcount
static
int* num_tasks_by_threadcount
static
ghost_taskq* taskq = NULL

The task queue created by ghost_taskq_create().

pthread_key_t threadcount_key
static
int* waiting_shep_by_threadcount
static