User's Guide
For a nestable lock, the omp_unset_nest_lock function decrements the nesting count, and
releases the thread executing the function from ownership of the lock if the resulting count is zero.
omp_test_lock and omp_test_nest_lock Functions
#include <omp.h>
int omp_test_lock(omp_lock_t *lock);
int omp_test_nest_lock(omp_nest_lock_t *lock);
These functions attempt to set a lock but do not block execution of the thread. The argument must
point to an initialized lock variable. These functions attempt to set a lock in the same manner as
omp_set_lock and omp_set_nest_lock, except that they do not block execution of the
thread.For a simple lock, the omp_test_lock function returns non-zero if the lock is successfully
set; otherwise, it returns zero.
For a nestable lock, the omp_test_nest_lock function returns the new nesting count if the lock
is successfully set; otherwise, it returns zero.
Timing Functions
The functions described in this section support a portable wall-clock timer:
• omp_get_wtime
• omp_get_wtick
omp_get_wtime
#include <omp.h>
double omp_get_wtime(void);
The omp_get_wtime function returns a double-precision floating-point value equal to the elapsed
wall clock time in seconds since some time in the past. The actual time in the past is arbitrary, but
it is guaranteed not to change during the execution of the application program.
The function may be used to measure elapsed times as shown in the following example:
double start;
double end;
start = omp_get_wtime();
... work to be timed ...
end = omp_get_wtime();
printf(“Work took %f sec. time.\n”, end-start);
The time returned is per-thread times. They are not required to be globally consistent across all the
threads participating in an application.
omp_get_wtick
#include <omp.h>
double omp_get_wtick(void);
The omp_get_wtick function returns a double-precision floating-point value equal to the number
of seconds between successive clock ticks.
174 Exception Handling