# OpenMP reduction with max/min function

**URL:** <https://fortran-lang.discourse.group/t/openmp-reduction-with-max-min-function/4966>\
**Category:** Help\
**Created:** [January 1, 2023, 2:43am UTC](https://fortran-lang.discourse.group/t/openmp-reduction-with-max-min-function/4966 "2023-01-01T02:43:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fortran4r](https://avatars.discourse-cdn.com/v4/letter/f/9de0a6/32.png) [@fortran4r](https://fortran-lang.discourse.group/u/fortran4r)\
**Post date:** [January 1, 2023, 2:43am UTC](https://fortran-lang.discourse.group/t/openmp-reduction-with-max-min-function/4966/1 "2023-01-01T02:43:19Z")

</div>

According to the OpenMP reference, Fortran supports reduction with max/min function, which is not supported in C++. Could anyone please explain to me how an OpenMP do loop can use reduction with max/min function?

> **[OpenMPRefCard-5-2-web.pdf](https://www.openmp.org/wp-content/uploads/OpenMPRefCard-5-2-web.pdf)**
>
> 1488.15 KB

---

<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:** [January 2, 2023, 7:01am UTC](https://fortran-lang.discourse.group/t/openmp-reduction-with-max-min-function/4966/2 "2023-01-02T07:01:28Z")

</div>

```fortran
program max_reduction
implicit none

integer :: a(8),v, i

a = [4,2,3,1,8,6,7,5]

v = a(1)

!$omp parallel do default(none) shared(a) reduction(max: v)
do i = 1, 8
   v = max(a(i),v)
end do
!$omp end parallel do

print *, "max(a) = ", v
end program

```
