Text-only Table of Contents (frame/ no frame)
(8) Basic OpenMP Functions Previous Top Next

Basic OpenMP Functions


omp_get_thread_num() - get the thread rank in a parallel region (0- omp_get_num_threads() -1)
omp_set_num_threads(nthreads) - set the number of threads used in a parallel region
omp_get _num_threads() - get the number of threads used in a parallel region


C/C++
#include <omp.h>
int omp_get_thread_num();
#
pragma omp parallel
{
printf("Thread rank: %d\n", omp_get_thread_num());
}

Fortran

INTEGER FUNCTION OMP_GET_THREAD_NUM()
!$OMP PARALLEL
write(*,*)'Thread rank: ', OMP_GET_THREAD_NUM()
!$OMP END PARALLEL


Note that in general the rank output are not in order.
Thread rank:  2
Thread rank: 0
Thread rank: 3
Thread rank: 1




Previous Top Next


openmp_functions.src  last modified Mar 23, 2009 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College