#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "WKFThreads.h"
Go to the source code of this file.
Code for spawning threads on various platforms. Code donated by John Stone, john.stone@gmail.com This code was originally written for the Tachyon Parallel/Multiprocessor Ray Tracer. Improvements have been donated by Mr. Stone on an ongoing basis. This code is provided under the three clause BSD Open Source License.
NOTE: The latest version of this source file can be re-generated by running the sequence of 'sed' commands shown at the top of the "threads.c" file within the Tachyon source distribution.
Definition in file WKFThreads.C.
Definition at line 244 of file WKFThreads.C.
Typedef to eliminate compiler warning caused by C/C++ linkage conflict.
Definition at line 653 of file WKFThreads.C.
Referenced by wkf_thread_create.
fetch an atomic int and add inc to it, returning new value
Definition at line 1190 of file WKFThreads.C.
References atomic_int_struct::lock, atomic_int_struct::val, wkf_mutex_lock, and wkf_mutex_unlock.
destroy an atomic int variable
Definition at line 1076 of file WKFThreads.C.
References atomic_int_struct::lock, and wkf_mutex_destroy.
fetch an atomic int and add inc to it, returning original value
Definition at line 1162 of file WKFThreads.C.
References atomic_int_struct::lock, atomic_int_struct::val, wkf_mutex_lock, and wkf_mutex_unlock.
get an atomic int variable
Definition at line 1133 of file WKFThreads.C.
References atomic_int_struct::lock, atomic_int_struct::val, wkf_mutex_lock, and wkf_mutex_unlock.
initialize an atomic int variable
Definition at line 1053 of file WKFThreads.C.
References atomic_int_struct::lock, atomic_int_struct::val, and wkf_mutex_init.
set an atomic int variable
Definition at line 1097 of file WKFThreads.C.
References atomic_int_struct::lock, atomic_int_struct::val, wkf_mutex_lock, and wkf_mutex_unlock.
signal a condition variable, waking all threads
Definition at line 1013 of file WKFThreads.C.
References wkf_cond_t.
initialize a condition variable
Definition at line 862 of file WKFThreads.C.
References NULL, and wkf_cond_t.
signal a condition variable, waking at least one thread
Definition at line 981 of file WKFThreads.C.
References wkf_cond_t.
wait on a condition variable
Definition at line 922 of file WKFThreads.C.
References result, wkf_cond_t, and wkf_mutex_t.
query CPU affinity of the calling process (if allowed by host system)
Definition at line 493 of file WKFThreads.C.
References NULL.
CPU optional instruction set capability flags
Definition at line 292 of file WKFThreads.C.
References CPU_ARM64_AES, CPU_ARM64_ASIMD, CPU_ARM64_ASIMDDP, CPU_ARM64_ASIMDFHM, CPU_ARM64_ASIMDHP, CPU_ARM64_ASIMDRDM, CPU_ARM64_CRC32, CPU_ARM64_FP, CPU_ARM64_SHA1, CPU_ARM64_SHA2, CPU_ARM64_SHA3, CPU_ARM64_SHA512, CPU_ARM64_SVE, CPU_AVX, CPU_AVX2, CPU_AVX512CD, CPU_AVX512ER, CPU_AVX512F, CPU_AVX512PF, CPU_F16C, CPU_FMA, CPU_HT, CPU_HYPERVISOR, CPU_SMTDEPTH_UNKNOWN, CPU_SSE2, CPU_SSE4_1, CPU_UNKNOWN, wkf_cpu_caps_struct::flags, and wkf_cpu_caps_struct::smtdepth.
Definition at line 476 of file WKFThreads.C.
References CPU_SMTDEPTH_UNKNOWN, wkf_cpu_caps_struct::smtdepth, and wkf_cpu_capability_flags.
initialize a reader/writer lock
Definition at line 1222 of file WKFThreads.C.
References NULL, wkf_cond_init, wkf_mutex_init, and wkf_rwlock_t.
set reader lock
Definition at line 1251 of file WKFThreads.C.
References wkf_cond_wait, wkf_mutex_lock, wkf_mutex_unlock, and wkf_rwlock_t.
unlock reader/writer lock
Definition at line 1315 of file WKFThreads.C.
References wkf_cond_signal, wkf_mutex_lock, wkf_mutex_unlock, and wkf_rwlock_t.
set writer lock
Definition at line 1280 of file WKFThreads.C.
References wkf_cond_wait, wkf_mutex_lock, wkf_mutex_unlock, and wkf_rwlock_t.
destroy a shared iterator
Definition at line 1720 of file WKFThreads.C.
References it, wkf_shared_iterator_struct::mtx, and wkf_mutex_destroy.
master thread calls this to query for fatal errors
Definition at line 1795 of file WKFThreads.C.
References wkf_shared_iterator_struct::fatalerror, it, wkf_shared_iterator_struct::mtx, wkf_mutex_lock, and wkf_mutex_unlock.
initialize a shared iterator
Definition at line 1710 of file WKFThreads.C.
References it, wkf_shared_iterator_struct::mtx, and wkf_mutex_init.
iterate the shared iterator, over a requested half-open interval
Definition at line 1746 of file WKFThreads.C.
References wkf_shared_iterator_struct::current, wkf_shared_iterator_struct::end, wkf_tasktile_struct::end, wkf_shared_iterator_struct::fatalerror, it, wkf_shared_iterator_struct::mtx, wkf_tasktile_struct::start, wkf_mutex_spin_lock, wkf_mutex_unlock, WKF_SCHED_CONTINUE, and WKF_SCHED_DONE.
set shared iterator parameters
Definition at line 1729 of file WKFThreads.C.
References wkf_shared_iterator_struct::current, wkf_tasktile_struct::end, wkf_shared_iterator_struct::end, wkf_shared_iterator_struct::fatalerror, it, wkf_shared_iterator_struct::mtx, wkf_tasktile_struct::start, wkf_shared_iterator_struct::start, wkf_mutex_lock, and wkf_mutex_unlock.
worker thread calls this to indicate a fatal error
Definition at line 1782 of file WKFThreads.C.
References wkf_shared_iterator_struct::fatalerror, it, wkf_shared_iterator_struct::mtx, wkf_mutex_spin_lock, and wkf_mutex_unlock.
synchronize on counting barrier primitive
Definition at line 1435 of file WKFThreads.C.
References barrier_struct::lock, barrier_struct::n_clients, barrier_struct::n_waiting, barrier_struct::phase, barrier_struct::result, barrier_struct::sum, barrier_struct::wait_cv, wkf_cond_broadcast, wkf_cond_wait, wkf_mutex_lock, and wkf_mutex_unlock.
destroy counting barrier primitive
Definition at line 1426 of file WKFThreads.C.
References barrier_struct::lock, barrier_struct::wait_cv, wkf_cond_destroy, and wkf_mutex_destroy.
initialize counting barrier primitive
Definition at line 1365 of file WKFThreads.C.
References barrier_struct::lock, barrier_struct::n_clients, barrier_struct::n_waiting, NULL, barrier_struct::phase, barrier_struct::sum, barrier_struct::wait_cv, wkf_cond_init, and wkf_mutex_init.
When rendering in the CAVE we use a special synchronization mode so that shared memory mutexes and condition variables will work correctly when accessed from multiple processes. Inter-process synchronization involves the kernel to a greater degree, so these barriers are substantially more costly to use than the ones designed for use within a single-process.
Definition at line 1389 of file WKFThreads.C.
References barrier_struct::lock, barrier_struct::n_clients, barrier_struct::n_waiting, NULL, barrier_struct::phase, barrier_struct::sum, and barrier_struct::wait_cv.
create a new child thread
Definition at line 655 of file WKFThreads.C.
References NULL, wkf_thread_t, and WKFTHREAD_START_ROUTINE.
join (wait for completion of, and merge with) a thread
Definition at line 698 of file WKFThreads.C.
References NULL, and wkf_thread_t.
If compiling on Linux, enable the GNU CPU affinity functions in both libc and the libpthreads
Definition at line 120 of file WKFThreads.C.
References NULL.
Referenced by affinitize_threads, vmd_cuda_affinitize_threads, and wkf_thread_numprocessors.
number of processors available, subject to user override
Definition at line 208 of file WKFThreads.C.
References NULL, and wkf_thread_numphysprocessors.
Referenced by Orbital::calculate_mo, cc_threaded, find_next_cluster, find_within, measure_gofr, measure_rmsdmat_qcp, measure_rmsdmat_qcp_ooc, measure_sasalist, vmd_bondsearch_thr, vmd_cuda_vol_cpotential, vmd_gaussdensity_threaded, vmdinfo_tcl, VMDApp::VMDinit, vol_cpotential_cpu, volin_threaded, and volin_threaded_prob.
Wait until all threads reach barrier, and return the function pointer passed in by the master thread.
Definition at line 1500 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.
destroy thread pool barrier
Definition at line 1488 of file WKFThreads.C.
References wkf_run_barrier_struct::lock, wkf_run_barrier_struct::wait_cv, wkf_cond_destroy, and wkf_mutex_destroy.
initialize thread pool barrier
Definition at line 1472 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.
non-blocking poll to see if peers are already at the barrier
Definition at line 1546 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.
set the CPU affinity of the current thread (if allowed by host system)
Definition at line 582 of file WKFThreads.C.
set the concurrency level and scheduling scope for threads
Definition at line 628 of file WKFThreads.C.
launch up to numprocs threads using shared iterator as a load balancer
Definition at line 2095 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.
worker thread can call this to get its client data pointer
Definition at line 2185 of file WKFThreads.C.
References wkf_threadlaunch_struct::clientdata, and NULL.
worker thread can call this to get its ID and number of peers
Definition at line 2172 of file WKFThreads.C.
References NULL, wkf_threadlaunch_struct::threadcount, and wkf_threadlaunch_struct::threadid.
iterate the shared iterator over the requested half-open interval
Definition at line 2195 of file WKFThreads.C.
References wkf_threadlaunch_struct::iter, and wkf_shared_iterator_next_tile.
worker thread calls this to indicate that an unrecoverable error occured
Definition at line 2203 of file WKFThreads.C.
References wkf_threadlaunch_struct::iter, and wkf_shared_iterator_setfatalerror.
create a thread pool with a specified number of worker threads
Definition at line 1832 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.
join all worker threads and free resources
Definition at line 1927 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.
return the number of worker threads currently in the pool
Definition at line 1961 of file WKFThreads.C.
References wkf_threadpool_struct::workercount.
master thread calls this to query for fatal errors
Definition at line 2087 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::iter, and wkf_shared_iterator_getfatalerror.
launch threads onto a new function, with associated parms
Definition at line 1892 of file WKFThreads.C.
References NULL, wkf_threadpool_workerdata_struct::parms, wkf_threadpool_struct::runbar, wkf_thread_run_barrier, and wkf_threadpool_struct::workerdata.
iterate the shared iterator over the requested half-open interval
Definition at line 2052 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.
Definition at line 1918 of file WKFThreads.C.
References wkf_threadpool_struct::runbar, and wkf_thread_run_barrier_poll.
Set shared iterator state to half-open interval defined by tile
Definition at line 2044 of file WKFThreads.C.
References wkf_threadpool_struct::iter, NULL, and wkf_shared_iterator_set.
worker thread calls this to indicate that an unrecoverable error occured
Definition at line 2079 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::iter, and wkf_shared_iterator_setfatalerror.
worker thread calls this when a failure occurs on a tile it has already taken from the scheduler
Definition at line 2072 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::errorstack, and wkf_tilestack_push.
wait for all worker threads to complete their work
Definition at line 1910 of file WKFThreads.C.
References NULL, wkf_threadpool_struct::runbar, and wkf_thread_run_barrier.
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 2018 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::devspeed, and NULL.
worker thread can call this to get its client data pointer
Definition at line 2034 of file WKFThreads.C.
References NULL, and wkf_threadpool_workerdata_struct::parms.
worker thread can call this to get its CPU/GPU device ID
Definition at line 1980 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::devid, and NULL.
worker thread calls this to get relative speed of this device as determined by the SM/core count and clock rate
Definition at line 2006 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::devspeed, and NULL.
worker thread can call this to get its ID and number of peers
Definition at line 1967 of file WKFThreads.C.
References NULL, wkf_threadpool_workerdata_struct::threadcount, and wkf_threadpool_workerdata_struct::threadid.
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 1995 of file WKFThreads.C.
References wkf_threadpool_workerdata_struct::devspeed.
shrink memory buffers associated with task tile stack if possible
Definition at line 1594 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.
destroy task tile stack
Definition at line 1585 of file WKFThreads.C.
References wkf_tilestack_t::mtx, NULL, wkf_tilestack_t::s, and wkf_mutex_destroy.
query if the task tile stack is empty or not
Definition at line 1685 of file WKFThreads.C.
References wkf_tilestack_t::mtx, wkf_tilestack_t::top, wkf_mutex_lock, and wkf_mutex_unlock.
initialize task tile stack (to empty)
Definition at line 1562 of file WKFThreads.C.
References wkf_tilestack_t::growthrate, wkf_tilestack_t::mtx, NULL, wkf_tilestack_t::s, wkf_tilestack_t::size, size, wkf_tilestack_t::top, and wkf_mutex_init.
pop a task tile off of the stack
Definition at line 1647 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.
pop all of the task tiles off of the stack
Definition at line 1670 of file WKFThreads.C.
References wkf_tilestack_t::mtx, wkf_tilestack_t::top, wkf_mutex_lock, and wkf_mutex_unlock.
push a task tile onto the stack
Definition at line 1618 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.