program main c*********************************************************************72 c cc MAIN is the main program for HELLO. c c Discussion: c c HELLO is a "Hello, World" program for OpenMP. c c But we demonstrate a few simple features of OpenMP, including: c c How you get the "include" file. c How you measure wall clock time. c How you find out how many processors are available. c How you find out which thread you are in a parallel section. c How you find out how many threads are available in a parallel section. c How you set the number of threads. c c Licensing: c c This code is distributed under the GNU LGPL license. c c Modified: c c 20 July 2008 c c Author: c c John Burkardt c include 'omp_lib.h' integer id integer proc_num integer thread_num double precision wtime double precision wtime1 double precision wtime2 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'HELLO' write ( *, '(a)' ) ' FORTRAN77/OpenMP version' wtime1 = omp_get_wtime ( ) c c How many processors are available? c proc_num = omp_get_num_procs ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The number of processors available:' write ( *, '(a,i8)' ) ' OMP_GET_NUM_PROCS () = ', proc_num c c How many threads are available by default or environment setting? c c$omp parallel private ( id ) id = omp_get_thread_num ( ) thread_num = omp_get_num_threads ( ) if ( id .eq. 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Calling OMP_GET_NUM_THREADS inside a ' write ( *, '(a)' ) ' parallel region, we get the number of' write ( *, '(a,i3)' ) ' threads is ', thread_num end if write ( *, '(a,i8,a,i8)' ) & ' This is process ', id, ' out of ', thread_num c$omp end parallel c c Request double the number of threads. c thread_num = 2 * thread_num write ( *, '(a)' ) ' ' write ( *, '(a,i8,a)' ) ' We request ', thread_num, ' threads.' call omp_set_num_threads ( thread_num ) c c Now how many threads do we see? c c$omp parallel private ( id ) id = omp_get_thread_num ( ) thread_num = omp_get_num_threads ( ) if ( id .eq. 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Calling OMP_GET_NUM_THREADS inside a ' write ( *, '(a)' ) ' parallel region, we get the number of' write ( *, '(a,i3)' ) ' threads is ', thread_num end if write ( *, '(a,i8,a,i8)' ) & ' This is process ', id, ' out of ', thread_num c$omp end parallel c c Finish up by measuring the elapsed time. c wtime2 = omp_get_wtime ( ) wtime = wtime2 - wtime1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'HELLO' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' write ( *, '(a,g14.6)' ) ' Elapsed wall clock time = ', wtime stop end