MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
thread.h File Reference

Data Structures

struct  thread_t

Macros

#define DO_PRAGMA(A...)
#define PRINT_MACRO(x)
#define STR(x)
#define LOCK(A)
#define TRYLOCK(A)
#define UNLOCK(A)
#define PINIT(A)
#define PDEINIT(A)
#define PNEW(A)
#define PNEW2(A)
#define LOCK_FFT   LOCK(mutex_fftw)
#define UNLOCK_FFT   UNLOCK(mutex_fftw)
#define MEM_ORDER   __ATOMIC_SEQ_CST
#define atomic_compare_exchange_n(ptr, pexpected, desired)
#define atomic_compare_exchange(ptr, pexpected, pdesired)
#define OMPTASK_SINGLE
#define OMP_IN_PARALLEL   0
#define OMP_FOR(n)
#define OMP_FOR_COLLAPSE(n, nthread)
#define OMP(A)
#define OMP_TASK_FOR(ntask)
#define OMP_TASK_FOR_COLLAPSE(n, ntask)
#define OMP_CRITICAL
#define THREAD_POOL_INIT(A)
#define QUEUE(counter, fun, arg, njob, urgent)
 Queue jobs to counter. Do not wait.
#define QUEUE_THREAD(counter, A, urgent)
#define WAIT(counter, urgent)
#define CALL(fun, arg, nthread, urgent)
 Queue jobs to a temp counter, Then wait for it to complete.
#define CALL_THREAD(A, urgent)
#define CALL_THREAD_ARR(A, nA, urgent)

Typedefs

typedef void *(* thread_fun) (void *)
typedef void *(* thread_wrapfun) (thread_t *)

Functions

long thread_id (void)
thread_t * thread_prep (long start, long end, long nthread, thread_wrapfun fun, void *data)
pthread_t thread_new (thread_fun fun, void *arg)
void thread_block_signal ()

Detailed Description

Functions regarding to threading.

Openmp version: 3.0 (200805): Introduced task 4.0 (201307): Introduced taskgroup. 4.5 (201511): Introduced taskloop and priority. Taskloop has implicit taskgroup.


Data Structure Documentation

◆ thread_t

struct thread_t

Information about job to launch for each thread. start and end are the two indices.

Collaboration diagram for thread_t:
Data Fields
long start
long end
long ithread
long nthread
thread_wrapfun fun
void * data
void * thread_data

Macro Definition Documentation

◆ DO_PRAGMA

#define DO_PRAGMA ( A...)
Value:
_Pragma(#A)

◆ PRINT_MACRO

#define PRINT_MACRO ( x)
Value:
DO_PRAGMA(message #x " is " STR(x))

◆ STR

#define STR ( x)
Value:
#x

◆ LOCK

#define LOCK ( A)
Value:
pthread_mutex_lock(&A)

◆ TRYLOCK

#define TRYLOCK ( A)
Value:
pthread_mutex_trylock(&A)

◆ UNLOCK

#define UNLOCK ( A)
Value:
pthread_mutex_unlock(&A)

◆ PINIT

#define PINIT ( A)
Value:
pthread_mutex_init(&A,NULL)

◆ PDEINIT

#define PDEINIT ( A)
Value:
pthread_mutex_destroy(&A)

◆ PNEW

#define PNEW ( A)
Value:
static pthread_mutex_t A=PTHREAD_MUTEX_INITIALIZER

◆ PNEW2

#define PNEW2 ( A)
Value:
pthread_mutex_t A=PTHREAD_MUTEX_INITIALIZER

◆ atomic_compare_exchange_n

#define atomic_compare_exchange_n ( ptr,
pexpected,
desired )
Value:
__atomic_compare_exchange_n(ptr, pexpected, desired, 0, MEM_ORDER, MEM_ORDER)

◆ atomic_compare_exchange

#define atomic_compare_exchange ( ptr,
pexpected,
pdesired )
Value:
__atomic_compare_exchange(ptr, pexpected, pdesired, 0, MEM_ORDER, MEM_ORDER)

◆ THREAD_POOL_INIT

#define THREAD_POOL_INIT ( A)
Value:
({thread_pool_init(A);info("Using thread pool with %d threads\n", A);})

◆ QUEUE

#define QUEUE ( counter,
fun,
arg,
njob,
urgent )
Value:
thread_pool_queue(counter, fun, arg, njob, urgent)

Queue jobs to counter. Do not wait.

◆ QUEUE_THREAD

#define QUEUE_THREAD ( counter,
A,
urgent )
Value:
thread_pool_queue(counter, NULL, A, A[0].nthread, urgent)

◆ WAIT

#define WAIT ( counter,
urgent )
Value:
thread_pool_wait(counter, urgent)

Function Documentation

◆ thread_id()

long thread_id ( void )

Return the pthread id of the calling thread.

Returns
pthread id cast to long.

◆ thread_prep()

thread_t * thread_prep ( long start,
long end,
long nthread,
thread_wrapfun fun,
void * data )

Break out the job to be executed by multiple threads. The index range is split evenly; threads beyond the range get empty ranges and NULL fun. thd[0].nthread is set to the number of active threads.

Parameters
[in]startStart index (inclusive).
[in]endEnd index (exclusive).
[in]nthreadNumber of threads.
[in]funFunction to be called by each thread.
[in]dataData shared by all threads.
Returns
Newly allocated array of nthread thread_t; the caller frees it. NULL if nthread is 0.

◆ thread_new()

pthread_t thread_new ( thread_fun fun,
void * arg )

Create a new detached thread and forget.

Parameters
[in]funThread function.
[in]argArgument passed to fun.
Returns
Thread id, or 0 on failure.

◆ thread_block_signal()

void thread_block_signal ( )

After calling this routine, this thread will nolonger receive signals