! compile as: gfortran -O2 -fopenmp summ.f90 ! try also the option -march=native program calcsum use omp_lib implicit none ! rkind=4 single precision (32-bit) ! rkind=8 double precision (64-bit) ! rkind=10 double precision (80-bit) integer, parameter :: rkind=4 integer(8),parameter:: two=2,p0=10,p1=35 real(rkind) :: S(0:1),x integer:: ntmax,nproc,prl,nth integer(8) :: m,N,power real(8) :: t0(0:1),time(0:1),tick character(100) :: of ! Preparations ! Set OpenMP options (see also produce_test.sh) ! set number of thereads for parallel region ! ntmax=omp_get_max_threads() ! nproc=omp_get_num_procs() ! nth=nproc ! call omp_set_num_threads(nth) ! tick=omp_get_wtick() ! call omp_set_dynamic(.FALSE.) ! call omp_set_nested(.false.) ! Get file name for output from shell script. if not define use default call getenv('TEST_PREC_OF',of) if(len_trim(adjustl(of))==0) of='local_sum.dat' !!!!!!! Start calculations open(1,file=of) ! write(*,11)'# p','N=2**p ','bit','S(seq)','Time(seq)','S(par)','Time(par)' write(1,11)'# p','N=2**p ','bit','S(seq)','Time(seq)','S(par)','Time(par)' do power= p0,p1 N= two**power do prl=0,1 !prl=0/1 for sequential/parallel OpenMP code x= real(0.,rkind) t0(prl)=omp_get_wtime() !!!!$omp parallel if(prl==1) num_threads(nth) private(m) shared(N) !$omp parallel if(prl==1) private(m) shared(N) !$omp do reduction(+:x) do m= -N,N x=x + real(m,rkind) end do !$omp end parallel S(prl)=x time(prl)=omp_get_wtime()-t0(prl) enddo write(1,12) power,N,rkind*8,S(0),time(0),S(1),time(1) ! write(*,12) power,N,rkind*8,S(0),time(0),S(1),time(1) enddo close(1) !!!!!!!! 11 format(a3,a15,a4,2(a30,a15)) 12 format(i3,i15,i4,2(e30.21,e15.6)) end program