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) |
#define | SCIPtnyDestroyLock(lock) |
#define | SCIPtnyAcquireLock(lock) |
#define | SCIPtnyReleaseLock(lock) |
#define | SCIPtnyInitCondition(condition) |
#define | SCIPtnyDestroyCondition(condition) |
#define | SCIPtnySignalCondition(condition) |
#define | SCIPtnyBroadcastCondition(condition) |
#define | SCIPtnyWaitCondition(condition, lock) |
#define SCIPtnyInitLock | ( | lock | ) |
Definition at line 44 of file tpi_tnycthrd.c.
Referenced by createThreadPool().
#define SCIPtnyDestroyLock | ( | lock | ) |
Definition at line 45 of file tpi_tnycthrd.c.
Referenced by freeThreadPool().
#define SCIPtnyAcquireLock | ( | lock | ) |
Definition at line 46 of file tpi_tnycthrd.c.
Referenced by freeThreadPool(), SCIPtpiCollectJobs(), SCIPtpiGetNewJobID(), threadPoolAddWork(), and threadPoolThreadRetcode().
#define SCIPtnyReleaseLock | ( | lock | ) |
Definition at line 47 of file tpi_tnycthrd.c.
Referenced by freeThreadPool(), SCIPtpiCollectJobs(), SCIPtpiGetNewJobID(), threadPoolAddWork(), and threadPoolThreadRetcode().
#define SCIPtnyInitCondition | ( | condition | ) |
Definition at line 50 of file tpi_tnycthrd.c.
Referenced by createThreadPool().
#define SCIPtnyDestroyCondition | ( | condition | ) |
Definition at line 51 of file tpi_tnycthrd.c.
Referenced by freeThreadPool().
#define SCIPtnySignalCondition | ( | condition | ) |
Definition at line 52 of file tpi_tnycthrd.c.
Referenced by jobQueueAddJob().
#define SCIPtnyBroadcastCondition | ( | condition | ) |
Definition at line 53 of file tpi_tnycthrd.c.
Referenced by freeThreadPool(), and threadPoolThreadRetcode().
#define SCIPtnyWaitCondition | ( | condition, | |
lock ) |
Definition at line 54 of file tpi_tnycthrd.c.
Referenced by freeThreadPool(), SCIPtpiCollectJobs(), threadPoolAddWork(), and threadPoolThreadRetcode().
typedef struct SCIP_ThreadPool SCIP_THREADPOOL |
Definition at line 69 of file tpi_tnycthrd.c.
|
static |
this function controls the execution of each of the threads
threadnum | thread number is passed in as argument stored inside a void pointer |
Definition at line 123 of file tpi_tnycthrd.c.
References SCIP_Job::args, SCIP_Job::jobfunc, SCIP_Job::nextjob, NULL, SCIP_Job::retcode, SCIP_CALL, SCIP_OKAY, SCIPtnyAcquireLock, SCIPtnyBroadcastCondition, SCIPtnyReleaseLock, SCIPtnyWaitCondition, and TRUE.
Referenced by threadPoolThread().
|
static |
this function controls the execution of each of the threads
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().
|
static |
creates a threadpool
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 assert(), BMSallocMemory, BMSallocMemoryArray, FALSE, i, NULL, SCIP_ALLOC, SCIP_Bool, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, SCIPtnyInitCondition, SCIPtnyInitLock, threadPoolThread(), and TRUE.
Referenced by SCIPtpiInit().
|
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.
threadpool | pointer to store threadpool |
newjob | pointer to new job |
Definition at line 335 of file tpi_tnycthrd.c.
References assert(), 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.
Referenced by threadPoolAddWork().
|
static |
adds a job to the threadpool
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 assert(), jobQueueAddJob(), SCIP_Job::nextjob, NULL, SCIP_CALL, SCIP_OKAY, SCIP_SUBMIT_QUEUECLOSED, SCIP_SUBMIT_QUEUEFULL, SCIP_SUBMIT_SHUTDOWN, SCIP_SUBMIT_SUCCESS, SCIPtnyAcquireLock, SCIPtnyReleaseLock, and SCIPtnyWaitCondition.
Referenced by SCIPtpiSubmitJob().
|
static |
frees the jobqueue of the threadpool
thrdpool | pointer to thread pool |
Definition at line 424 of file tpi_tnycthrd.c.
References assert(), BMSfreeMemory, SCIP_JobQueue::firstjob, SCIP_ThreadPool::jobqueue, SCIP_JobQueue::lastjob, SCIP_Job::nextjob, NULL, SCIP_ThreadPool::queueopen, and SCIP_ThreadPool::shutdown.
|
static |
free the thread pool
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 assert(), BMSfreeMemory, BMSfreeMemoryArray, FALSE, freeJobQueue(), i, MIN, SCIP_Bool, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, SCIP_UNUSED, SCIPtnyAcquireLock, SCIPtnyBroadcastCondition, SCIPtnyDestroyCondition, SCIPtnyDestroyLock, SCIPtnyReleaseLock, SCIPtnyWaitCondition, and TRUE.
Referenced by SCIPtpiExit().
|
static |
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().
|
static |
returns whether the job id is running
currentjobs | queue of current jobs |
jobid | id of job to check |
Definition at line 562 of file tpi_tnycthrd.c.
References checkJobQueue(), FALSE, SCIP_Bool, SCIP_JOB_INQUEUE, and TRUE.
Referenced by SCIPtpiCollectJobs().
int SCIPtpiGetNumThreads | ( | void | ) |
returns the number of threads
Definition at line 574 of file tpi_tnycthrd.c.
References NULL.
Referenced by jobQueueAddJob(), and jobQueueProcessJob().
SCIP_RETCODE SCIPtpiInit | ( | int | nthreads, |
int | queuesize, | ||
SCIP_Bool | blockwhenfull ) |
initializes tpi
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 assert(), createThreadPool(), NULL, SCIP_Bool, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, and SCIP_UNUSED.
Referenced by SCIPsyncstoreInit().
SCIP_RETCODE SCIPtpiExit | ( | void | ) |
deinitializes tpi
Definition at line 594 of file tpi_tnycthrd.c.
References assert(), freeThreadPool(), NULL, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, and TRUE.
Referenced by SCIPsyncstoreExit().
SCIP_RETCODE SCIPtpiCreateJob | ( | SCIP_JOB ** | job, |
int | jobid, | ||
SCIP_RETCODE(* | jobfunc )(void *args), | ||
void * | jobarg ) |
creates a job for parallel processing
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().
int SCIPtpiGetNewJobID | ( | void | ) |
get a new job id for the new set of submitted jobs
Definition at line 624 of file tpi_tnycthrd.c.
References assert(), NULL, SCIP_CALL_ABORT, SCIPtnyAcquireLock, and SCIPtnyReleaseLock.
Referenced by SCIPconcurrentSolve().
SCIP_RETCODE SCIPtpiSubmitJob | ( | SCIP_JOB * | job, |
SCIP_SUBMITSTATUS * | status ) |
submit a job for parallel processing; the return value is a globally defined status
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 assert(), SCIP_Job::jobid, NULL, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, SCIP_UNUSED, and threadPoolAddWork().
Referenced by SCIPconcurrentSolve().
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
jobid | the jobid of the jobs to wait for |
Definition at line 656 of file tpi_tnycthrd.c.
References assert(), BMSfreeMemory, isJobRunning(), isJobRunning(), SCIP_Job::jobid, MIN, SCIP_Job::nextjob, NULL, SCIP_Job::retcode, SCIP_CALL, SCIP_ERROR, SCIP_OKAY, SCIP_UNUSED, SCIPtnyAcquireLock, SCIPtnyReleaseLock, and SCIPtnyWaitCondition.
Referenced by SCIPconcurrentSolve().
SCIP_RETCODE SCIPtpiInitLock | ( | SCIP_LOCK ** | lock | ) |
initializes the given lock
lock | the lock |
Definition at line 727 of file tpi_tnycthrd.c.
References assert(), BMSallocMemory, BMSfreeMemory, NULL, SCIP_ALLOC, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreCreate(), and SCIPsyncstoreInit().
void SCIPtpiDestroyLock | ( | SCIP_LOCK ** | lock | ) |
destroys the given lock
lock | the lock |
Definition at line 745 of file tpi_tnycthrd.c.
References assert(), BMSfreeMemory, and NULL.
Referenced by SCIPsyncstoreExit(), and SCIPsyncstoreRelease().
SCIP_RETCODE SCIPtpiAcquireLock | ( | SCIP_LOCK * | lock | ) |
acquires the given lock
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().
SCIP_RETCODE SCIPtpiReleaseLock | ( | SCIP_LOCK * | lock | ) |
releases the given lock
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().
SCIP_RETCODE SCIPtpiInitCondition | ( | SCIP_CONDITION ** | condition | ) |
initializes the given condition variable
condition | condition to be created and initialized |
Definition at line 781 of file tpi_tnycthrd.c.
References assert(), BMSallocMemory, NULL, SCIP_ALLOC, SCIP_ERROR, and SCIP_OKAY.
Referenced by SCIPsyncstoreInit().
void SCIPtpiDestroyCondition | ( | SCIP_CONDITION ** | condition | ) |
destroys the given condition variable
condition | condition to be destroyed and freed |
Definition at line 795 of file tpi_tnycthrd.c.
References assert(), BMSfreeMemory, and NULL.
Referenced by SCIPsyncstoreExit().
SCIP_RETCODE SCIPtpiSignalCondition | ( | SCIP_CONDITION * | condition | ) |
signals one waiting thread
condition | the condition variable to signal |
Definition at line 804 of file tpi_tnycthrd.c.
References SCIP_Condition::condition, SCIP_ERROR, and SCIP_OKAY.
SCIP_RETCODE SCIPtpiBroadcastCondition | ( | SCIP_CONDITION * | condition | ) |
signals all waiting threads
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().
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.
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().
int SCIPtpiGetThreadNum | ( | void | ) |
returns the thread number
Definition at line 838 of file tpi_tnycthrd.c.
Referenced by applyBoundChanges().
SCIP_Bool SCIPtpiIsAvailable | ( | void | ) |
indicate whether a working TPI is available
Definition at line 846 of file tpi_tnycthrd.c.
References FALSE, SCIP_Bool, and TRUE.
Referenced by doScipCreate(), and SCIPsolveConcurrent().
void SCIPtpiGetLibraryName | ( | char * | name, |
int | namesize ) |
get name of library that the TPI interfaces to
name | buffer to store name |
namesize | length of name buffer |
Definition at line 852 of file tpi_tnycthrd.c.
References assert(), NULL, and SCIPsnprintf().
Referenced by doScipCreate().
void SCIPtpiGetLibraryDesc | ( | char * | desc, |
int | descsize ) |
get description of library that the TPI interfaces to
desc | buffer to store description |
descsize | length of description |
Definition at line 863 of file tpi_tnycthrd.c.
References assert(), NULL, and SCIPsnprintf().
Referenced by doScipCreate().