File: openmp_46.f90

package info (click to toggle)
lfortran 0.60.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,416 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 38; javascript: 15
file content (32 lines) | stat: -rw-r--r-- 716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
program omp_task_mre
  use omp_lib
  implicit none

  integer, parameter :: n = 10
  real :: array(n)
  integer :: i

  ! Initialize the array
  do i = 1, n
    array(i) = real(i)
  end do

  !$OMP PARALLEL SECTIONS SHARED(array)
    !$OMP SECTION
    do i = 1, n
      !$OMP TASK FIRSTPRIVATE(i) SHARED(array)
        array(i) = array(i) * real(i)
        print *, "Task: i = ", i, ", computed by thread ", omp_get_thread_num()
      !$OMP END TASK
    end do
    !$OMP SECTION
    print*, "All tasks submitted. Waiting for completion."
  !$OMP END PARALLEL SECTIONS

  ! Print the updated array
  print *, "Updated array:"
  do i = 1, n
    print *, "array(", i, ") = ", array(i)
  end do

end program omp_task_mre