program main !*****************************************************************************80 ! !! MAIN is the main program for HELLO. ! ! Discussion: ! ! HELLO is a "Hello, World" program for OpenMP. ! ! But we demonstrate a few simple features of OpenMP, including: ! ! How you get the "include" file. ! How you measure wall clock time. ! How you find out how many processors are available. ! How you find out which thread you are in a parallel section. ! How you find out how many threads are available in a parallel section. ! How you set the number of threads. ! ! Licensing: ! ! This code is distributed under the GNU LGPL license. ! ! Modified: ! ! 20 July 2007 ! ! Author: ! ! John Burkardt ! use omp_lib integer id integer proc_num integer thread_num double precision wtime double precision wtime1 double precision wtime2 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'HELLO' write ( *, '(a)' ) ' FORTRAN90/OpenMP version' wtime1 = omp_get_wtime ( ) ! ! How many processors are available? ! proc_num = omp_get_num_procs ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The number of processors available:' write ( *, '(a,i8)' ) ' OMP_GET_NUM_PROCS () = ', proc_num ! ! How many threads are available by default or environment setting? ! !$omp parallel private ( id ) id = omp_get_thread_num ( ) thread_num = omp_get_num_threads ( ) if ( id == 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 !$omp end parallel ! ! Request double the number of threads. ! thread_num = 2 * thread_num write ( *, '(a)' ) ' ' write ( *, '(a,i8,a)' ) ' We request ', thread_num, ' threads.' call omp_set_num_threads ( thread_num ) ! ! Now how many threads do we see? ! !$omp parallel private ( id ) id = omp_get_thread_num ( ) thread_num = omp_get_num_threads ( ) if ( id == 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 !$omp end parallel ! ! Finish up by measuring the elapsed time. ! 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