Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

WKFThreads.C File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "WKFThreads.h"

Go to the source code of this file.

Typedefs

typedef void *(* WKFTHREAD_START_ROUTINE )(void *)

Functions

int wkf_thread_numphysprocessors (void)
int wkf_thread_numprocessors (void)
int * wkf_cpu_affinitylist (int *cpuaffinitycount)
int wkf_thread_set_self_cpuaffinity (int cpu)
int wkf_thread_setconcurrency (int nthr)
int wkf_thread_create (wkf_thread_t *thr, void *fctn(void *), void *arg)
int wkf_thread_join (wkf_thread_t thr, void **stat)
int wkf_mutex_init (wkf_mutex_t *mp)
int wkf_mutex_lock (wkf_mutex_t *mp)
int wkf_mutex_trylock (wkf_mutex_t *mp)
int wkf_mutex_spin_lock (wkf_mutex_t *mp)
int wkf_mutex_unlock (wkf_mutex_t *mp)
int wkf_mutex_destroy (wkf_mutex_t *mp)
int wkf_cond_init (wkf_cond_t *cvp)
int wkf_cond_destroy (wkf_cond_t *cvp)
int wkf_cond_wait (wkf_cond_t *cvp, wkf_mutex_t *mp)
int wkf_cond_signal (wkf_cond_t *cvp)
int wkf_cond_broadcast (wkf_cond_t *cvp)
int wkf_thread_run_barrier_init (wkf_run_barrier_t *barrier, int n_clients)
void wkf_thread_run_barrier_destroy (wkf_run_barrier_t *barrier)
void *(*)(void *) wkf_thread_run_barrier (wkf_run_barrier_t *barrier, void *fctn(void *), void *parms, void **rsltparms)
int wkf_thread_run_barrier_poll (wkf_run_barrier_t *barrier)
int wkf_tilestack_init (wkf_tilestack_t *s, int size)
void wkf_tilestack_destroy (wkf_tilestack_t *s)
int wkf_tilestack_compact (wkf_tilestack_t *s)
int wkf_tilestack_push (wkf_tilestack_t *s, const wkf_tasktile_t *t)
int wkf_tilestack_pop (wkf_tilestack_t *s, wkf_tasktile_t *t)
int wkf_tilestack_popall (wkf_tilestack_t *s)
int wkf_tilestack_empty (wkf_tilestack_t *s)
int wkf_shared_iterator_init (wkf_shared_iterator_t *it)
int wkf_shared_iterator_destroy (wkf_shared_iterator_t *it)
int wkf_shared_iterator_set (wkf_shared_iterator_t *it, wkf_tasktile_t *tile)
int wkf_shared_iterator_next_tile (wkf_shared_iterator_t *it, int reqsize, wkf_tasktile_t *tile)
int wkf_shared_iterator_setfatalerror (wkf_shared_iterator_t *it)
int wkf_shared_iterator_getfatalerror (wkf_shared_iterator_t *it)
wkf_threadpool_twkf_threadpool_create (int workercount, int *devlist)
int wkf_threadpool_launch (wkf_threadpool_t *thrpool, void *fctn(void *), void *parms, int blocking)
int wkf_threadpool_wait (wkf_threadpool_t *thrpool)
int wkf_threadpool_poll (wkf_threadpool_t *thrpool)
int wkf_threadpool_destroy (wkf_threadpool_t *thrpool)
int wkf_threadpool_get_workercount (wkf_threadpool_t *thrpool)
int wkf_threadpool_worker_getid (void *voiddata, int *threadid, int *threadcount)
int wkf_threadpool_worker_getdevid (void *voiddata, int *devid)
int wkf_threadpool_worker_setdevspeed (void *voiddata, float speed)
int wkf_threadpool_worker_getdevspeed (void *voiddata, float *speed)
int wkf_threadpool_worker_devscaletile (void *voiddata, int *tilesize)
int wkf_threadpool_worker_getdata (void *voiddata, void **clientdata)
int wkf_threadpool_sched_dynamic (wkf_threadpool_t *thrpool, wkf_tasktile_t *tile)
int wkf_threadpool_next_tile (void *voidparms, int reqsize, wkf_tasktile_t *tile)
int wkf_threadpool_tile_failed (void *voidparms, wkf_tasktile_t *tile)
int wkf_threadpool_setfatalerror (void *voidparms)
int wkf_threadpool_getfatalerror (void *voidparms)
int wkf_threadlaunch (int numprocs, void *clientdata, void *fctn(void *), wkf_tasktile_t *tile)
int wkf_threadlaunch_getid (void *voidparms, int *threadid, int *threadcount)
int wkf_threadlaunch_getdata (void *voidparms, void **clientdata)
int wkf_threadlaunch_next_tile (void *voidparms, int reqsize, wkf_tasktile_t *tile)
int wkf_threadlaunch_setfatalerror (void *voidparms)


