23
3/12/2013 Computer Engg, IIT(BHU) 1 OpenMP-2

3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

Embed Size (px)

DESCRIPTION

Run time environment omp_get_num_threads() omp_get_thread_num() omp_in_parallel Routines related to locks

Citation preview

Page 1: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

3/12/2013 Computer Engg, IIT(BHU) 1

OpenMP-2

Page 2: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

Environment Variables

OMP_NUM_THREADS

OMP_SCHEDULE

Page 3: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

Run time environment

omp_get_num_threads()

omp_get_thread_num()

omp_in_parallel

Routines related to locks

Page 4: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

Lock routines

●Will only discuss simple lock: may not be locked if already in a locked state.

●Simple lock interface:

➢Type: omp_lock_t

➢Operations:

•omp_init_lock(omp_lock_t *a)

•omp_destroy_lock(omp_lock_t *a)

•omp_set_lock(omp_lock_t *a)

•omp_unset_lock(omp_lock_t *a)

•omp_test_lock(omp_lock_t *a)

Page 5: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

Lock routines

●omp_init_lock initializes the lock. After the call, the lock is unset.

●omp_destroy_lock destroys the lock. The lock must be unset before this call.

●omp_set_lock attempts to set the lock. If the lock is already set by another thread, it will wait until the lock is no longer set, and then sets it.

●omp_unset_lock unsets the lock. It should only be called by the same thread that set the lock; the consequences of doing otherwise are undefined.

●omp_test_lock attempts to set the lock. If the lock is already set by another thread, it returns 0; if it managed to set the lock, it returns 1.

Page 6: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OpenMP :User level library routines

omp_get_num_threads() : The omp_get_num threads library routine enables the programmer to retrieve the number of threads in the current team.

omp_get_thread_num() : Returns the number of the calling thread as an integer value.

omp_get_num() : procs returns, as an integer, the total number of processors available to the program at the instant in which it is called.

omp_in_parallel() : returns true if it is called from within an active parallel region Otherwise, it returns false.

Page 7: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_SET_NUM_THREADS

Purpose:● Sets the number of threads that

will be used in the next parallel region. Must be a positive integer.

Page 8: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_MAX_THREADS

Purpose:● Returns the maximum value that

can be returned by a call to the OMP_GET_NUM_THREADS function.

Page 9: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_THREAD_LIMIT

Purpose:● New with OpenMP 3.0. Returns

the maximum number of OpenMP threads available to a program.

Page 10: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_NUM_PROCS

Purpose:● Returns the number of processors

that are available to the program.

Page 11: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_SET_DYNAMIC

Purpose:● Enables or disables dynamic

adjustment (by the run time system) of the number of threads available for execution of parallel regions.

Page 12: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_DYNAMIC

Purpose:● Used to determine if dynamic

thread adjustment is enabled or not.

Page 13: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_SET_NESTED

Purpose:● Used to enable or disable nested

parallelism.

Page 14: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_NESTED

Purpose:● Used to determine if nested

parallelism is enabled or not.

Page 15: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_SET_SCHEDULE

Purpose:● This routine is new with OpenMP

version 3.0● This routine sets the schedule type

that is applied when the loop directive specifies a runtime schedule.

Page 16: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_SCHEDULE

Purpose:● This routine is new with OpenMP

version 3.0● This routine returns the schedule

that is applied when the loop directive specifies a runtime schedule.

Page 17: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_SET_MAX_ACTIVE_LEVELS

Purpose:● This routine is new with OpenMP

version 3.0● This routine limits the number of

nested active parallel regions.

Page 18: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_MAX_ACTIVE_LEVELS

Purpose:● This routine is new with OpenMP

version 3.0● This routine returns the maximum

number of nested active parallel regions.

Page 19: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_LEVEL

Purpose:● This routine is new with OpenMP

version 3.0● This routine returns the number of

nested parallel regions enclosing the task that contains the call.

Page 20: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_ANCESTOR_THREAD_NUM

Purpose:● This routine is new with OpenMP

version 3.0● This routine returns, for a given

nested level of the current thread, the thread number of the ancestor or the current thread.

Page 21: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_TEAM_SIZE

Purpose:● This routine is new with OpenMP

version 3.0● This routine returns, for a given nested

level of the current thread, the size of the thread team to which the ancestor or the current thread belongs.

Page 22: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_GET_ACTIVE_LEVEL

Purpose:● This routine is new with OpenMP

version 3.0● The omp_get_active_level routine

returns the number of nested, active parallel regions enclosing the task that contains the call.

Page 23: 3/12/2013Computer Engg, IIT(BHU)1 OpenMP-2. Environment Variables OMP_NUM_THREADS OMP_SCHEDULE

OMP_IN_FINAL

Purpose:● This routine is new with OpenMP

version 3.0● This routine returns true if the

routine is executed in a final task region; otherwise, it returns false.