fdv
fdv

Reputation: 73

fortran compiler optimization of do cycle in include statement

I have a large Fortran code for HPC where several equations are solved over a computational grid. So in many places in the source code are placed nested do cycle to loop over the entair computational domain, shuch as

do k = 1,number_of_point_in_z
  do j = 1,number_of_point_in_y
    do i = 1,number_of_point_in_x
      ... some operations ...
    end do
  end do
end do

I would like to replace these lines with a single statment and I found the only solution to be the use of include statment, as

include 'start_domain_cycle'
      ... some operations ...
include 'end_domain_cycle'

with two files named start_domain_cycle and end_domain_cycle defined as follow

block
  integer :: i, j, k
  do k = 1,number_of_point_in_z
    do j = 1,number_of_point_in_y
      do i = 1,number_of_point_in_x

and

      end do
    end do
  end do
end block

My questions are:

  1. will the compiler be able to optimize this code when compiling with optimizations? (for example -O3 with gfortran)
  2. are there better solutions to avoid hard coding every time the do loop?

Upvotes: 0

Views: 93

Answers (1)

PierU
PierU

Reputation: 2689

  1. The source code present in the include files is first inserted where the include are, then the complete code is compiled. So from an optimisation point of view it makes no difference.

  2. A matter of personal preference... I find it more readable to have the whole code together, but this is just my opinion. You could also append the 3 do on a single line (with shorter variable names for readability)

do k = 1,nz ; do j = 1,ny ; do i = 1,nx

Upvotes: 1

Related Questions