# Optimizing vectorized array operations

**URL:** <https://fortran-lang.discourse.group/t/optimizing-vectorized-array-operations/9416>\
**Category:** Help\
**Created:** [March 20, 2025, 1:54pm UTC](https://fortran-lang.discourse.group/t/optimizing-vectorized-array-operations/9416 "2025-03-20T13:54:41Z")\
**Posts on this page:** 1\
**Showing post:** 44

<div class="post-metadata">

**Author:** ![zerothi](https://avatars.discourse-cdn.com/v4/letter/z/c5a1d2/32.png) [@zerothi](https://fortran-lang.discourse.group/u/zerothi)\
**Post date:** [March 27, 2025, 1:18pm UTC](https://fortran-lang.discourse.group/t/optimizing-vectorized-array-operations/9416/44 "2025-03-27T13:18:36Z")

</div>

There are lots of really good answers here! So I won’t add to those.

Let me just add a final note which makes array-syntax sub-optimal, and in this suggestion, it can kill performance.

When you do

```auto
real, allocatable :: a(:,:,:)
...

a = b

```

what the compiler will do (because of the standard) is to check if `a` has the correct shape, and if not, deallocate it, then re-allocate it, then copy. If it has the correct shape, it will just copy. However, the checks inserts lots of unnecessary code…

While this may be intended by the programmer, it can hurt performance when one is doing that call frequently, and you intentionally don’t want to check shape. So I would encourage users to adopt this standard:

```auto
a(:,:,:) = b

```

whenever you really don’t want to deallocate. The slices tells the compiler that you want to overwrite values in the array, and thus the compiler will not put in checks for shape, and re-alloc statements.  
The point is that you’ll be removing lots of branches, and gain _free_ performance.  
Once gotten use to it will also be more obvious _when_ you want what.

---

_[View the full topic](https://fortran-lang.discourse.group/t/optimizing-vectorized-array-operations/9416)._