Typedef Documentation

typedef void*(* WKFTHREAD_START_ROUTINE)(void *)
 

Typedef to eliminate compiler warning caused by C/C++ linkage conflict.

Definition at line 319 of file WKFThreads.C.

Referenced by wkf_thread_create.


Function Documentation

int wkf_cond_broadcast wkf_cond_t  
 

signal a condition variable, waking all threads

Definition at line 633 of file WKFThreads.C.

References wkf_cond_t.

int wkf_cond_destroy wkf_cond_t  
 

destroy a condition variable

Definition at line 527 of file WKFThreads.C.

References wkf_cond_t.

int wkf_cond_init wkf_cond_t  
 

initialize a condition variable

Definition at line 494 of file WKFThreads.C.

References NULL, and wkf_cond_t.

int wkf_cond_signal wkf_cond_t  
 

signal a condition variable, waking at least one thread

Definition at line 604 of file WKFThreads.C.

References wkf_cond_t.

int wkf_cond_wait wkf_cond_t  ,
wkf_mutex_t  
 

wait on a condition variable

Definition at line 548 of file WKFThreads.C.

References wkf_cond_t, and wkf_mutex_t.

int* wkf_cpu_affinitylist int *    cpuaffinitycount
 

query CPU affinity of the calling process (if allowed by host system)

Definition at line 160 of file WKFThreads.C.

References NULL.

int wkf_mutex_destroy wkf_mutex_t  
 

destroy a mutex

Definition at line 474 of file WKFThreads.C.

References wkf_mutex_t.

int wkf_mutex_init wkf_mutex_t  
 

initialize a mutex

Definition at line 379 of file WKFThreads.C.

References wkf_mutex_t.

int wkf_mutex_lock wkf_mutex_t  
 

lock a mutex

Definition at line 396 of file WKFThreads.C.

References wkf_mutex_t.

int wkf_mutex_spin_lock wkf_mutex_t  
 

lock a mutex by spinning only

Definition at line 434 of file WKFThreads.C.

References wkf_mutex_t.

int wkf_mutex_trylock wkf_mutex_t  
 

try to lock a mutex

Definition at line 413 of file WKFThreads.C.

References wkf_mutex_t.

int wkf_mutex_unlock wkf_mutex_t  
 

unlock a mutex

Definition at line 457 of file WKFThreads.C.

References wkf_mutex_t.

int wkf_shared_iterator_destroy wkf_shared_iterator_t   it
 

destroy a shared iterator

Definition at line 916 of file WKFThreads.C.

References wkf_shared_iterator_struct::mtx, and wkf_mutex_destroy.

int wkf_shared_iterator_getfatalerror wkf_shared_iterator_t   it
 

master thread calls this to query for fatal errors

Definition at line 991 of file WKFThreads.C.

References wkf_shared_iterator_struct::fatalerror, wkf_shared_iterator_struct::mtx, wkf_mutex_lock, and wkf_mutex_unlock.

int wkf_shared_iterator_init wkf_shared_iterator_t   it
 

initialize a shared iterator

Definition at line 906 of file WKFThreads.C.

References wkf_shared_iterator_struct::mtx, and wkf_mutex_init.

int wkf_shared_iterator_next_tile wkf_shared_iterator_t   it,
int    reqsize,
wkf_tasktile_t   tile
 

iterate the shared iterator, over a requested half-open interval

Definition at line 942 of file WKFThreads.C.

References wkf_shared_iterator_struct::current, wkf_shared_iterator_struct::end, wkf_tasktile_struct::end, wkf_shared_iterator_struct::fatalerror, wkf_shared_iterator_struct::mtx, wkf_tasktile_struct::start, wkf_mutex_spin_lock, wkf_mutex_unlock, WKF_SCHED_CONTINUE, and WKF_SCHED_DONE.

int wkf_shared_iterator_set wkf_shared_iterator_t   it,
wkf_tasktile_t   tile
 

set shared iterator parameters

Definition at line 925 of file WKFThreads.C.

References wkf_shared_iterator_struct::current, wkf_tasktile_struct::end, wkf_shared_iterator_struct::end, wkf_shared_iterator_struct::fatalerror, wkf_shared_iterator_struct::mtx, wkf_tasktile_struct::start, wkf_shared_iterator_struct::start, wkf_mutex_lock, and wkf_mutex_unlock.

