Purpose
This function returns the number of the currently executing thread within the team. The number returned will always be between 0 and NUM_PARTHDS - 1. NUM_PARTHDS is the number of currently executing threads within the team.The master thread of the team returns a value of 0.
If you call omp_get_thread_num from within a serial region, from within a serialized nested parallel region, or from outside the dynamic extent of any parallel region, this function will return a value of 0.
This function binds to the closest parallel region.
Class
Function.
Argument Type and Attributes
None.
Result Type and Attributes
Default integer.
Result Value
The value of the currently executing thread within the team between 0 and NUM_PARTHDS - 1. NUM_PARTHDS is the number of currently executing threads within the team. A call to omp_get_thread_num from a serialized nested parallel region, or from outside the dynamic extent of any parallel region returns 0.
Examples
USE omp_lib INTEGER NP !$OMP PARALLEL PRIVATE(NP) NP = omp_get_thread_num() CALL WORK(NP) !$OMP MASTER NP = omp_get_thread_num() CALL WORK(NP) !$OMP END MASTER !$OMP END PARALLEL END SUBROUTINE WORK(THD_NUM) INTEGER THD_NUM PRINT *, THD_NUM END