c Program to take the sum of the members of a structure
c to another array
program double_array_sample1_ex1
implicit none
c
type Vector
real*8, allocatable :: a(:), b(:), c(:), d(:),
& e(:), f(:), g(:), h(:)
end type Vector
c
type(Vector) :: vec
real*8, allocatable :: r(:)
integer i, k, n
integer*8 time0, time1, dtime
real*8 time
c
write(*,*)"Array size Elapsed time [sec]"
do k=1,20
c Array size
n = k * 2000000
c Allocation
allocate(vec%a(n), vec%b(n), vec%c(n), vec%d(n),
& vec%e(n), vec%f(n), vec%g(n), vec%h(n), r(n))
c Initialization
do i=1,n
vec%a(i) = 1d0
vec%b(i) = 1d0
vec%c(i) = 1d0
vec%d(i) = 1d0
vec%e(i) = 1d0
vec%f(i) = 1d0
vec%g(i) = 1d0
vec%h(i) = 1d0
end do
c Start time
call system_clock(time0)
c Main calculation: find the sum of all members of vec
do i=1,n
r(i) = vec%a(i) + vec%b(i) + vec%c(i) + vec%d(i)
& + vec%e(i) + vec%f(i) + vec%g(i) + vec%h(i)
end do
c Finish time
call system_clock(time1, dtime)
c Output time
time = 1d0*(time1-time0)/dtime
write(*,"(i11,f16.7)")n, time
c Deallocation
deallocate(vec%a, vec%b, vec%c, vec%d, vec%e,
& vec%f, vec%g, vec%h, r)
end do
end program
|
c Program to take the sum of the members of a structure
c to another array
program double_array_sample1_ex2
implicit none
c
type Vector
real*8 a, b, c, d, e, f,
& g, h
end type Vector
c
type(Vector), allocatable :: vec(:)
real*8, allocatable :: r(:)
integer i, k, n
integer*8 time0, time1, dtime
real*8 time
c
write(*,*)"Array size Elapsed time [sec]"
do k=1,20
c Array size
n = k * 2000000
c Allocation
allocate(vec(n), r(n))
c Initialization
do i=1,n
vec(i)%a = 1d0
vec(i)%b = 1d0
vec(i)%c = 1d0
vec(i)%d = 1d0
vec(i)%e = 1d0
vec(i)%f = 1d0
vec(i)%g = 1d0
vec(i)%h = 1d0
end do
c Start time
call system_clock(time0)
c Main calculation: find the sum of all members of vec
do i=1,n
r(i) = vec(i)%a + vec(i)%b + vec(i)%c + vec(i)%d
& + vec(i)%e + vec(i)%f + vec(i)%g + vec(i)%h
end do
c Finish time
call system_clock(time1, dtime)
c Output time
time = 1d0*(time1-time0)/dtime
write(*,"(i11,f16.7)")n, time
c Deallocation
deallocate(vec, r)
end do
end program
|