Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

OpenMP* Runtime Library Routines

OpenMP* provides runtime library routines to help you manage your program in parallel mode. Many of these runtime library routines have corresponding environment variables that can be set as defaults. The runtime library routines let you dynamically change these factors to assist in controlling your program. In all cases, a call to a runtime library routine overrides any corresponding environment variable.

CAUTION:

Running OpenMP runtime library routines may initialize the OpenMP runtime environment, which might cause a situation where subsequent programmatic setting of OpenMP environment variables has no effect. To avoid this situation, you can use the Intel extension routine kmp_set_defaults() to set OpenMP environment variables.

The compiler supports all the OpenMP runtime library routines. Refer to the OpenMP API specification for detailed information about using these routines.

Include the appropriate declarations of the routines in your source code by adding a statement similar to the following:

#include <omp.h>

The header files are provided in the ../include (Linux*) or ..\include (Windows*) directory of your compiler installation.

Thread Team Routines

Routines that affect and monitor thread teams in the current contention group.

Routine

Description

void omp_set_num_threads(int nthreads)

Sets the number of threads to use for subsequent parallel regions created by the calling thread.

int omp_get_num_threads(void)

Returns the number of threads that are being used in the current parallel region.

This function does not necessarily return the value inherited by the calling thread from the omp_set_num_threads() function.

int omp_get_max_threads(void)

Returns the number of threads available to subsequent parallel regions created by the calling thread.

int omp_get_thread_num(void)

Returns the thread number of the calling thread, within the context of the current parallel region.

int omp_in_parallel(void)

Returns TRUE if called within the dynamic extent of a parallel region executing in parallel; otherwise returns FALSE.

Thread Affinity Routines

Routines that affect and access thread affinity policies that are in effect.

Function

Description

omp_proc_bind_t omp_get_proc_bind(void)

Returns the currently active thread affinity policy, which can be initialized by the environment variable OMP_PROC_BIND.

This policy is used for subsequent nested parallel regions.

int omp_get_num_places(void)

Returns the number of places available to the execution environment in the place list of the initial task, usually threads, cores, or sockets.

int omp_get_place_num_procs(int place_num)

Returns the number of processors associated with the place numbered place_num. The routine returns zero when place_num is negative or is greater than or equal to omp_get_num_places().

void omp_get_place_proc_ids(int place_num, int *ids)

Returns the numerical identifiers of each processor associated with the place numbered place_num. The numerical identifiers are non-negative and their meaning is implementation defined. The numerical identifiers are returned in the array ids and their order in the array is implementation defined.The array ids must be sufficiently large to contain omp_get_place_num_procs(place_num) elements. The routine has no effect when place_num is negative or greater than or equal to omp_get_num_places().

int omp_get_place_num(void)

Returns the place number of the place to which the encountering thread is bound. The returned value is between 0 and omp_get_num_places() - 1, inclusive. When the encountering thread is not bound to a place, the routine returns -1.

Teams Region Routines

Routines that affect and monitor the league of teams that may execute a teams region.

Function

Description

int omp_get_num_teams(void)

Returns the number of initial teams in the current teams region.

int omp_get_team_num(void)

Returns the initial team number of the calling thread.

void omp_set_num_teams(int num_teams)

Affects the number of threads to be used for subsequent teams regions that do not specify a num_teams clause.

int omp_get_max_teams(void)

Returns an upper bound on the number of teams that could be created by a teams construct without a num_teams clause that is encountered after execution returns from this routine.

void omp_set_teams_thread_limit(int thread_limit)

Defines the maximum number of OpenMP threads that can participate in each contention group created by a teams construct.

Tasking Routines

Routines that pertain to OpenMP explicit tasks.

Function Description

int omp_get_max_task_priority(void)

Returns the maximum value that can be specified in the priority clause.

int omp_in_explicit_task(void)

Returns TRUE if called within an explicit task region; otherwise returns FALSE.

int omp_in_final(void)

Returns TRUE if called within a final task region; otherwise returns FALSE.

Resource Relinquishing Routines

Routines that relinquish resources used by the OpenMP runtime. These routines are only effective on the host device.

Function Description

int omp_pause_resource(omp_pause_resource_t kind, int device_num)

Allows the runtime to relinquish resources used by OpenMP on the specified device. The routine returns zero in case of success, and non-zero otherwise.

int omp_pause_resource_all(omp_pause_resource_t kind)

Allows the runtime to relinquish resources used by OpenMP on all devices. The routine returns zero in case of success, and non-zero otherwise.

Device Information Routines

Routines that pertain to the set of devices that are accessible to an OpenMP program.

Function Description

int omp_get_num_procs(void)

Returns the number of processors available to the program.

void omp_set_default_device(int device_number)

Sets the default device number.

int omp_get_default_device(void)

Returns the default device number.

int omp_get_num_devices(void)

Returns the number of target devices.

int omp_get_device_num(void)

Returns the device number of the device on which the calling thread is executing.

Device Memory Routines

Routines that support allocation of memory and management of pointers in the data environments of target devices.

Routine Description

void *omp_target_alloc(size_t size, int device_num)

