summaryrefslogtreecommitdiffhomepage
path: root/fortran.html.markdown
diff options
context:
space:
mode:
authorIly <90933947+Ily83@users.noreply.github.com>2024-05-15 03:18:59 +0200
committerGitHub <noreply@github.com>2024-05-14 19:18:59 -0600
commit7dce0227a74f71ac8126b7f5c193433cc68f4c71 (patch)
treef8072d16c360978ccdfd1e973b756d74ab370b7a /fortran.html.markdown
parentd6244e00c1f812802ec1da2052ee1419d916bccb (diff)
[fortran/en] do concurrent (#4531)
Diffstat (limited to 'fortran.html.markdown')
-rw-r--r--fortran.html.markdown29
1 files changed, 29 insertions, 0 deletions
diff --git a/fortran.html.markdown b/fortran.html.markdown
index c0d90367..83074073 100644
--- a/fortran.html.markdown
+++ b/fortran.html.markdown
@@ -438,6 +438,35 @@ contains
end function complex_abs
end module fruity
+
+! ISO Standard Fortran 2008 introduced the DO CONCURRENT construct to allow you
+! to express loop-level parallelism
+
+integer :: i
+real :: array(100)
+
+DO CONCURRENT (i = 1:size(array))
+ array(i) = sqrt(i**i)
+END DO
+
+
+! Only calls to pure functions are allowed inside the loop and we can declare
+! multiple indices:
+
+integer :: x, y
+real :: array(8, 16)
+
+do concurrent (x = 1:size(array, 1), y = 1:size(array, 2))
+ array(x, y) = real(x)
+end do
+
+! loop indices can also declared inside the contruct:
+
+real :: array(8, 16)
+
+do concurrent (integer :: x = 1:size(array, 1), y = 1:size(array, 2))
+ array(x, y) = real(x)
+end do
```
### More Resources