Scippy

SCIP

Solving Constraint Integer Programs

tpi_openmp.c File Reference

Detailed Description

the interface functions for openmp

Author
Stephen J. Maher
Leona Gottwald
Marc Pfetsch

Definition in file tpi_openmp.c.

#include "tpi/tpi.h"
#include "blockmemshell/memory.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"
#include <omp.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_JobQueues
 

Macros

#define SCIPompInitLock(lock)   (omp_init_lock(lock), SCIP_OKAY)
 
#define SCIPompDestroyLock(lock)   (omp_destroy_lock(lock))
 
#define SCIPompAcquireLock(lock)   (omp_set_lock(lock), SCIP_OKAY)
 
#define SCIPompReleaseLock(lock)   (omp_unset_lock(lock), SCIP_OKAY)
 
#define SCIPompInitCondition(condition)
 
#define SCIPompDestroyCondition(condition)   do { assert((condition)->_waiters == 0); assert((condition)->_waitnum == 0); assert((condition)->_signals == 0); omp_destroy_lock(&(condition)->_lock); } while(0)
 

Typedefs

typedef struct SCIP_JobQueue SCIP_JOBQUEUE
 
typedef struct SCIP_JobQueues SCIP_JOBQUEUES
 

Functions

static SCIP_RETCODE createJobQueue (int nthreads, int qsize, SCIP_Bool blockwhenfull)
 
static SCIP_RETCODE freeJobQueue (void)
 
static void executeJob (SCIP_JOB *job)
 
SCIP_RETCODE SCIPtpiWaitCondition (SCIP_CONDITION *condition, SCIP_LOCK *lock)
 
static SCIP_RETCODE SCIPompWaitCondition (SCIP_CONDITION *condition, omp_lock_t *lock)
 
static void jobQueueProcessJob (void)
 
static SCIP_RETCODE jobQueueAddJob (SCIP_JOB *newjob)
 
SCIP_RETCODE SCIPtpiSignalCondition (SCIP_CONDITION *condition)
 
SCIP_RETCODE SCIPtpiBroadcastCondition (SCIP_CONDITION *condition)
 
int SCIPtpiGetNumThreads ()
 
int SCIPtpiGetThreadNum ()
 
SCIP_RETCODE SCIPtpiCreateJob (SCIP_JOB **job, int jobid, SCIP_RETCODE(*jobfunc)(void *args), void *jobarg)
 
int SCIPtpiGetNewJobID (void)
 
SCIP_RETCODE SCIPtpiSubmitJob (SCIP_JOB *job, SCIP_SUBMITSTATUS *status)
 
static SCIP_Bool isJobRunning (int jobid)
 
static SCIP_Bool isJobWaiting (int jobid)
 
SCIP_RETCODE SCIPtpiCollectJobs (int jobid)
 
SCIP_RETCODE SCIPtpiInit (int nthreads, int queuesize, SCIP_Bool blockwhenfull)
 
SCIP_RETCODE SCIPtpiExit (void)
 
SCIP_RETCODE SCIPtpiInitLock (SCIP_LOCK **lock)
 
void SCIPtpiDestroyLock (SCIP_LOCK **lock)
 
SCIP_RETCODE SCIPtpiAcquireLock (SCIP_LOCK *lock)
 
SCIP_RETCODE SCIPtpiReleaseLock (SCIP_LOCK *lock)
 
SCIP_RETCODE SCIPtpiInitCondition (SCIP_CONDITION **condition)
 
void SCIPtpiDestroyCondition (SCIP_CONDITION **condition)
 
SCIP_Bool SCIPtpiIsAvailable (void)
 
void SCIPtpiGetLibraryName (char *name, int namesize)
 
void SCIPtpiGetLibraryDesc (char *desc, int descsize)
 

Macro Definition Documentation

◆ SCIPompInitLock

#define SCIPompInitLock (   lock)    (omp_init_lock(lock), SCIP_OKAY)

Definition at line 44 of file tpi_openmp.c.

◆ SCIPompDestroyLock

#define SCIPompDestroyLock (   lock)    (omp_destroy_lock(lock))

Definition at line 45 of file tpi_openmp.c.

◆ SCIPompAcquireLock

#define SCIPompAcquireLock (   lock)    (omp_set_lock(lock), SCIP_OKAY)

Definition at line 46 of file tpi_openmp.c.

◆ SCIPompReleaseLock

#define SCIPompReleaseLock (   lock)    (omp_unset_lock(lock), SCIP_OKAY)

Definition at line 47 of file tpi_openmp.c.

◆ SCIPompInitCondition

