OpenMP
Source: examples/omp/
Link against @libomp for OpenMP support.
Prerequisites
Add libomp to your MODULE.bazel:
starlark
bazel_dep(name = "libomp", version = "21.1.8")4.A. Hello OpenMP
omp/
├── BUILD.bazel
└── hello_omp.f90fortran
program hello_omp
use omp_lib
implicit none
integer :: tid, nthreads
!$omp parallel private(tid)
tid = omp_get_thread_num()
nthreads = omp_get_num_threads()
print *, "thread", tid, "of", nthreads
!$omp end parallel
end program hello_ompstarlark
fortran_test(
name = "hello_omp",
srcs = ["hello_omp.f90"],
copts = ["-fopenmp"],
deps = ["@libomp"],
)bash
bazel test //omp:hello_omp --test_output=all thread 0 of 16
thread 2 of 16
thread 1 of 16
thread 3 of 16
thread 8 of 16
thread 9 of 16
thread 11 of 16
thread 7 of 16
thread 4 of 16
thread 10 of 16
thread 5 of 16
thread 12 of 16
thread 13 of 16
thread 14 of 16
thread 6 of 16
thread 15 of 16