# 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:** 10

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [March 20, 2025, 9:44pm UTC](https://fortran-lang.discourse.group/t/optimizing-vectorized-array-operations/9416/10 "2025-03-20T21:44:39Z")

</div>

The reason in this MRE is actually obvious 🙂 …

At each iteration of the outer loop on `i`:

- In the fast version, the inner loop on `j` is executed only `N_samples=1000` times, which means that only 1000 elements of `pack_tot` are updated.
- In the slow version all the `N_grid_pack=800000` elements of `pack_tot` are updated (and the whole `line_pack` is set to zero, although you really need only 1000 elements).

---

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