Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements

## Fortran 90 Optimisation

Beginner
348 Views
I have written a Fortran 90 module to perform a vector cross product with a variety of data types. These routines are called many thousands of times in my software and therefore I would like them to be inlined. However, I am unable to find an compiler option to inline the functions.

I have generated a cut down test case :-

module module_vec3d

interface cross_product
module procedure cross_product_R4_R4
end interface

contains

function cross_product_R4_R4(x, y) result(z)

real :: z(3)
real, intent(in) :: x(3), y(3)

z = (/ x(2) * y(3) - x(3) * y(2), &
x(3) * y(1) - x(1) * y(3), &
x(1) * y(2) - x(2) * y(1) /)
return
end function cross_product_R4_R4

end module module_vec3d

program try_dp

#ifndef INLINE
use module_vec3d
#endif

integer, parameter :: N = 10000
real :: a(3, N), c(3, N)
real :: time_begin, time_end
integer :: i, j

do i = 1, N
a(:, i) = (/ 0.1 + 0.05 * i / N, 0.2 - 0.1 * i / N, 0.3 - 0.05 * i / N /)
enddo
c(:,:) = 0.0

call cpu_time(time_begin)
do j = 1, N
do i = 1, N
#ifdef INLINE
c(1, j) = c(1, j) + a(2, i) * a(3, j) - a(3, i) * a(2, j)
c(2, j) = c(2, j) + a(3, i) * a(1, j) - a(1, i) * a(3, j)
c(3, j) = c(3, j) + a(1, i) * a(2, j) - a(2, i) * a(1, j)
#else
c(:, j) = c(:, j) + cross_product(a(:, i), a(:, j))
#endif
enddo
enddo
call cpu_time(time_end)
print *, time_end - time_begin

write(20,*) c

end program try_dp

Using the manual inline code (#ifdef INLINE), the run time is reduced by a factor of 3 on my machine. How can I force the compiler to inline these functions?

P.S. I have downloaded a trial version of Intel Fortran v7 and the performance for the module function is even worse.
3 Replies
Employee
348 Views
With CVF, you can use the /inline:all option - there is not a way to specify inlining of a specific routine. Note that in CVF, the inlined routine has to be in the same source file as the caller. Even with :all, your routine may not be able to be inlined.

However, it is not clear to me that the compiler can inline a function reference with array section arguments. Is there some reason why you don't just have the whole loop version as a callable routine? Compilers would be much happier with that.

Steve
Beginner
348 Views
Steve,