int wkf_shared_iterator_setfatalerror wkf_shared_iterator_t   it
 

worker thread calls this to indicate a fatal error

Definition at line 978 of file WKFThreads.C.

References wkf_shared_iterator_struct::fatalerror, wkf_shared_iterator_struct::mtx, wkf_mutex_spin_lock, and wkf_mutex_unlock.

int wkf_thread_create wkf_thread_t  ,
void *fctn(void *)   ,
void *   
 

create a new child thread

Definition at line 321 of file WKFThreads.C.

References NULL, wkf_thread_t, and WKFTHREAD_START_ROUTINE.

int wkf_thread_join wkf_thread_t   ,
void **   
 

join (wait for completion of, and merge with) a thread

Definition at line 353 of file WKFThreads.C.

References wkf_thread_t.

int wkf_thread_numphysprocessors void   
 

If compiling on Linux, enable the GNU CPU affinity functions in both libc and the libpthreads

Definition at line 93 of file WKFThreads.C.

Referenced by wkf_thread_numprocessors.

int wkf_thread_numprocessors void   
 

number of processors available, subject to user override

Definition at line 128 of file WKFThreads.C.

References NULL, and wkf_thread_numphysprocessors.

Referenced by evaluate_grid_fast, find_next_cluster, find_within, measure_gofr, vmd_bondsearch_thr, vmd_cuda_gaussdensity_direct, vmd_cuda_vol_cpotential, vmd_gaussdensity_threaded, vmdinfo_tcl, VMDinitialize, and vol_cpotential_cpu.

void*(*)(void *) wkf_thread_run_barrier  
 

Wait until all threads reach barrier, and return the function pointer passed in by the master thread.

Definition at line 696 of file WKFThreads.C.

References wkf_run_barrier_struct::fctn, wkf_run_barrier_struct::lock, wkf_run_barrier_struct::n_clients, wkf_run_barrier_struct::n_waiting, NULL, wkf_run_barrier_struct::parms, wkf_run_barrier_struct::phase, wkf_run_barrier_struct::rslt, wkf_run_barrier_struct::rsltparms, wkf_run_barrier_struct::wait_cv, wkf_cond_broadcast, wkf_cond_wait, wkf_mutex_lock, and wkf_mutex_unlock.

Referenced by wkf_threadpool_destroy, wkf_threadpool_launch, and wkf_threadpool_wait.

void wkf_thread_run_barrier_destroy wkf_run_barrier_t   barrier
 

destroy thread pool barrier

Definition at line 684 of file WKFThreads.C.

References wkf_run_barrier_struct::lock, wkf_run_barrier_struct::wait_cv, wkf_cond_destroy, and wkf_mutex_destroy.

int wkf_thread_run_barrier_init wkf_run_barrier_t   barrier,
int    n_clients
 

initialize thread pool barrier

Definition at line 668 of file WKFThreads.C.

References wkf_run_barrier_struct::fctn, wkf_run_barrier_struct::lock, wkf_run_barrier_struct::n_clients, wkf_run_barrier_struct::n_waiting, NULL, wkf_run_barrier_struct::phase, wkf_run_barrier_struct::wait_cv, wkf_cond_init, and wkf_mutex_init.

int wkf_thread_run_barrier_poll wkf_run_barrier_t   barrier
 

non-blocking poll to see if peers are already at the barrier

Definition at line 742 of file WKFThreads.C.

References wkf_run_barrier_struct::lock, wkf_run_barrier_struct::n_clients, wkf_run_barrier_struct::n_waiting, wkf_mutex_lock, and wkf_mutex_unlock.

int wkf_thread_set_self_cpuaffinity int    cpu
 

set the CPU affinity of the current thread (if allowed by host system)

Definition at line 249 of file WKFThreads.C.

int wkf_thread_setconcurrency int   
 

set the concurrency level and scheduling scope for threads

Definition at line 294 of file WKFThreads.C.

int wkf_threadlaunch int    numprocs,
void *    clientdata,
void *fctn(void *)   ,
wkf_tasktile_t   tile
 

launch up to numprocs threads using shared iterator as a load balancer

Definition at line 1291 of file WKFThreads.C.

References wkf_threadlaunch_struct::clientdata, wkf_threadlaunch_struct::iter, NULL, wkf_threadlaunch_struct::threadcount, wkf_threadlaunch_struct::threadid, wkf_shared_iterator_destroy, wkf_shared_iterator_getfatalerror, wkf_shared_iterator_init, wkf_shared_iterator_set, wkf_thread_create, wkf_thread_join, and wkf_thread_t.

