Skip to content

Commit 735be70

Browse files
authored
feat: add openmp example to fortran code (#184)
1 parent 1f3602f commit 735be70

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

examples/tabulate_fortran/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ fortran_binary(
3737
modules = {
3838
"functions.f90": "user_functions.mod",
3939
},
40+
fopts = ["-fopenmp"],
41+
linkopts = ["-fopenmp"],
4042
)
4143

4244
platform_transition_filegroup(

examples/tabulate_fortran/tabulate.f90

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,27 @@
1717

1818
program tabulate
1919
use user_functions
20+
use omp_lib
2021

2122
implicit none
2223
real :: x, xbegin, xend
2324
integer :: i, steps
25+
integer :: num_threads
26+
27+
num_threads = omp_get_max_threads()
28+
write(*,*) 'Running with ', num_threads, ' OpenMP threads'
2429

2530
write(*,*) 'Please enter the range (begin, end) and the number of steps:'
2631
read(*,*) xbegin, xend, steps
2732

33+
write(*,*) 'X F(X) Thread'
34+
35+
!$omp parallel do private(x) schedule(static)
2836
do i = 0, steps
2937
x = xbegin + i * (xend - xbegin) / steps
30-
write(*,'(2f10.4)') x, f(x)
38+
!$omp critical
39+
write(*,'(2f10.4, i6)') x, f(x), omp_get_thread_num()
40+
!$omp end critical
3141
end do
42+
!$omp end parallel do
3243
end program tabulate

0 commit comments

Comments
 (0)