Commit d4474df7 authored by Budiardja, Reuben's avatar Budiardja, Reuben
Browse files

Added several versions of the Fortran port.

parent 666b8933
......@@ -4,7 +4,11 @@ FC := xlf2003_r
C_FLAGS := -O3 -qsmp=omp -qoffload
F_FLAGS := -O3 -qsmp=omp -qoffload
all: rush_larsen_simple_c rush_larsen_simple_f
all: rush_larsen_simple_c \
rush_larsen_simple_f \
rush_larsen_simple_f_1 \
rush_larsen_simple_f_2 \
rush_larsen_simple_f_3
rush_larsen_simple_c: rush_larsen_simple.cc
$(CC) -o rush_larsen_simple_c \
......@@ -14,7 +18,22 @@ rush_larsen_simple_f: rush_larsen_simple.f90
$(FC) -o rush_larsen_simple_f \
$(F_FLAGS) rush_larsen_simple.f90
rush_larsen_simple_f_1: rush_larsen_simple_1.f90
$(FC) -o rush_larsen_simple_f_1 \
$(F_FLAGS) rush_larsen_simple_1.f90
rush_larsen_simple_f_2: rush_larsen_simple_2.f90
$(FC) -o rush_larsen_simple_f_2 \
$(F_FLAGS) rush_larsen_simple_2.f90
rush_larsen_simple_f_3: rush_larsen_simple_3.f90
$(FC) -o rush_larsen_simple_f_3 \
$(F_FLAGS) rush_larsen_simple_3.f90
clean:
rm -f rush_larsen_simple_c \
rush_larsen_simple_f
rush_larsen_simple_f \
rush_larsen_simple_f_1 \
rush_larsen_simple_f_2 \
rush_larsen_simple_f_3
rm -f *.o *.mod
module rush_larsen_simple_module
use omp_lib
use iso_fortran_env
implicit none
public
real ( real64 ) :: &
TimeTotal = 0.0_real64
real ( real64 ), dimension ( : ), allocatable :: &
m_gate, &
Vm
real ( real64 ), parameter :: &
Mhu_a ( 0 : 14 ) = &
[ 9.9632117206253790e-01_real64, 4.0825738726469545e-02_real64, &
6.3401613233199589e-04_real64, 4.4158436861700431e-06_real64, &
1.1622058324043520e-08_real64, 1.0000000000000000e+00_real64, &
4.0568375699663400e-02_real64, 6.4216825832642788e-04_real64, &
4.2661664422410096e-06_real64, 1.3559930396321903e-08_real64, &
-1.3573468728873069e-11_real64, -4.2594802366702580e-13_real64, &
7.6779952208246166e-15_real64, 1.4260675804433780e-16_real64, &
-2.6656212072499249e-18_real64 ], &
Tau_a ( 0 : 18 ) = &
[ 1.7765862602413648d+01*0.02_real64, &
5.0010202770602419d-02*0.02_real64, &
-7.8002064070783474d-04*0.02_real64, &
-6.9399661775931530d-05*0.02_real64, &
1.6936588308244311d-06*0.02_real64, &
5.4629017090963798d-07*0.02_real64, &
-1.3805420990037933d-08*0.02_real64, &
-8.0678945216155694d-10*0.02_real64, &
1.6209833004622630d-11*0.02_real64, &
6.5130101230170358d-13*0.02_real64, &
-6.9931705949674988d-15*0.02_real64, &
-3.1161210504114690d-16*0.02_real64, &
5.0166191902609083d-19*0.02_real64, &
7.8608831661430381d-20*0.02_real64, &
4.3936315597226053d-22*0.02_real64, &
-7.0535966258003289d-24*0.02_real64, &
-9.0473475495087118d-26*0.02_real64, &
-2.9878427692323621d-28*0.02_real64, &
1.0000000000000000_real64 ]
contains
subroutine Initialize ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start, &
Time_H2D
allocate ( m_gate ( 0 : nCells-1 ) )
m_gate = 0.0_real64
allocate ( Vm ( 0 : nCells-1 ) )
Vm = 0.0_real64
Start = omp_get_wtime ( )
!$OMP target enter data map ( to: m_gate )
!$OMP target enter data map ( to: Vm )
!$OMP target enter data map ( to: Mhu_a )
!$OMP target enter data map ( to: Tau_a )
Time_H2D = omp_get_wtime ( ) - Start
write ( *, fmt = '(a20, f6.4, a4)' ) &
'OMP Time H2D : ', Time_H2D, ' sec'
TimeTotal = TimeTotal + Time_H2D
end subroutine Initialize
subroutine Compute ( nCells, nIterations )
integer ( int64 ), intent ( in ) :: &
nCells
integer, intent ( in ) :: &
nIterations
integer :: &
iT, ii, j, k
integer, parameter :: &
Mhu_l = 10, &
Mhu_m = 5, &
Tau_m = 18
real ( real64 ) :: &
x, sum1, sum2, mhu, tauR, &
Start, &
TimeCompute
Start = omp_get_wtime ( )
do iT = 0, nIterations
!$OMP target teams distribute parallel do &
!$OMP private ( x, sum1, j, sum2, k, mhu, tauR )
do ii = 0, nCells - 1
x = Vm(ii)
sum1 = 0.0
do j = Mhu_m-1, 0, -1
sum1 = Mhu_a(j) + x*sum1
end do
sum2 = 0.0
k = Mhu_m + Mhu_l - 1
do j = k, Mhu_m, -1
sum2 = Mhu_a(j) + x * sum2
end do
mhu = sum1/sum2
sum1 = 0.0
do j = Tau_m-1, 0, -1
sum1 = Tau_a(j) + x*sum1
end do
tauR = sum1
m_gate(ii) = m_gate(ii) + (mhu - m_gate(ii))*(1-exp(-tauR))
end do
!$OMP end target teams distribute parallel do
end do
TimeCompute = omp_get_wtime ( ) - Start
write ( *, fmt = '(a20, f6.4, a4)' ) &
'OMP Time Compute : ', TimeCompute, ' sec'
TimeTotal = TimeTotal + TimeCompute
end subroutine Compute
subroutine Verify ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start, &
Time_D2H
Start = omp_get_wtime ( )
!$OMP target update from ( m_gate )
Time_D2H = omp_get_wtime ( ) - Start
write(*, fmt = '(a20, f6.4, a4)' ) &
'OMP Time D2H : ', Time_D2H, ' sec'
TimeTotal = TimeTotal + Time_D2H
if ( m_gate ( 0 ) < 0.506796_real64 &
.or. m_gate ( 0 ) > 0.996322_real64 ) then
write ( *, fmt = '( a, f17.15)' ) &
'FAILED sanity check, m_gate[0]=', m_gate ( 0 )
else
write ( *, fmt = '( a, f17.15)' ) &
'PASSED sanity check, m_gate[0]=', m_gate ( 0 )
end if
end subroutine Verify
subroutine Finalize ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start
!$OMP target exit data map ( delete : Vm )
!$OMP target exit data map ( delete : m_gate )
!$OMP target exit data map ( delete: Mhu_a )
!$OMP target exit data map ( delete: Tau_a )
deallocate ( Vm )
deallocate ( m_gate )
end subroutine Finalize
end module rush_larsen_simple_module
program rush_larsen_simple
use rush_larsen_simple_module
implicit none
integer :: &
nIterations
integer ( int64 ) :: &
nCells
nIterations = 100
nCells = 671088640
call Initialize ( nCells )
call Compute ( nCells, nIterations )
call Verify ( nCells )
write(*, fmt = '(a20, f6.4, a4)' ) &
'OMP Time Total : ', TimeTotal, ' sec'
call Finalize ( nCells )
end program rush_larsen_simple
\ No newline at end of file
module rush_larsen_simple_module
use omp_lib
use iso_fortran_env
implicit none
public
real ( real64 ) :: &
TimeTotal = 0.0_real64
real ( real64 ), dimension ( : ), allocatable :: &
m_gate, &
Vm
contains
subroutine Initialize ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start, &
Time_H2D
allocate ( m_gate ( 0 : nCells-1 ) )
m_gate = 0.0_real64
allocate ( Vm ( 0 : nCells-1 ) )
Vm = 0.0_real64
Start = omp_get_wtime ( )
!$OMP target enter data map ( to: m_gate )
!$OMP target enter data map ( to: Vm )
Time_H2D = omp_get_wtime ( ) - Start
write ( *, fmt = '(a20, f6.4, a4)' ) &
'OMP Time H2D : ', Time_H2D, ' sec'
TimeTotal = TimeTotal + Time_H2D
end subroutine Initialize
subroutine Compute ( nCells, nIterations )
integer ( int64 ), intent ( in ) :: &
nCells
integer, intent ( in ) :: &
nIterations
integer :: &
iT, ii, j, k
integer, parameter :: &
Mhu_l = 10, &
Mhu_m = 5, &
Tau_m = 18
real ( real64 ) :: &
x, sum1, sum2, mhu, tauR, &
Start, &
TimeCompute
real ( real64 ), parameter :: &
Mhu_a ( 0 : 14 ) = &
[ 9.9632117206253790e-01_real64, 4.0825738726469545e-02_real64, &
6.3401613233199589e-04_real64, 4.4158436861700431e-06_real64, &
1.1622058324043520e-08_real64, 1.0000000000000000e+00_real64, &
4.0568375699663400e-02_real64, 6.4216825832642788e-04_real64, &
4.2661664422410096e-06_real64, 1.3559930396321903e-08_real64, &
-1.3573468728873069e-11_real64, -4.2594802366702580e-13_real64, &
7.6779952208246166e-15_real64, 1.4260675804433780e-16_real64, &
-2.6656212072499249e-18_real64 ], &
Tau_a ( 0 : 18 ) = &
[ 1.7765862602413648d+01*0.02_real64, &
5.0010202770602419d-02*0.02_real64, &
-7.8002064070783474d-04*0.02_real64, &
-6.9399661775931530d-05*0.02_real64, &
1.6936588308244311d-06*0.02_real64, &
5.4629017090963798d-07*0.02_real64, &
-1.3805420990037933d-08*0.02_real64, &
-8.0678945216155694d-10*0.02_real64, &
1.6209833004622630d-11*0.02_real64, &
6.5130101230170358d-13*0.02_real64, &
-6.9931705949674988d-15*0.02_real64, &
-3.1161210504114690d-16*0.02_real64, &
5.0166191902609083d-19*0.02_real64, &
7.8608831661430381d-20*0.02_real64, &
4.3936315597226053d-22*0.02_real64, &
-7.0535966258003289d-24*0.02_real64, &
-9.0473475495087118d-26*0.02_real64, &
-2.9878427692323621d-28*0.02_real64, &
1.0000000000000000_real64 ]
Start = omp_get_wtime ( )
do iT = 0, nIterations
!$OMP target teams distribute parallel do &
!#OMP firstprivate ( to: Mhu_a, Tau_a ) &
!$OMP private ( x, sum1, j, sum2, k, mhu, tauR )
do ii = 0, nCells - 1
x = Vm(ii)
sum1 = 0.0
do j = Mhu_m-1, 0, -1
sum1 = Mhu_a(j) + x*sum1
end do
sum2 = 0.0
k = Mhu_m + Mhu_l - 1
do j = k, Mhu_m, -1
sum2 = Mhu_a(j) + x * sum2
end do
mhu = sum1/sum2
sum1 = 0.0
do j = Tau_m-1, 0, -1
sum1 = Tau_a(j) + x*sum1
end do
tauR = sum1
m_gate(ii) = m_gate(ii) + (mhu - m_gate(ii))*(1-exp(-tauR))
end do
!$OMP end target teams distribute parallel do
end do
TimeCompute = omp_get_wtime ( ) - Start
write ( *, fmt = '(a20, f6.4, a4)' ) &
'OMP Time Compute : ', TimeCompute, ' sec'
TimeTotal = TimeTotal + TimeCompute
end subroutine Compute
subroutine Verify ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start, &
Time_D2H
Start = omp_get_wtime ( )
!$OMP target update from ( m_gate )
Time_D2H = omp_get_wtime ( ) - Start
write(*, fmt = '(a20, f6.4, a4)' ) &
'OMP Time D2H : ', Time_D2H, ' sec'
TimeTotal = TimeTotal + Time_D2H
if ( m_gate ( 0 ) < 0.506796_real64 &
.or. m_gate ( 0 ) > 0.996322_real64 ) then
write ( *, fmt = '( a, f17.15)' ) &
'FAILED sanity check, m_gate[0]=', m_gate ( 0 )
else
write ( *, fmt = '( a, f17.15)' ) &
'PASSED sanity check, m_gate[0]=', m_gate ( 0 )
end if
end subroutine Verify
subroutine Finalize ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start
!$OMP target exit data map ( delete : Vm )
!$OMP target exit data map ( delete : m_gate )
deallocate ( Vm )
deallocate ( m_gate )
end subroutine Finalize
end module rush_larsen_simple_module
program rush_larsen_simple
use rush_larsen_simple_module
implicit none
integer :: &
nIterations
integer ( int64 ) :: &
nCells
nIterations = 100
nCells = 671088640
call Initialize ( nCells )
call Compute ( nCells, nIterations )
call Verify ( nCells )
write(*, fmt = '(a20, f6.4, a4)' ) &
'OMP Time Total : ', TimeTotal, ' sec'
call Finalize ( nCells )
end program rush_larsen_simple
\ No newline at end of file
module rush_larsen_simple_module
use omp_lib
use iso_fortran_env
implicit none
public
real ( real64 ) :: &
TimeTotal = 0.0_real64
real ( real64 ), dimension ( : ), allocatable :: &
m_gate, &
Vm
contains
subroutine Initialize ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start, &
Time_H2D
allocate ( m_gate ( 0 : nCells-1 ) )
m_gate = 0.0_real64
allocate ( Vm ( 0 : nCells-1 ) )
Vm = 0.0_real64
Start = omp_get_wtime ( )
!$OMP target enter data map ( to: m_gate )
!$OMP target enter data map ( to: Vm )
Time_H2D = omp_get_wtime ( ) - Start
write ( *, fmt = '(a20, f6.4, a4)' ) &
'OMP Time H2D : ', Time_H2D, ' sec'
TimeTotal = TimeTotal + Time_H2D
end subroutine Initialize
subroutine Compute ( nCells, nIterations )
integer ( int64 ), intent ( in ) :: &
nCells
integer, intent ( in ) :: &
nIterations
integer :: &
iT, ii, j, k
integer, parameter :: &
Mhu_l = 10, &
Mhu_m = 5, &
Tau_m = 18
real ( real64 ) :: &
x, sum1, sum2, mhu, tauR, &
Start, &
TimeCompute
Start = omp_get_wtime ( )
do iT = 0, nIterations
!$OMP target teams distribute parallel do &
!$OMP private ( x, sum1, j, sum2, k, mhu, tauR )
do ii = 0, nCells - 1
block
real ( real64 ), parameter :: &
Mhu_a ( 0 : 14 ) = &
[ 9.9632117206253790e-01_real64, 4.0825738726469545e-02_real64, &
6.3401613233199589e-04_real64, 4.4158436861700431e-06_real64, &
1.1622058324043520e-08_real64, 1.0000000000000000e+00_real64, &
4.0568375699663400e-02_real64, 6.4216825832642788e-04_real64, &
4.2661664422410096e-06_real64, 1.3559930396321903e-08_real64, &
-1.3573468728873069e-11_real64, -4.2594802366702580e-13_real64, &
7.6779952208246166e-15_real64, 1.4260675804433780e-16_real64, &
-2.6656212072499249e-18_real64 ], &
Tau_a ( 0 : 18 ) = &
[ 1.7765862602413648d+01*0.02_real64, &
5.0010202770602419d-02*0.02_real64, &
-7.8002064070783474d-04*0.02_real64, &
-6.9399661775931530d-05*0.02_real64, &
1.6936588308244311d-06*0.02_real64, &
5.4629017090963798d-07*0.02_real64, &
-1.3805420990037933d-08*0.02_real64, &
-8.0678945216155694d-10*0.02_real64, &
1.6209833004622630d-11*0.02_real64, &
6.5130101230170358d-13*0.02_real64, &
-6.9931705949674988d-15*0.02_real64, &
-3.1161210504114690d-16*0.02_real64, &
5.0166191902609083d-19*0.02_real64, &
7.8608831661430381d-20*0.02_real64, &
4.3936315597226053d-22*0.02_real64, &
-7.0535966258003289d-24*0.02_real64, &
-9.0473475495087118d-26*0.02_real64, &
-2.9878427692323621d-28*0.02_real64, &
1.0000000000000000_real64 ]
x = Vm(ii)
sum1 = 0.0
do j = Mhu_m-1, 0, -1
sum1 = Mhu_a(j) + x*sum1
end do
sum2 = 0.0
k = Mhu_m + Mhu_l - 1
do j = k, Mhu_m, -1
sum2 = Mhu_a(j) + x * sum2
end do
mhu = sum1/sum2
sum1 = 0.0
do j = Tau_m-1, 0, -1
sum1 = Tau_a(j) + x*sum1
end do
tauR = sum1
m_gate(ii) = m_gate(ii) + (mhu - m_gate(ii))*(1-exp(-tauR))
end block
end do
!$OMP end target teams distribute parallel do
end do
TimeCompute = omp_get_wtime ( ) - Start
write ( *, fmt = '(a20, f6.4, a4)' ) &
'OMP Time Compute : ', TimeCompute, ' sec'
TimeTotal = TimeTotal + TimeCompute
end subroutine Compute
subroutine Verify ( nCells )
integer ( int64 ), intent ( in ) :: &
nCells
real ( real64 ) :: &
Start, &
Time_D2H