Scippy

SCIP

Solving Constraint Integer Programs

tpi_tnycthrd.c File Reference

Detailed Description

a TPI implementation using tinycthreads

Author
Stephen J. Maher
Robert Lion Gottwald

Definition in file tpi_tnycthrd.c.

#include "tpi/tpi.h"
#include "blockmemshell/memory.h"

Go to the source code of this file.

Typedefs

typedef struct SCIP_ThreadPool SCIP_THREADPOOL
 
typedef struct SCIP_JobQueue SCIP_JOBQUEUE
 

Functions

static int threadPoolThread (void *threadnum)
 
static SCIP_RETCODE createThreadPool (SCIP_THREADPOOL **thrdpool, int nthreads, int qsize, SCIP_Bool blockwhenfull)
 
static void jobQueueAddJob (SCIP_THREADPOOL *threadpool, SCIP_JOB *newjob)
 
static SCIP_RETCODE threadPoolAddWork (SCIP_JOB *newjob, SCIP_SUBMITSTATUS *status)
 
static void freeJobQueue (SCIP_THREADPOOL *thrdpool)
 
static SCIP_RETCODE freeThreadPool (SCIP_THREADPOOL **thrdpool, SCIP_Bool finishjobs, SCIP_Bool completequeue)
 
static SCIP_JOBSTATUS checkJobQueue (SCIP_JOBQUEUE *jobqueue, int jobid)
 
static SCIP_Bool isJobRunning (SCIP_JOBQUEUE *currentjobs, int jobid)
 
int SCIPtpiGetNumThreads (void)
 
SCIP_RETCODE SCIPtpiInit (int nthreads, int queuesize, SCIP_Bool blockwhenfull)
 
SCIP_RETCODE SCIPtpiExit (void)
 
SCIP_RETCODE SCIPtpiCreateJob (SCIP_JOB **job, int jobid, SCIP_RETCODE(*jobfunc)(void *args), void *jobarg)
 
int SCIPtpiGetNewJobID (void)
 
SCIP_RETCODE SCIPtpiSumbitJob (SCIP_JOB *job, SCIP_SUBMITSTATUS *status)
 
SCIP_RETCODE SCIPtpiCollectJobs (int jobid)
 

Typedef Documentation

◆ SCIP_THREADPOOL

Definition at line 28 of file tpi_tnycthrd.c.

◆ SCIP_JOBQUEUE

typedef struct SCIP_JobQueue SCIP_JOBQUEUE

Definition at line 49 of file tpi_tnycthrd.c.

Function Documentation

◆ threadPoolThread()

static int threadPoolThread ( void *  threadnum)
static

this function controls the execution of each of the threads

Parameters
threadnumthread number is passed in as argument stored inside a void pointer

Definition at line 82 of file tpi_tnycthrd.c.

Referenced by createThreadPool().

◆ createThreadPool()

static SCIP_RETCODE createThreadPool ( SCIP_THREADPOOL **  thrdpool,
int  nthreads,
int  qsize,
SCIP_Bool  blockwhenfull 
)
static

creates a threadpool

Parameters
thrdpoolpointer to store threadpool
nthreadsnumber of threads in the threadpool
qsizemaximum size of the jobqueue
blockwhenfullshould the jobqueue block if it is full

Definition at line 209 of file tpi_tnycthrd.c.

References BMSallocMemory, BMSallocMemoryArray, FALSE, NULL, SCIP_ALLOC, SCIP_CALL, SCIP_ERROR, SCIPtpiInitCondition(), SCIPtpiInitLock(), threadPoolThread(), and TRUE.

◆ jobQueueAddJob()

static void jobQueueAddJob ( SCIP_THREADPOOL threadpool,
SCIP_JOB newjob 
)
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.

Definition at line 283 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 SCIPtpiSignalCondition().

◆ threadPoolAddWork()

static SCIP_RETCODE threadPoolAddWork ( SCIP_JOB newjob,
SCIP_SUBMITSTATUS status 
)
static

adds a job to the threadpool

Parameters
newjobjob to add to threadpool
statuspointer to store the job's submit status

Definition at line 315 of file tpi_tnycthrd.c.

References NULL.

◆ freeJobQueue()

static void freeJobQueue ( SCIP_THREADPOOL thrdpool)
static

◆ freeThreadPool()

◆ checkJobQueue()

static SCIP_JOBSTATUS checkJobQueue ( SCIP_JOBQUEUE jobqueue,
int  jobid 
)
static

◆ isJobRunning()

static SCIP_Bool isJobRunning ( SCIP_JOBQUEUE currentjobs,
int  jobid 
)
static

Definition at line 514 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 526 of file tpi_tnycthrd.c.

◆ SCIPtpiInit()

SCIP_RETCODE SCIPtpiInit ( int  nthreads,
int  queuesize,
SCIP_Bool  blockwhenfull 
)

initializes tpi

Parameters
nthreadsthe number of threads to be used
queuesizethe size of the queue
blockwhenfullshould the queue block when full

Definition at line 534 of file tpi_tnycthrd.c.

Referenced by SCIPsyncstoreInit().

◆ SCIPtpiExit()

SCIP_RETCODE SCIPtpiExit ( void  )

deinitializes tpi

Definition at line 546 of file tpi_tnycthrd.c.

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
jobpointer to the job that will be created
jobidthe id for the current job
jobfuncpointer to the job function
jobargthe job's argument

Definition at line 559 of file tpi_tnycthrd.c.

References BMSallocMemory, SCIP_Job::jobfunc, SCIP_Job::jobid, NULL, SCIP_ALLOC, and SCIP_OKAY.

Referenced by SCIPsolveConcurrent().

◆ SCIPtpiGetNewJobID()

int SCIPtpiGetNewJobID ( void  )

get a new job id for the new set of submitted jobs

Definition at line 577 of file tpi_tnycthrd.c.

Referenced by SCIPsolveConcurrent().

◆ SCIPtpiSumbitJob()

SCIP_RETCODE SCIPtpiSumbitJob ( SCIP_JOB job,
SCIP_SUBMITSTATUS status 
)

submit a job for parallel processing the return is a globally defined status

Parameters
jobpointer to the job to be submitted
statuspointer to store the job's submit status

Definition at line 593 of file tpi_tnycthrd.c.

References SCIP_Job::jobid, and NULL.

Referenced by SCIPsolveConcurrent().

◆ 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

if the job has the right jobid collect its retcode, remove it from the finished job list, and free it

Parameters
jobidthe jobid of the jobs to wait for

Definition at line 612 of file tpi_tnycthrd.c.

References SCIP_Job::retcode, SCIP_CALL, and SCIPtpiAcquireLock().

Referenced by SCIPsolveConcurrent().