Allocates memory in a device data environment and returns a device pointer to that memory.

void omp_target_free(void *device_ptr, int device_num)

Frees device memory that was allocated by the omp_target_alloc.

int omp_target_is_present(const void *ptr, int device_num)

Returns TRUE if device_num refers to the host device or if ptr refers to storage that has corresponding storage in the device data environment of device_num. Otherwise, it returns FALSE.

int omp_target_is_accessible(const void *ptr, size_t size, int device_num)

Returns TRUE if the storage of size bytes starting at the address given by ptr is accessible from device device_num. Otherwise, it returns FALSE.

int omp_target_memcpy(void *dst, const void *src, size_t length, size_t dst_offset, size_t src_offset, int dst_device_num, int src_device_num)

This routine copies length bytes of memory at offset src _offset from src in the device data environment of device src_device_num to dst, starting at offset dst_offset in the device data environment of the device specified by dst_device_num. Returns zero on success and a non-zero value on failure. Use omp_get_initial_device to return the device number you can use to reference the host device and host device data environment. This routine includes a task scheduling point.

The effect of this routine is unspecified when it is called from within a target region.

Lock Routines

Use these routines to affect OpenMP locks.

Function

Description

void omp_init_lock(omp_lock_t *lock)

Initializes the lock to the unlocked state.

void omp_init_nest_lock(omp_nest_lock_t *lock)

Initializes the nested lock to the unlocked state. The nesting count for the nested lock is set to zero.

void omp_init_lock_with_hint(omp_lock_t *lock, omp_sync_hint_t hint)

Initializes the lock to the unlocked state, optionally choosing a specific lock implementation based on hint. See the OpenMP specification for the available hints.

void omp_init_nest_lock_with_hint(omp_nest_lock_t *lock, omp_sync_hint_t hint)

Initializes the nested lock to the unlocked state, optionally choosing a specific lock implementation based on hint. The nesting count for the nested lock is set to zero. See the OpenMP specification for the available hints.

void omp_destroy_lock(omp_lock_t *lock)

Changes the state of the lock to uninitialized.

Timing Routines

Function

Description

double omp_get_wtime(void)

Returns a double precision value equal to the elapsed wall clock time (in seconds) relative to an arbitrary reference time. The reference time does not change during program execution.

double omp_get_wtick(void)

Returns a double precision value equal to the number of seconds between successive clock ticks.

Event Routines

Function

Description

void omp_fulfill_event(omp_event_handle_t event)

Fulfills the event associated with the event handle event and destroys the event.

Interoperability Routines

Function Description

int omp_get_num_interop_properties(const omp_interop_t interop)

Returns the number of implementation-defined properties available for interop. The total number of properties available for interop is the returned value minus omp_ipr_first.

omp_intptr_t omp_get_interop_int(const omp_interop_t interop, omp_interop_property_t property_id, int *ret_code)

Returns the requested integer property, if available, and zero if an error occurs or no value is available.

void *omp_get_interop_ptr(const omp_interop_t interop, omp_interop_property_t property_id, int *ret_code)

Returns the requested pointer property, if available, and NULL if an error occurs or no value is available.

const char *omp_get_interop_str(const omp_interop_t interop, omp_interop_property_t property_id, int *ret_code)

Returns the requested string property as a C string, if available, and NULL if an error occurs or no value is available.

const char *omp_get_interop_name(const omp_interop_t interop, omp_interop_property_t property_id)

Returns the name of the property identified by property_id as a C string.

Memory Management Routines

Function Description

omp_allocator_handle_t omp_init_allocator(omp_memspace_handle_t memspace, int ntraits, const omp_alloctrait_t traits[])

Creates a new allocator that is associated with the memspace memory space and returns a handle to it.

void omp_destroy_allocator(omp_allocator_handle_t allocator)

Releases all resources used to implement the allocator handle.

void omp_set_default_allocator(omp_allocator_handle_t allocator)

Sets the default memory allocator to be used by allocation calls, allocate directives and allocate clauses that do not specify an allocator.

omp_allocator_handle_t omp_get_default_allocator(void)

Returns a handle to the memory allocator to be used by allocation calls, allocate directives and allocate clauses that do not specify an allocator.

void *omp_alloc(size_t size, omp_allocator_handle_t allocator)

Requests a memory allocation of size bytes from the specified memory allocator.

Tool Control Routines

Function

Description

int omp_control_tool(int command, int modifier, void *arg)

Enables a program to pass commands to an active tool.

Environment Display Routines

Function

Description

void omp_display_env(int verbose)

Displays the OpenMP version number and the initial values of ICVs associated with the environment variables.

Device Runtime Routines Available on GPU

The following device runtime routines are available on CPU and GPU.

  • omp_get_device_num
  • omp_get_max_threads
  • omp_get_num_devices
  • omp_get_num_procs
  • omp_get_num_teams
  • omp_get_num_threads
  • omp_get_team_num
  • omp_get_team_size
  • omp_get_thread_limit
  • omp_get_thread_num
  • omp_in_parallel
  • omp_is_initial_device