int wkf_threadlaunch_getdata void *    voidparms,
void **    clientdata
 

worker thread can call this to get its client data pointer

Definition at line 1381 of file WKFThreads.C.

References wkf_threadlaunch_struct::clientdata, and NULL.

int wkf_threadlaunch_getid void *    voidparms,
int *    threadid,
int *    threadcount
 

worker thread can call this to get its ID and number of peers

Definition at line 1368 of file WKFThreads.C.

References NULL, wkf_threadlaunch_struct::threadcount, and wkf_threadlaunch_struct::threadid.

int wkf_threadlaunch_next_tile void *    voidparms,
int    reqsize,
wkf_tasktile_t   tile
 

iterate the shared iterator over the requested half-open interval

Definition at line 1391 of file WKFThreads.C.

References wkf_threadlaunch_struct::iter, and wkf_shared_iterator_next_tile.

int wkf_threadlaunch_setfatalerror void *    voidparms
 

worker thread calls this to indicate that an unrecoverable error occured

Definition at line 1399 of file WKFThreads.C.

References wkf_threadlaunch_struct::iter, and wkf_shared_iterator_setfatalerror.

wkf_threadpool_t* wkf_threadpool_create int    workercount,
int *    devlist
 

create a thread pool with a specified number of worker threads

Definition at line 1028 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::devid, wkf_threadpool_struct::devlist, wkf_threadpool_workerdata_struct::devspeed, wkf_threadpool_workerdata_struct::errorstack, wkf_threadpool_struct::errorstack, wkf_threadpool_workerdata_struct::iter, wkf_threadpool_struct::iter, NULL, wkf_threadpool_struct::runbar, wkf_threadpool_workerdata_struct::threadcount, wkf_threadpool_workerdata_struct::threadid, wkf_threadpool_struct::threads, wkf_threadpool_workerdata_struct::thrpool, wkf_shared_iterator_init, wkf_thread_create, wkf_thread_run_barrier_init, wkf_thread_t, wkf_tilestack_init, wkf_threadpool_struct::workercount, and wkf_threadpool_struct::workerdata.

int wkf_threadpool_destroy wkf_threadpool_t   thrpool
 

join all worker threads and free resources

Definition at line 1123 of file WKFThreads.C.

References wkf_threadpool_struct::devlist, wkf_threadpool_struct::errorstack, wkf_threadpool_struct::iter, NULL, wkf_threadpool_struct::runbar, wkf_threadpool_struct::threads, wkf_shared_iterator_destroy, wkf_thread_join, wkf_thread_run_barrier, wkf_thread_run_barrier_destroy, wkf_tilestack_destroy, wkf_threadpool_struct::workercount, and wkf_threadpool_struct::workerdata.

int wkf_threadpool_get_workercount wkf_threadpool_t   thrpool
 

return the number of worker threads currently in the pool

Definition at line 1157 of file WKFThreads.C.

References wkf_threadpool_struct::workercount.

int wkf_threadpool_getfatalerror void *    thrparms
 

master thread calls this to query for fatal errors

Definition at line 1283 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::iter, and wkf_shared_iterator_getfatalerror.

int wkf_threadpool_launch wkf_threadpool_t   thrpool,
void *fctn(void *)   ,
void *    parms,
int    blocking
 

launch threads onto a new function, with associated parms

Definition at line 1088 of file WKFThreads.C.

References NULL, wkf_threadpool_workerdata_struct::parms, wkf_threadpool_struct::runbar, wkf_thread_run_barrier, and wkf_threadpool_struct::workerdata.

int wkf_threadpool_next_tile void *    voidparms,
int    reqsize,
wkf_tasktile_t   tile
 

iterate the shared iterator over the requested half-open interval

Definition at line 1248 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::errorstack, wkf_threadpool_workerdata_struct::iter, WKF_SCHED_CONTINUE, WKF_SCHED_DONE, wkf_shared_iterator_next_tile, WKF_TILESTACK_EMPTY, and wkf_tilestack_pop.

int wkf_threadpool_poll wkf_threadpool_t   thrpool
 

Definition at line 1114 of file WKFThreads.C.

References wkf_threadpool_struct::runbar, and wkf_thread_run_barrier_poll.

int wkf_threadpool_sched_dynamic wkf_threadpool_t   thrpool,
wkf_tasktile_t   tile
 

Set shared iterator state to half-open interval defined by tile

Definition at line 1240 of file WKFThreads.C.

References wkf_threadpool_struct::iter, NULL, and wkf_shared_iterator_set.

int wkf_threadpool_setfatalerror void *    thrparms
 

worker thread calls this to indicate that an unrecoverable error occured

