Tuesday 15 April 2014

fortran - OpenMP and internal subroutines -



fortran - OpenMP and internal subroutines -

i've been testing openmp speedup of simple fortran code 1) internal subroutine phone call within parallel part , 2) parallel part initialization within internal subroutine. in both cases openmp loop placed within internal subroutine. here simple code:

module module_with_subroutine include "omp_lib.h" integer ,parameter :: rkind = selected_real_kind(15,307) real(rkind) ,dimension(100,100,100) :: real(rkind) :: elapsed_time integer :: clock_start ,clock_end ,clock_rate contains subroutine module_subprogram = 3.14_rkind phone call system_clock(count_rate = clock_rate) phone call system_clock(count = clock_start) !!$omp parallel num_threads(12) !!! case 1 phone call intrinsic_subprogram !!$omp end parallel phone call system_clock(count = clock_end) elapsed_time = (clock_end-clock_start)/real(clock_rate,rkind) print *, 'elapsed time in seconds: ',elapsed_time print *, 'clock start: ',clock_start print *, 'clock end: ',clock_end print *, 'clock rate: ',clock_rate contains subroutine intrinsic_subprogram integer :: i, j, k, steps ,nthread steps = 1,10000 !$omp parallel num_threads(12) !!! case 2 !$omp collapse(3) private (i,j,k,nthread) k = 1,100 j = 1,100 = 1,100 nthread = omp_get_thread_num() a(i,j,k) = (exp(a(i,j,k)**3.14 + sqrt(a(i,j,k)**3.14) + log(a(i,j,k)**3.14)))**1.414 if(a(i,j,k) <= 3.14) a(i,j,k) = 1.0 end if !print *, 'thread number',nthread !print *, 'i,j,k',i,j,k end end end !$omp end !$omp end parallel end end subroutine end subroutine end module

strange thing here sec case bit faster first one, despite multiple parallel regions initializations within steps loop. maybe can explain behaviour ? i'm new openmp programming , maybe i'm misunderstanding openmp thread forking technology. give thanks in advance !

fortran openmp

No comments:

Post a Comment