# Intel vs gfortran performance

**URL:** <https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758>\
**Category:** Help\
**Created:** [November 18, 2022, 5:56am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758 "2022-11-18T05:56:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [November 18, 2022, 5:56am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/1 "2022-11-18T05:56:27Z")

</div>

**First is the output from gfortran**

![gfortran_output](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/6/6398aff7cf66414205da6ce07eb782205bd669cb.png)

**Intel output**

 ![intel_output](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/6/6e0638785a82b24195ed587e9c37445092c51838.png)

Both were run on the same system.

> Processor | 11th Gen Intel(R) Core™ i5-11500 @ 2.70GHz 2.71 GHz  
> Installed RAM | 8.00 GB (7.83 GB usable)  
> System type | 64-bit operating system, x64-based processor

How come the compute time difference is so large?

---

<div class="post-metadata">

**Author:** ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)\
**Post date:** [November 18, 2022, 6:57am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/3 "2022-11-18T06:57:27Z")

</div>

You should set the same optimize options. Generally  
`gfortran foo.f90 -O3 -march=native`  
and  
`ifort foo.f90 -O3 -xHost`

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [November 18, 2022, 7:35am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/4 "2022-11-18T07:35:02Z")

</div>

I got this warning

**ifort: command line warning #10006: ignoring unknown option ‘/xHost’**

but the code works.

intel is still (4 times) faster.

---

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [November 18, 2022, 7:50am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/5 "2022-11-18T07:50:28Z")

</div>

In my x86-64 Ubuntu system `ifort -O3 -xHost` was about 25% faster than `gfortran -O3 -march=native` with one program that spent most of its time calculating a double precision intrinsic but about 25% slower with another.  
Both programs started with `x=1`; one then went `10**9` times round a loop containing  
`x = atan(x)` , the other went `10**9` times around `x = log(1d0+x)`. Of course we were not told what Shahid’s program was doing. Integer or single or quad precision arithmetic, or non-numerical work, may give quite different run-time differences.

---

<div class="post-metadata">

**Author:** ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)\
**Post date:** [November 18, 2022, 7:57am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/6 "2022-11-18T07:57:58Z")

</div>

Sorry , On windows, It is `/QxHost`

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [November 18, 2022, 9:33am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/7 "2022-11-18T09:33:00Z")

</div>

Since we don’t have access to the source code we can’t make any specific comments as to the performance difference.

As a general comment, the two compilers are developed by two very different teams with vastly different funding sources; ifort/ifx by Intel’s engineers and gfortran mostly by open-source volunteer contributors. The really impressive part is how gfortran, a completely free and open-source compiler, is able to complete so well with a compiler that up until a couple years ago was a paid, high-end product (parallel studio XE).

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [November 18, 2022, 9:49am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/8 "2022-11-18T09:49:39Z")

</div>

The iteration has some form like that:

```auto
...
 do istep = 1, nsteps ! 1000
     do i = 1, Nx ! 512
        do j = 1, Ny ! 512

            dfde1(i,j) = -3.5*e1(i,j) + 1.5*e1(i,j)**3 + &
                &2*eta1(i,j)*( e2(i,j)**2 + e3(i,j)**2 + e4(i,j)**2 )
           .
           . ! same type of calculation for 50 times 
           .

           jp = j + 1
           jm = j - 1

           ip = i + 1
           im = i - 1

           if ( im == 0 ) im = Nx
           if ( ip == ( Nx + 1) ) ip = 1
           if ( jm == 0 ) jm = Ny
           if ( jp == ( Ny + 1) ) jp = 1

           lap_e1(i,j) = ( e1(ip,j) + e1(im,j) + e1(i,jm) + e1(i,jp) - &
                4.0*e1(i,j) ) / ( dx*dy )
           .
           . ! for 50 terms
           .

           e1(i,j) = e1(i,j) - 0.5*0.6*( dfde1(i,j) - 0.56*lap_e1(i,j) )
           .
           . ! for 50 terms
           .
        end do
    end do
end do

```

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [November 18, 2022, 9:52am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/9 "2022-11-18T09:52:56Z")

</div>

Note, that in the sample code you are accessing your 2D matrices in a non-contiguous manner, that will affect performance. Fortran is column-major, not row-major, so the loop order should be reversed.

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [November 18, 2022, 9:55am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/10 "2022-11-18T09:55:36Z")

</div>

Yeah. But the code is the same for both compilers.

---

<div class="post-metadata">

**Author:** ![FedericoPerini](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/federicoperini/32/1750_2.png) [@FedericoPerini](https://fortran-lang.discourse.group/u/FedericoPerini)\
**Post date:** [November 18, 2022, 10:04am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/11 "2022-11-18T10:04:32Z")

</div>

> [@Shahid](#):
>
> But the code is the same

Sorry but, no minimum working example, useless discussion 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 18, 2022, 10:55am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/12 "2022-11-18T10:55:53Z")

</div>

> [@Shahid](#):
>
> Yeah. But the code is the same for both compilers.

It does not follow that the progress of the calculation will be the same or that the results will be the same or even comparable. Until you establish that the program is running correctly and the results are similar, it is not useful to compare run times.

You should note that the default for Intel is “optimize” whereas for Gfortran it is not. Before you compare run times and ask why those times are different, you have to compile using optimization levels that are comparable.

---

<div class="post-metadata">

**Author:** ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)\
**Post date:** [November 18, 2022, 11:42am UTC](https://fortran-lang.discourse.group/t/intel-vs-gfortran-performance/4758/13 "2022-11-18T11:42:58Z")

</div>

Yes ,ifort will do loop-interchange but gfortran not.  
It said it can ,but actaully not.

`-floop-interchange`

> **[Using the GNU Compiler Collection (GCC): Optimize Options](https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Optimize-Options.html)**
>
> Using the GNU Compiler Collection (GCC): Optimize Options

by the way, `do concurrent` can do it.
