# Comments in ResearchGate about Fortran

**URL:** <https://fortran-lang.discourse.group/t/comments-in-researchgate-about-fortran/697>\
**Category:** Uncategorized\
**Created:** [February 10, 2021, 5:17am UTC](https://fortran-lang.discourse.group/t/comments-in-researchgate-about-fortran/697 "2021-02-10T05:17:33Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [February 10, 2021, 1:18pm UTC](https://fortran-lang.discourse.group/t/comments-in-researchgate-about-fortran/697/5 "2021-02-10T13:18:52Z")

</div>

> [@Ashok](#):
>
> He says that he heard from a person belonging to Fortran standardization committee that when we use ‘OO’ features of Fortran - it slows by 100 times !! Is it true ? Any comments…

Hi Ashok,

I have seen such performance tests before in the course [“Programming with Fortran”](https://doku.lrz.de/display/PUBLIC/Programming+with+Fortran) offered at the Leibniz-Rechenzentrum. Specifically you can check the sections “Further performance aspects and use of Parameterized derived types” in the course slides.

The problem typically boils down to the issue of using an _array of structures_ (AoS) or a _structure of arrays_ (SoA). Imagine you are doing a particle simulation. Each particle can be represented as an instance of the derived type:

```auto
type :: body
  character(len =4) :: units
  real :: mass
  real :: pos(3), vel(3)
end type body

```

In your main code you will then allocate an array of bodies:

```auto
type(body), allocatable :: traj(:)
allocate(traj(ntraj))

```

Alternatively, you can fold the array properties into the derived type:

```auto
type :: body_p( k, ntraj)
  integer, kind :: k = kind(1.0)
  integer, len :: ntraj = 1
  character(len=4) :: units
  real(kind=k) :: mass(ntraj)
  real(kind=k) :: pos(ntraj,3), vel (ntraj,3)
end type body_p

```

In the main code you would use this structure of arrays as follows:

```auto
type( body_p(ntraj=:) ), allocatable :: dyn_traj
allocate(body_p(ntraj=20) :: dyn_trag)

```

What is not immediately obvious is the two objects differ in their memory alignment as illustrated by the image below:

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/1X/5eea6001ac7bca81952361163fd9153b91d09dbb.png)

Depending what you are doing with the particles, the size of your array, compiler, etc. - the contiguous memory layout in the SoA format can potentially lead to improved vectorization, resulting in faster executables.

In some cases the poor performance of derived types, could be simply due to an immature compiler implementation, which doesn’t manage to exploit all the vectorization opportunities.

---

_[View the full topic](https://fortran-lang.discourse.group/t/comments-in-researchgate-about-fortran/697)._