#define SCIPompInitCondition (   condition)
Value:
( omp_init_lock(&(condition)->_lock), \
(condition)->_waiters = 0, (condition)->_waitnum = 0, (condition)->_signals = 0, SCIP_OKAY )
@ SCIP_OKAY
Definition: type_retcode.h:42

Definition at line 50 of file tpi_openmp.c.

◆ SCIPompDestroyCondition

#define SCIPompDestroyCondition (   condition)    do { assert((condition)->_waiters == 0); assert((condition)->_waitnum == 0); assert((condition)->_signals == 0); omp_destroy_lock(&(condition)->_lock); } while(0)

Definition at line 52 of file tpi_openmp.c.

Typedef Documentation

◆ SCIP_JOBQUEUE

typedef struct SCIP_JobQueue SCIP_JOBQUEUE

Definition at line 88 of file tpi_openmp.c.

◆ SCIP_JOBQUEUES

Definition at line 100 of file tpi_openmp.c.

Function Documentation

◆ createJobQueue()

static SCIP_RETCODE createJobQueue ( int  nthreads,
int  qsize,
SCIP_Bool  blockwhenfull 
)
static

create job queue

Parameters
nthreadsthe number of threads
qsizethe queue size
blockwhenfullshould the queue be blocked from new jobs when full

Definition at line 107 of file tpi_openmp.c.

References BMSallocMemory, SCIP_JobQueues::nthreads, SCIP_ALLOC, and SCIP_UNUSED.

◆ freeJobQueue()

static SCIP_RETCODE freeJobQueue ( void  )
static

free job queue

Definition at line 144 of file tpi_openmp.c.

◆ executeJob()

static void executeJob ( SCIP_JOB job)
static

execute job

Parameters
jobthe job to be executed in parallel

Definition at line 162 of file tpi_openmp.c.

References SCIP_CALL_ABORT, SCIPompAcquireLock, and SCIPtpiGetThreadNum().

◆ SCIPtpiWaitCondition()

SCIP_RETCODE SCIPtpiWaitCondition ( SCIP_CONDITION condition,
SCIP_LOCK lock 
)

wait for a condition

Parameters
conditioncondition to wait for
lockcorresponding lock

Definition at line 200 of file tpi_openmp.c.

References SCIP_JobQueues::lock, SCIP_CALL, SCIP_OKAY, SCIPompAcquireLock, SCIPompReleaseLock, SCIPtpiAcquireLock(), and SCIPtpiReleaseLock().

◆ SCIPompWaitCondition()

static SCIP_RETCODE SCIPompWaitCondition ( SCIP_CONDITION condition,
omp_lock_t *  lock 
)
static

wait for a condition (direct access to lock)

Parameters
conditioncondition to wait for
lockcorresponding lock

Definition at line 239 of file tpi_openmp.c.

References SCIP_JobQueues::lock, SCIP_CALL, SCIP_OKAY, SCIPompAcquireLock, and SCIPompReleaseLock.

◆ jobQueueProcessJob()

static void jobQueueProcessJob ( void  )
static

process jobs from job queue

The job will only be added when the number of active jobs is equal to the number of threads. As such, there will always be number of threads + 1 tasks available for the scheduler to run.

Definition at line 283 of file tpi_openmp.c.

References SCIP_CALL_ABORT, and SCIPompAcquireLock.

◆ jobQueueAddJob()

static SCIP_RETCODE jobQueueAddJob ( SCIP_JOB newjob)
static

adding a job to the job queue

This gives some more flexibility in the handling of new jobs. IMPORTANT: This function MUST be called from within a mutex.

Definition at line 330 of file tpi_openmp.c.

References SCIP_Job::nextjob, NULL, SCIP_CALL, and SCIPompAcquireLock.

◆ SCIPtpiSignalCondition()

SCIP_RETCODE SCIPtpiSignalCondition ( SCIP_CONDITION condition)

signal a condition

Parameters
conditioncondition to signal

Definition at line 382 of file tpi_openmp.c.

References NULL, SCIP_CALL, SCIP_OKAY, SCIPompAcquireLock, and SCIPompReleaseLock.

◆ SCIPtpiBroadcastCondition()

SCIP_RETCODE SCIPtpiBroadcastCondition ( SCIP_CONDITION condition)

broadcase a condition

Parameters
conditionbroadcast a condition

Definition at line 400 of file tpi_openmp.c.

References NULL, SCIP_CALL, SCIP_OKAY, SCIPompAcquireLock, and SCIPompReleaseLock.

◆ SCIPtpiGetNumThreads()

