Hi here,
My initial understanding of this project was inaccurate, and I’d like to
thank the Fortran community for their valuable suggestions and guidance. To
gain a clearer understanding, I spent time reading related documents and
discussions. Based on what I’ve learned, I’ve drafted a project proposal
that outlines the project’s scope, defines its goals, presents a timeline,
and introduces my relevant background. I would greatly appreciate any
feedback or suggestions from the community on this proposal. Thanks a lot!
Google Summer of Code 2025 Proposal
*Project*: Fortran - DO CONCURRENT
Abstract
This project aims to extend GNU Fortran's support for DO CONCURRENT by
enabling actual parallel execution using OpenMP infrastructure. With OpenMP
6.0 introducing support for !$omp loop on DO CONCURRENT, we seek to
integrate this capability into GCC. The project focuses on OpenMP directive
and DO CONCURRENT clause parsing and lowering, and on leveraging libgomp to
support parallel execution. These enhancements will align GNU Fortran with
Fortran 2018/202X standards and benefit parallel scientific applications.
Introduction
OpenMP is a popular directive-based API for parallelizing code to run on
multi-core CPUs. Meanwhile, standard programming languages like C and
Fortran have also begun to introduce built-in features to help compilers
parallelize code. One such feature is Fortran’s DO CONCURRENT construct,
which can be seen as an accessible alternative for expressing parallelism.
However, its current implementation depends heavily on the compiler's
ability to auto-parallelize the code.
The good news is that it's now possible to leverage both approaches.
Recently, OpenMP released version 6.0, introducing support for applying the
OpenMP loop construct to Fortran DO CONCURRENT. This signals potential for
GCC to better integrate Fortran-native concurrency with OpenMP’s parallel
infrastructure. By supporting this new OpenMP feature, GNU Fortran users
will be able to manually parallelize their code when using DO CONCURRENT.
This project originates from the GNU community and specifically aims to
improve the GNU Fortran compiler’s support for DO CONCURRENT. Currently,
GNU Fortran can recognize DO CONCURRENT syntax, but execution is still
serial. The main goal of this project is to enable real parallel execution
of DO CONCURRENT loops.
To achieve this, we break the goal into several sub-tasks and focus on the
most essential ones for this GSoC project. We will further explain each in
the proposed solution section. To help readers unfamiliar with Fortran,
it's useful to note that the DO CONCURRENT construct can include a MASK
clause to selectively execute some loop iterations. To manually enable
parallelization, users can combine DO CONCURRENT with OpenMP directives
like !$omp loop. If OpenMP directives are not used, and parallelism is
still desired, one can rely on compiler auto-parallelization by passing
command-line flags such as those described in Task 3.
- Task 1: Handling DO CONCURRENT loops in the generic OpenMP code,
possibly starting without MASK support and only for those annotated
with !$omp
loop.
- Task 2: Extending support to include MASK or optimizing loop bounds
accordingly.
- Task 3: Supporting parallelization without !$omp loop using the
-fdo-concurrent= flag (e.g., “none”, “omp”, or “parallel”, similar to
-ftree-parallelize-loops=n).
Here is a possible example of a DO CONCURRENT loop using OpenMP !$omp loop,
with a MASK clause and locality specifiers LOCAL and LOCAL_INIT, compliant
with Fortran 2018+ and OpenMP 6.0 syntax:
program test_mask_locality
implicit none
integer :: i, a(100), b(100), t
b = [(i, i=1,100)]
t = 50
!$omp parallel
!$omp loop
do concurrent (i = 1:100, b(i) > t) local_init(a)
a(i) = b(i) * 2
end do
!$omp end loop
!$omp end parallel
print *, "Finished conditional concurrent execution"
end program test_mask_locality
Our goal is for GNU Fortran to successfully parse and execute such code,
leveraging the OpenMP infrastructure to run it in parallel. By enabling
this, we will be able to support state-of-the-art applications—for example,
some neural network training and deployment infrastructure like Fiats.
Background
The DO CONCURRENT construct was first introduced in the Fortran 2008
standard [1] to express loop-level parallelism, indicating that each
iteration of the loop is independent. It was inspired by the earlier FORALL
construct and provided a clearer semantic model for potential parallel
execution [1][2]. Later revisions of the standard have enhanced its
capabilities: Fortran 2018 [3][4] added locality specifiers such as LOCAL,
LOCAL_INIT, and SHARED, and introduced the MASK clause for conditionally
executing iterations. The upcoming Fortran 202X draft [5] proposes further
improvements, including explicit support for REDUCE clauses, making DO
CONCURRENT better aligned with parallel programming needs.
On the OpenMP side,