Intel® MPI Library
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
2154 Discussions

IFORT constant numbers

conor_p_
Beginner
471 Views

Hello,

I have frequently heard that in C++ HPC xeon phi applications, it is beneficial to declare variables as const, if possible. However, I cannot seem to ascertain whether or not this is possible in Fortran. Is there a way to do this type of optimization using ifort

 

 

0 Kudos
4 Replies
conor_p_
Beginner
471 Views

I have seen that used for doubles and ints. Would that work for an array that I am passing to a subroutine as well?

0 Kudos
TimP
Honored Contributor III
471 Views
Hard to guess without context.
0 Kudos
Ron_Green
Moderator
471 Views

I think you're asking the wrong question - the question you want to ask is 'what is the most efficient way to pass array arguments?' - this is really what you're after, correct?

Read this:  https://software.intel.com/en-us/articles/fortran-array-data-and-arguments-and-vectorization

while written for Xeon Phi it also applies to any Intel processor using the Intel Fortran compilers.

Don't forget that job #1 is to align your data and tell the compiler it is aligned:  https://software.intel.com/en-us/articles/data-alignment-to-assist-vectorization.   If you're using Phi, YOU MUST ALIGN YOUR DATA for performance.  Anything else is window dressing and minor tweaks.

You should read through the rest of the Methodology guide for more details on tuning:  https://software.intel.com/en-us/articles/programming-and-compiling-for-intel-many-integrated-core-architecture

Also, I recommend using -fno-alias -fno-fnalias if you're sure your code is not aliasing.

Ron

 

0 Kudos
conor_p_
Beginner
471 Views

Ronald I am not quite sure if that is my question, here is an example of what I am talking about

subroutine calc_sum(A,B,n,sumval)
    implicit none
    double precision :: A(n),B(n)
    double precision :: A1,B1
    double precision:: sumval
    integer :: loop1,loop2

    sumval = 0.0d0
    do loop1 = 1,n
         A1 = A(loop1)
         do loop2 = 1,n
              B1 = B(loop2)

              sumval = sumval + A1+B
         enddo
    enddo
end subroutine
    

I do not know how to tell the compiler that, for the purposes of this subroutine, the array elements are constant. For instance, if the code I were writing were in C++ (which I don't actually know, so I apologize if there is a typo in the following code) I would write the following

void calc_sum(const double A, const double B, const int n, double sumval)

I have frequently seen these types of optimizations implemented in xeon phi codes. Does the -fno-alias handle this?

Just a side question about alignment, consider the case that A were an array of structures with an odd number of double elements

type a_elements
       double precision :: a1,a2,a3
end type a_elements

type(a_elements) :: A(n)

When I run for a Xeon phi, does EVERY array element have to be aligned or just the first array element? In this example, the first array element, A(1), would be aligned when I compile with -align array64byte, but the remaining array elements would not be. If all array elements need to be aligned, how would I pad this data structure to accomplish this in Fortran?

0 Kudos
Reply