Detailed Description
a TPI implementation using tinycthreads
Definition in file tpi_tnycthrd.c.
#include "tpi/tpi.h"
#include "blockmemshell/memory.h"
#include "tinycthread/tinycthread.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"
Go to the source code of this file.
Data Structures | |
struct | SCIP_Lock |
struct | SCIP_Condition |
struct | SCIP_Job |
struct | SCIP_JobQueue |
struct | SCIP_ThreadPool |
Macros | |
#define | SCIPtnyInitLock(lock) ( mtx_init((lock), mtx_plain) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
#define | SCIPtnyDestroyLock(lock) ( mtx_destroy(lock) ) |
#define | SCIPtnyAcquireLock(lock) ( mtx_lock(lock) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
#define | SCIPtnyReleaseLock(lock) ( mtx_unlock(lock) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
#define | SCIPtnyInitCondition(condition) ( cnd_init(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
#define | SCIPtnyDestroyCondition(condition) ( cnd_destroy(condition) ) |
#define | SCIPtnySignalCondition(condition) ( cnd_signal(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
#define | SCIPtnyBroadcastCondition(condition) ( cnd_broadcast(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
#define | SCIPtnyWaitCondition(condition, lock) ( cnd_wait((condition), (lock)) == thrd_success ? SCIP_OKAY: SCIP_ERROR ) |
Typedefs | |
typedef struct SCIP_ThreadPool | SCIP_THREADPOOL |
typedef struct SCIP_JobQueue | SCIP_JOBQUEUE |
Macro Definition Documentation
◆ SCIPtnyInitLock
#define SCIPtnyInitLock | ( | lock | ) | ( mtx_init((lock), mtx_plain) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
Definition at line 44 of file tpi_tnycthrd.c.
◆ SCIPtnyDestroyLock
#define SCIPtnyDestroyLock | ( | lock | ) | ( mtx_destroy(lock) ) |
Definition at line 45 of file tpi_tnycthrd.c.
◆ SCIPtnyAcquireLock
#define SCIPtnyAcquireLock | ( | lock | ) | ( mtx_lock(lock) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
Definition at line 46 of file tpi_tnycthrd.c.
◆ SCIPtnyReleaseLock
#define SCIPtnyReleaseLock | ( | lock | ) | ( mtx_unlock(lock) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
Definition at line 47 of file tpi_tnycthrd.c.
◆ SCIPtnyInitCondition
#define SCIPtnyInitCondition | ( | condition | ) | ( cnd_init(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
Definition at line 50 of file tpi_tnycthrd.c.
◆ SCIPtnyDestroyCondition
#define SCIPtnyDestroyCondition | ( | condition | ) | ( cnd_destroy(condition) ) |
Definition at line 51 of file tpi_tnycthrd.c.
◆ SCIPtnySignalCondition
#define SCIPtnySignalCondition | ( | condition | ) | ( cnd_signal(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
Definition at line 52 of file tpi_tnycthrd.c.
◆ SCIPtnyBroadcastCondition
#define SCIPtnyBroadcastCondition | ( | condition | ) | ( cnd_broadcast(condition) == thrd_success ? SCIP_OKAY : SCIP_ERROR ) |
Definition at line 53 of file tpi_tnycthrd.c.
◆ SCIPtnyWaitCondition
#define SCIPtnyWaitCondition | ( | condition, | |
lock | |||
) | ( cnd_wait((condition), (lock)) == thrd_success ? SCIP_OKAY: SCIP_ERROR ) |
Definition at line 54 of file tpi_tnycthrd.c.
Typedef Documentation
◆ SCIP_THREADPOOL
typedef struct SCIP_ThreadPool SCIP_THREADPOOL |
Definition at line 69 of file tpi_tnycthrd.c.
◆ SCIP_JOBQUEUE
typedef struct SCIP_JobQueue SCIP_JOBQUEUE |
Definition at line 90 of file tpi_tnycthrd.c.
Function Documentation
◆ threadPoolThreadRetcode()
|
static |
this function controls the execution of each of the threads
- Parameters
-
threadnum thread number is passed in as argument stored inside a void pointer
Definition at line 123 of file tpi_tnycthrd.c.
Referenced by threadPoolThread().
◆ threadPoolThread()
|
static |
this function controls the execution of each of the threads
- Parameters
-
threadnum thread number is passed in as argument stored inside a void pointer
Definition at line 250 of file tpi_tnycthrd.c.
References threadPoolThreadRetcode().
Referenced by createThreadPool().
◆ createThreadPool()
|
static |
creates a threadpool
- Parameters
-
thrdpool pointer to store threadpool nthreads number of threads in the threadpool qsize maximum size of the jobqueue blockwhenfull should the jobqueue block if it is full
Definition at line 259 of file tpi_tnycthrd.c.
References BMSallocMemory, BMSallocMemoryArray, FALSE, NULL, SCIP_ALLOC, SCIP_CALL, SCIP_ERROR, SCIPtnyInitCondition, SCIPtnyInitLock, threadPoolThread(), and TRUE.
◆ jobQueueAddJob()
|
static |
adding a job to the job queue.
This gives some more flexibility in the handling of new jobs. This function needs to be called from within a mutex.
- Parameters
-
threadpool pointer to store threadpool newjob pointer to new job
Definition at line 335 of file tpi_tnycthrd.c.
References SCIP_JobQueue::firstjob, SCIP_ThreadPool::jobqueue, SCIP_JobQueue::lastjob, SCIP_Job::nextjob, SCIP_JobQueue::njobs, NULL, SCIP_ThreadPool::queuenotempty, SCIP_ThreadPool::queuesize, SCIP_CALL_ABORT, and SCIPtnySignalCondition.
◆ threadPoolAddWork()
|
static |
adds a job to the threadpool
- Parameters
-
newjob job to add to threadpool status pointer to store the job's submit status
Definition at line 367 of file tpi_tnycthrd.c.
References NULL.
◆ freeJobQueue()
|
static |
frees the jobqueue of the threadpool
- Parameters
-
thrdpool pointer to thread pool
Definition at line 424 of file tpi_tnycthrd.c.
References BMSfreeMemory, SCIP_JobQueue::firstjob, SCIP_ThreadPool::jobqueue, SCIP_JobQueue::lastjob, SCIP_Job::nextjob, NULL, SCIP_ThreadPool::queueopen, and SCIP_ThreadPool::shutdown.
Referenced by freeThreadPool().
◆ freeThreadPool()
|
static |
free the thread pool
- Parameters
-
thrdpool pointer to thread pool finishjobs currently unused completequeue Wait until the queue has complete?
Definition at line 449 of file tpi_tnycthrd.c.
References BMSfreeMemory, BMSfreeMemoryArray, FALSE, freeJobQueue(), MIN, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, SCIP_UNUSED, SCIPtnyAcquireLock, SCIPtnyBroadcastCondition, SCIPtnyDestroyCondition, SCIPtnyDestroyLock, SCIPtnyReleaseLock, SCIPtnyWaitCondition, and TRUE.
◆ checkJobQueue()
|
static |
- Parameters
-
jobqueue pointer to the job queue jobid id of job to check
Definition at line 535 of file tpi_tnycthrd.c.
References SCIP_JobQueue::firstjob, SCIP_Job::jobid, SCIP_JobQueue::lastjob, SCIP_Job::nextjob, NULL, SCIP_JOB_DOESNOTEXIST, and SCIP_JOB_INQUEUE.
Referenced by isJobRunning().
◆ isJobRunning()
|
static |
returns whether the job id is running
- Parameters
-
currentjobs queue of current jobs jobid id of job to check
Definition at line 562 of file tpi_tnycthrd.c.
References checkJobQueue(), FALSE, SCIP_JOB_INQUEUE, and TRUE.
◆ SCIPtpiGetNumThreads()
int SCIPtpiGetNumThreads | ( | void | ) |
returns the number of threads
Definition at line 574 of file tpi_tnycthrd.c.
◆ SCIPtpiInit()
SCIP_RETCODE SCIPtpiInit | ( | int | nthreads, |
int | queuesize, | ||
SCIP_Bool | blockwhenfull | ||
) |
initializes tpi
- Parameters
-
nthreads the number of threads to be used queuesize the size of the queue blockwhenfull should the queue block when full
Definition at line 582 of file tpi_tnycthrd.c.
References SCIP_ERROR, and SCIP_UNUSED.
Referenced by SCIPsyncstoreInit().
◆ SCIPtpiExit()
SCIP_RETCODE SCIPtpiExit | ( | void | ) |
deinitializes tpi
Definition at line 594 of file tpi_tnycthrd.c.
References SCIP_ERROR.
Referenced by SCIPsyncstoreExit().
◆ SCIPtpiCreateJob()
SCIP_RETCODE SCIPtpiCreateJob | ( | SCIP_JOB ** | job, |
int | jobid, | ||
SCIP_RETCODE(*)(void *args) | jobfunc, | ||
void * | jobarg | ||
) |
creates a job for parallel processing
- Parameters
-
job pointer to the job that will be created jobid the id for the current job jobfunc pointer to the job function jobarg the job's argument
Definition at line 606 of file tpi_tnycthrd.c.
References BMSallocMemory, NULL, SCIP_ALLOC, SCIP_ERROR, SCIP_OKAY, and SCIP_UNUSED.
Referenced by SCIPconcurrentSolve().
◆ SCIPtpiGetNewJobID()
int SCIPtpiGetNewJobID | ( | void | ) |
get a new job id for the new set of submitted jobs
Definition at line 624 of file tpi_tnycthrd.c.
Referenced by SCIPconcurrentSolve().
◆ SCIPtpiSubmitJob()
SCIP_RETCODE SCIPtpiSubmitJob | ( | SCIP_JOB * | job, |
SCIP_SUBMITSTATUS * | status | ||
) |
submit a job for parallel processing; the return value is a globally defined status
- Parameters
-
job pointer to the job to be submitted status pointer to store the job's submit status
Definition at line 639 of file tpi_tnycthrd.c.
References SCIP_Job::jobid, NULL, SCIP_ERROR, and SCIP_UNUSED.
Referenced by SCIPconcurrentSolve().
◆ SCIPtpiCollectJobs()
SCIP_RETCODE SCIPtpiCollectJobs | ( | int | jobid | ) |
blocks until all jobs of the given jobid have finished and then returns the smallest SCIP_RETCODE of all the jobs
- Parameters
-
jobid the jobid of the jobs to wait for
Definition at line 656 of file tpi_tnycthrd.c.
References SCIP_CALL, SCIP_ERROR, SCIP_UNUSED, and SCIPtnyAcquireLock.
Referenced by SCIPconcurrentSolve().
◆ SCIPtpiInitLock()
SCIP_RETCODE SCIPtpiInitLock | ( | SCIP_LOCK ** | lock | ) |
initializes the given lock
- Parameters
-
lock the lock
Definition at line 727 of file tpi_tnycthrd.c.
References BMSallocMemory, BMSfreeMemory, NULL, SCIP_ALLOC, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreCreate(), and SCIPsyncstoreInit().
◆ SCIPtpiDestroyLock()
void SCIPtpiDestroyLock | ( | SCIP_LOCK ** | lock | ) |
destroys the given lock
- Parameters
-
lock the lock
Definition at line 745 of file tpi_tnycthrd.c.
References BMSfreeMemory, and NULL.
Referenced by SCIPsyncstoreExit(), and SCIPsyncstoreRelease().
◆ SCIPtpiAcquireLock()
SCIP_RETCODE SCIPtpiAcquireLock | ( | SCIP_LOCK * | lock | ) |
acquires the given lock
- Parameters
-
lock the lock
Definition at line 756 of file tpi_tnycthrd.c.
References SCIP_Lock::lock, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreCapture(), SCIPsyncstoreEnsureAllSynced(), SCIPsyncstoreRelease(), SCIPsyncstoreSetSolveIsStopped(), SCIPsyncstoreSolveIsStopped(), and SCIPsyncstoreStartSync().
◆ SCIPtpiReleaseLock()
SCIP_RETCODE SCIPtpiReleaseLock | ( | SCIP_LOCK * | lock | ) |
releases the given lock
- Parameters
-
lock the lock
Definition at line 766 of file tpi_tnycthrd.c.
References SCIP_Lock::lock, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreCapture(), SCIPsyncstoreEnsureAllSynced(), SCIPsyncstoreFinishSync(), SCIPsyncstoreRelease(), SCIPsyncstoreSetSolveIsStopped(), and SCIPsyncstoreSolveIsStopped().
◆ SCIPtpiInitCondition()
SCIP_RETCODE SCIPtpiInitCondition | ( | SCIP_CONDITION ** | condition | ) |
initializes the given condition variable
- Parameters
-
condition condition to be created and initialized
Definition at line 781 of file tpi_tnycthrd.c.
References BMSallocMemory, NULL, SCIP_ALLOC, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreInit().
◆ SCIPtpiDestroyCondition()
void SCIPtpiDestroyCondition | ( | SCIP_CONDITION ** | condition | ) |
destroys the given condition variable
- Parameters
-
condition condition to be destroyed and freed
Definition at line 795 of file tpi_tnycthrd.c.
References BMSfreeMemory, and NULL.
Referenced by SCIPsyncstoreExit().
◆ SCIPtpiSignalCondition()
SCIP_RETCODE SCIPtpiSignalCondition | ( | SCIP_CONDITION * | condition | ) |
signals one waiting thread
- Parameters
-
condition the condition variable to signal
Definition at line 804 of file tpi_tnycthrd.c.
References SCIP_Condition::condition, SCIP_ERROR, and SCIP_OKAY.
◆ SCIPtpiBroadcastCondition()
SCIP_RETCODE SCIPtpiBroadcastCondition | ( | SCIP_CONDITION * | condition | ) |
signals all waiting threads
- Parameters
-
condition the condition variable to broadcast
Definition at line 815 of file tpi_tnycthrd.c.
References SCIP_Condition::condition, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreFinishSync().
◆ SCIPtpiWaitCondition()
SCIP_RETCODE SCIPtpiWaitCondition | ( | SCIP_CONDITION * | condition, |
SCIP_LOCK * | lock | ||
) |
waits on a condition variable. The given lock must be held by the caller and will be held when this function returns.
- Parameters
-
condition the condition variable to wait on lock the lock that is held by the caller
Definition at line 827 of file tpi_tnycthrd.c.
References SCIP_Condition::condition, SCIP_Lock::lock, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreEnsureAllSynced().
◆ SCIPtpiGetThreadNum()
int SCIPtpiGetThreadNum | ( | void | ) |
returns the thread number
Definition at line 838 of file tpi_tnycthrd.c.
Referenced by applyBoundChanges(), and execConcsolver().
◆ SCIPtpiIsAvailable()
SCIP_Bool SCIPtpiIsAvailable | ( | void | ) |
indicate whether a working TPI is available
Definition at line 846 of file tpi_tnycthrd.c.
Referenced by doScipCreate(), and SCIPsolveConcurrent().
◆ SCIPtpiGetLibraryName()
void SCIPtpiGetLibraryName | ( | char * | name, |
int | namesize | ||
) |
get name of library that the TPI interfaces to
- Parameters
-
name buffer to store name namesize length of name buffer
Definition at line 852 of file tpi_tnycthrd.c.
References NULL, and SCIPsnprintf().
Referenced by doScipCreate().
◆ SCIPtpiGetLibraryDesc()
void SCIPtpiGetLibraryDesc | ( | char * | desc, |
int | descsize | ||
) |
get description of library that the TPI interfaces to
- Parameters
-
desc buffer to store description descsize length of description
Definition at line 863 of file tpi_tnycthrd.c.
References NULL, and SCIPsnprintf().
Referenced by doScipCreate().