# Using coarrays with two different compilers: Speed measured by code and by operative system

**URL:** <https://fortran-lang.discourse.group/t/using-coarrays-with-two-different-compilers-speed-measured-by-code-and-by-operative-system/742>\
**Category:** Uncategorized\
**Created:** [February 21, 2021, 5:36pm UTC](https://fortran-lang.discourse.group/t/using-coarrays-with-two-different-compilers-speed-measured-by-code-and-by-operative-system/742 "2021-02-21T17:36:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_GF](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/samuel_gf/32/148_2.png) [@Samuel\_GF](https://fortran-lang.discourse.group/u/Samuel_GF)\
**Post date:** [February 21, 2021, 5:36pm UTC](https://fortran-lang.discourse.group/t/using-coarrays-with-two-different-compilers-speed-measured-by-code-and-by-operative-system/742/1 "2021-02-21T17:36:31Z")

</div>

# Let’s compare two different vendors

This is the code: [compute pi](https://github.com/scivision/fortran2018-examples/blob/main/coarray/pi.f90) (It is not my code)

## Machine

- Intel Core i5 10th gen, 16GB RAM.
- GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0.
- ifort version 2021.1

## Let’s compile

```auto
$ caf -ffree-form -fcoarray=lib -O3 coarrays.f -o coarray_gfort
$ ifort -free -coarray -O3 coarrays.f -o coarray_ifort

```

# Run the program

## GFortran results

Let’s run it several times to find out a patron (this is just one of many results)

```auto
$ time cafrun -np 8 ./coarray_gfort

number of Fortran coarray images: 8
 approximating pi in 2000000 steps.
 pi: 3.1415926535897931 iterated pi: 3.1395227456008259     
pi error 0.207E-02
Elapsed wall clock time 0.475E-02 seconds, using 8 images.

real	0m0,047s
user	0m0,106s
sys	0m0,096s

```

## Intel Fortran results

```auto
$ time ./coarray_ifort

number of Fortran coarray images: 8
 approximating pi in 2000000 steps.
 pi: 3.14159265358979 iterated pi: 3.13952274560078     
pi error 0.207E-02
Elapsed wall clock time 0.224E-02 seconds, using 8 images.

real	0m0,081s
user	0m0,166s
sys	0m0,192s

```

# My questions

Although elapsed time calculated by code is better with Intel Fortran, the operative system says the GFortran program ran faster. Is this ok for you? Am I doing something wrong? I am not able to interpret results.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [February 21, 2021, 5:49pm UTC](https://fortran-lang.discourse.group/t/using-coarrays-with-two-different-compilers-speed-measured-by-code-and-by-operative-system/742/2 "2021-02-21T17:49:59Z")

</div>

I would recommend to increase the workload a bit, with timings in hundreds of second regime it might be hard to get meaningful values. Also, you want to avoid benchmarking the overhead in launching MPI (`caf` will most likely use OpenMPI and `ifort` will probably use IntelMPI here), which you might be observing in the timings from the OS.

Some blind tests to establish a baseline can help here, launching an MPI enabled binary with multiple processes has a certain overhead compared to a sequential binary and can be easily measured with and simple empty Fortran program.

---

<div class="post-metadata">

**Author:** ![billlong](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@billlong](https://fortran-lang.discourse.group/u/billlong)\
**Post date:** [February 22, 2021, 4:55am UTC](https://fortran-lang.discourse.group/t/using-coarrays-with-two-different-compilers-speed-measured-by-code-and-by-operative-system/742/3 "2021-02-22T04:55:19Z")

</div>

Another data point, in case it is interesting. Cray Fortran, Intel-broadwell target, program launch with Slurm (srun):

> ftn test\_pi.f90  
> srun -n8 -CBW28 ./a.out  
> number of Fortran coarray images: 8  
> approximating pi in 2000000 steps.  
> pi: 3.1415926535897931 iterated pi: 3.1395227456007966  
> pi error 0.207E-02  
> Elapsed wall clock time 0.172E-02 seconds, using 8 images.