Definition at line 1275 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::iter, and wkf_shared_iterator_setfatalerror.

int wkf_threadpool_tile_failed void *    voidparms,
wkf_tasktile_t   tile
 

worker thread calls this when a failure occurs on a tile it has already taken from the scheduler

Definition at line 1268 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::errorstack, and wkf_tilestack_push.

int wkf_threadpool_wait wkf_threadpool_t   thrpool
 

wait for all worker threads to complete their work

Definition at line 1106 of file WKFThreads.C.

References NULL, wkf_threadpool_struct::runbar, and wkf_thread_run_barrier.

int wkf_threadpool_worker_devscaletile void *    voiddata,
int *    tilesize
 

worker thread calls this to scale max tile size by worker speed as determined by the SM/core count and clock rate

Definition at line 1214 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::devspeed, and NULL.

int wkf_threadpool_worker_getdata void *    voiddata,
void **    clientdata
 

worker thread can call this to get its client data pointer

Definition at line 1230 of file WKFThreads.C.

References NULL, and wkf_threadpool_workerdata_struct::parms.

int wkf_threadpool_worker_getdevid void *    voiddata,
int *    devid
 

worker thread can call this to get its CPU/GPU device ID

Definition at line 1176 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::devid, and NULL.

int wkf_threadpool_worker_getdevspeed void *    voiddata,
float *    speed
 

worker thread calls this to get relative speed of this device as determined by the SM/core count and clock rate

Definition at line 1202 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::devspeed, and NULL.

int wkf_threadpool_worker_getid void *    voiddata,
int *    threadid,
int *    threadcount
 

worker thread can call this to get its ID and number of peers

Definition at line 1163 of file WKFThreads.C.

References NULL, wkf_threadpool_workerdata_struct::threadcount, and wkf_threadpool_workerdata_struct::threadid.

int wkf_threadpool_worker_setdevspeed void *    voiddata,
float    speed
 

worker thread calls this to set relative speed of this device as determined by the SM/core count and clock rate Note: this should only be called once, during the worker's device initialization process

Definition at line 1191 of file WKFThreads.C.

References wkf_threadpool_workerdata_struct::devspeed.

int wkf_tilestack_compact wkf_tilestack_t  
 

shrink memory buffers associated with task tile stack if possible

Definition at line 790 of file WKFThreads.C.

References wkf_tilestack_t::mtx, NULL, wkf_tilestack_t::s, wkf_tilestack_t::size, wkf_tilestack_t::top, wkf_mutex_lock, and wkf_mutex_unlock.

void wkf_tilestack_destroy wkf_tilestack_t  
 

destroy task tile stack

Definition at line 781 of file WKFThreads.C.

References wkf_tilestack_t::mtx, NULL, wkf_tilestack_t::s, and wkf_mutex_destroy.

int wkf_tilestack_empty wkf_tilestack_t  
 

query if the task tile stack is empty or not

Definition at line 881 of file WKFThreads.C.

References wkf_tilestack_t::mtx, wkf_tilestack_t::top, wkf_mutex_lock, and wkf_mutex_unlock.

int wkf_tilestack_init wkf_tilestack_t   s,
int    size
 

initialize task tile stack (to empty)

Definition at line 758 of file WKFThreads.C.

References wkf_tilestack_t::growthrate, wkf_tilestack_t::mtx, NULL, wkf_tilestack_t::s, wkf_tilestack_t::size, wkf_tilestack_t::top, and wkf_mutex_init.

int wkf_tilestack_pop wkf_tilestack_t  ,
wkf_tasktile_t  
 

pop a task tile off of the stack

Definition at line 843 of file WKFThreads.C.

References wkf_tilestack_t::mtx, wkf_tilestack_t::s, wkf_tilestack_t::top, wkf_mutex_lock, wkf_mutex_unlock, and WKF_TILESTACK_EMPTY.

int wkf_tilestack_popall wkf_tilestack_t  
 

pop all of the task tiles off of the stack

Definition at line 866 of file WKFThreads.C.

References wkf_tilestack_t::mtx, wkf_tilestack_t::top, wkf_mutex_lock, and wkf_mutex_unlock.

int wkf_tilestack_push wkf_tilestack_t  ,
const wkf_tasktile_t  
 

push a task tile onto the stack

Definition at line 814 of file WKFThreads.C.

References wkf_tilestack_t::growthrate, wkf_tilestack_t::mtx, NULL, wkf_tilestack_t::s, wkf_tilestack_t::size, wkf_tilestack_t::top, wkf_mutex_lock, and wkf_mutex_unlock.


Generated on Wed May 23 01:50:52 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002