int SCIPtpiGetNumThreads ( void  )

returns the number of threads

Definition at line 416 of file tpi_openmp.c.

◆ SCIPtpiGetThreadNum()

int SCIPtpiGetThreadNum ( void  )

returns the thread number

Definition at line 423 of file tpi_openmp.c.

Referenced by executeJob().

◆ 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 430 of file tpi_openmp.c.

References BMSallocMemory, NULL, SCIP_ALLOC, and SCIP_OKAY.

◆ SCIPtpiGetNewJobID()

int SCIPtpiGetNewJobID ( void  )

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

Definition at line 448 of file tpi_openmp.c.

◆ 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
jobpointer to the job to be submitted
statuspointer to store the submit status

Definition at line 462 of file tpi_openmp.c.

◆ isJobRunning()

static SCIP_Bool isJobRunning ( int  jobid)
static

check whether a job is running

Parameters
jobidjob id to check

Definition at line 478 of file tpi_openmp.c.

◆ isJobWaiting()

static SCIP_Bool isJobWaiting ( int  jobid)
static

check whether a job is waiting

Parameters
jobidjob id to check

Definition at line 499 of file tpi_openmp.c.

◆ 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
jobidthe jobid of the jobs to wait for

Definition at line 527 of file tpi_openmp.c.

References SCIP_CALL, SCIP_OKAY, and SCIPompAcquireLock.

◆ 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 596 of file tpi_openmp.c.

References SCIP_JobQueues::nthreads.

◆ SCIPtpiExit()

SCIP_RETCODE SCIPtpiExit ( void  )

deinitializes tpi

Definition at line 611 of file tpi_openmp.c.

◆ SCIPtpiInitLock()

SCIP_RETCODE SCIPtpiInitLock ( SCIP_LOCK **  lock)

initializes the given lock

Parameters
lockthe lock

Definition at line 631 of file tpi_openmp.c.

References BMSallocMemory, SCIP_JobQueues::lock, NULL, SCIP_ALLOC, and SCIP_OKAY.

◆ SCIPtpiDestroyLock()

void SCIPtpiDestroyLock ( SCIP_LOCK **  lock)

destroys the given lock

Parameters
lockthe lock

Definition at line 643 of file tpi_openmp.c.

References BMSfreeMemory, SCIP_JobQueues::lock, and NULL.

◆ SCIPtpiAcquireLock()

SCIP_RETCODE SCIPtpiAcquireLock ( SCIP_LOCK lock)

acquires the given lock

Parameters
lockthe lock

Definition at line 654 of file tpi_openmp.c.

References SCIP_JobQueues::lock, and SCIP_OKAY.

Referenced by SCIPtpiWaitCondition().

◆ SCIPtpiReleaseLock()

SCIP_RETCODE SCIPtpiReleaseLock ( SCIP_LOCK lock)

releases the given lock

Parameters
lockthe lock

Definition at line 663 of file tpi_openmp.c.

References SCIP_JobQueues::lock, and SCIP_OKAY.

Referenced by SCIPtpiWaitCondition().

◆ SCIPtpiInitCondition()

SCIP_RETCODE SCIPtpiInitCondition ( SCIP_CONDITION **  condition)

initializes the given condition variable

Parameters
conditioncondition to be created and initialized

Definition at line 677 of file tpi_openmp.c.

References BMSallocMemory, NULL, SCIP_ALLOC, and SCIP_OKAY.

◆ SCIPtpiDestroyCondition()

void SCIPtpiDestroyCondition ( SCIP_CONDITION **  condition)

destroys the given condition variable

Parameters
conditioncondition to be destroyed and freed

Definition at line 694 of file tpi_openmp.c.

References BMSfreeMemory.

◆ SCIPtpiIsAvailable()

SCIP_Bool SCIPtpiIsAvailable ( void  )

indicate whether a working TPI is available

Definition at line 708 of file tpi_openmp.c.

References TRUE.

◆ SCIPtpiGetLibraryName()

void SCIPtpiGetLibraryName ( char *  name,
int  namesize 
)

get name of library that the TPI interfaces to

Parameters
namebuffer to store name
namesizelength of name buffer

Definition at line 714 of file tpi_openmp.c.

References NULL, and SCIPsnprintf().

◆ SCIPtpiGetLibraryDesc()

void SCIPtpiGetLibraryDesc ( char *  desc,
int  descsize 
)

get description of library that the TPI interfaces to

Parameters
descbuffer to store description
descsizelength of description

Definition at line 725 of file tpi_openmp.c.

References NULL, and SCIPsnprintf().