Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

allocatable array efficiency issue

$
0
0

Is it normal to observe such a big difference in execution time when the allocatable arrays are used vs fixed.

an example code produces 

ifort pexcample.f90 -O3 ; time ./a.out

(a, fixed size)  Time =   0.000004 seconds.

real    0m0.041s

user    0m0.002s

sys    0m0.004s

(b, allocatable array)  Time =  14.428799 seconds.

real    0m19.532s

user    0m4.383s

sys    0m12.056s

 

program pexample
	implicit none
	integer(kind=8), parameter :: n = 1000,	m = 1024, p = 1024, np = n*m*p
!	real(kind=8) :: x(3,n,m,p)
	real(kind=8), allocatable :: x(:,:,:,:)
	real(kind=8) :: tic, toc
	integer(kind=8) :: i, j, k, l, id
	
	allocate( x(1:3,1:n,1:m,1:p) )		
	call cpu_time(tic)

	do k = 1, p
		do j = 1, m
			do i = 1, n
!				id = I + N*(J-1) + N*M*(K-1)
				x(1,i,j,k) = 0.d0!(i-1)*1.d0/(n-1)
				x(2,i,j,k) = 0.d0!(j-1)*1.d0/(m-1)					
				x(3,i,j,k) = 0.d0!(k-1)*1.d0/(p-1)
			end do
		end do
	end do
	
	call cpu_time(toc)		
	deallocate( x )
	print '("Time = ",f10.6," seconds.")', toc-tic
	
end program pexample

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>