Why do you lose performance that way? I don’t want to lose performance.
the nvidia compiler seems to be evil to my application when I do this haha I assume it’s that the optimizer is looking first into the subroutine and not the whole do concurrent + atomics in one single big block and might not be inlining something or eliminating some dependencies. I haven’t looked at the assembly (yet)
Hi Jorge,
I suspect that Nvidia compiler can lose performances not only because of atomic/inlining, but also for the reduce: it creates private copies that could create a lot of memory overhead depending of kind of reduce.
I have not read all your examples, but if the reduce is done on (even small) array, my first step is investigating the reduce overhead. The “-Minfo=accel” “-gpu=ptxinfo” compiler flags give useful information, generally.
For the inlining, I often pass “-lto” to force the compiler to use more effort in inlining and generating faster executables, but with not negligible increase of compilation time, unfortunately.
My best regards.
Stefano
You can hack your compiler to make it believe that the print is pure. The trick is used here: GitHub - plevold/fortran-debug-utils: Some debug utilities for Fortran · GitHub
It’s probably not very standard compliant though.
My main question is if this is a problem with the language (then let’s fix it!) or it’s a problem in a particular compiler (then let’s fix the compiler!). Or both (then let’s fix both!).
Oh, it definitely is a problem with the language!
Fortran really needs a do parallel facility that is a simple, explicit directive by the Fortranner to run in parallel..
Not the compiler vendor saying “may be your executions will run concurrently if you are sitting in an ivory tower and you’re ‘really nice’ to me, I’m in a good mood, and it’s prime time in a galaxy far, far away ..” which is the case with do concurrent in the current standard, honestly the standardese on this feature is weasel words.
The word “concurrent” as used in the language standard is almost synonymous with “parallel”. So the question I think is what exactly can a high-level language do to make better use of the available hardware?
To me, it seems odd that “concurrent” has come to mean “offload to gpu hardware”. Its original meaning was simply to do things in parallel (i.e. concurrently) with the semantics that the various iterations of the loop can occur in arbitrary order, without being tied tightly to gpu hardware or to any other hardware that might become available in the future while the fortran language is still in use. I think there should have been a new syntax/semantics introduced to allow the programmer to specify gpu hardware if available, or to compile to cpu+vector instructions if not. With the current situation, the programmer has lost some control over the low-level code, not gained it.
LFortran gives you a compiler error if you have do concurrent and use GPU offloading and it cannot be offloaded. So that should fix this particular problem, no?
I have little to no experience with DO CONCURRENT but do all the compilers that support it at least throw a warning if there are dependencies that will inhibit parallel/out of order execution.
LFortran gives an error, but you can override it with a --gpu-allow-cpu-fallback compiler flag that will make it run on a CPU instead if it cannot be offloaded.
So even if you are telling it to use the CPU, will compilers still give a warning if it has to resort to executing in a serial manner as opposed to executing in parallel. I presume this is the fallback.
When you ask to run do concurrent using openmp on a CPU, I think we currently always run it. But should introduce a similar error + compiler override option as we do for a GPU. Good point.
- Under the current standard,
do concurrentis merely a semantic assertion by the programmer that loop iterations have no interdependencies and can execute in any arbitrary order. A compiler is completely standard-conforming if it executes ado concurrentloop purely sequentially on a single thread, - There is unpredictability and fragility of compiler auto-parallelization which impacts
do concurrent. This causes real-world pain points for Fortranners outside of the “ivory towers” and “national labs”, - Even when you pass the right compiler flags, whether a
do concurrentloop actually runs in parallel depends entirely on internal compiler cost-models and heuristics. Minor, seemingly unrelated changes in your code can silently cause the compiler to drop parallelization and fall back to serial execution without warning, - Each compiler vendor (NVIDIA
nvfortran, Intelifx, GNUgfortran, LLVMflang) implementsdo concurrentdifferently. Code that offloads smoothly to a GPU on one compiler might run serially on another, or require completely different flag combinations, - Because the standard deliberately avoids dictating hardware execution models (threads, SIMD, GPUs) to preserve broad portability, it uses weasel language (“may execute in any order”). To a working scientist or engineer who seeks parallel execution, that is an evasion of responsibility,
- Modern hardware is inherently parallel. Treating parallel execution as a non-binding “hint” rather than a first-class, guaranteed execution model creates a usability gap compared to modern frameworks or directive-based standards like OpenMP. Furthermore, reliance on vendor-specific flags hurts Fortran’s supposed selling point: write-once, run-anywhere portability across decades of hardware,
- Fortran needs a built-in construct that carries an explicit execution mandate - an initial go-by to study and design might be
!$omp parallel doin OpenMP - thus saydo parallel. It shall be natively integrated into the core Fortran syntax without relying on external comment directives or vendor-specific compiler flags (-stdpar,-fopenmp,-qopenmp) to wake up the parallelizer,
I tend to disagree. For instance every modern CPU architecture has had vectorised instructions for decades, and in practice all of us almost completely rely on the ability of the compilers to vectorize the simple do loops. OpenMP directives can help in difficult cases by telling the compiler “you can vectorize, it’s OK”, and do concurrent is supposed to tell the compiler “it’s OK” too. If we rely on the compiler to vectorize, we can as well rely on it to multithread.
Yes, I agree with @PierU on this, I think the jury is still out. We need to actually spend good effort optimizing do concurrent both on CPU and GPUs and see what performance we can reliably get. So far the experience with my prototype is super encouraging, but that was for one code and one specific hardware. Now we need to extend it to all codes (especially large codes) on all hardware. If more is needed to specify more explicitly in the language itself, then we need to extend it, based on the evidence that we’ll uncover.
To be fair to the compiler writers I’ve had the same compiler problem with C++ on the parallel front. The 2017 C++ standard introduced parallelisation of the STL. It took a relatively long time to get reasonable cross compiler support for parallel sorting. I’ve had issues with g++ as recently as the 15.2.0 release.
There are various possibilities. There can be a single-thread cpu version, single-thread cpu+vector version, single-thread cpu+gpu version, and then also these same multithread versions. One possibility might be to write a single fortran code, and then direct the compiler to generate some or all of these versions with some kind of hints about which should be used (based on array dimensions, memory requirements, etc.). But a more complicated code might use different algorithms, with different fortran code, for some or all of these cases. Is it reasonable to expect to do this in a high-level language, or is the programmer expected to write low-level code (e.g. cuda) for the various possibilities? A high-level programming language is always going to use some kind of “weasel language” to cover the possibilities in an abstract way, but it might also give the programmer some control. This seems to me like a complicated and difficult language design problem.
Isn’t this the OpenMP specification ?
Surely we have to work from what has become a very useful addition to Fortran.
My 12 years of effectively using OpenMP tells me that “do parallel” should not be treated as simple !
My problem with OpenMP is the complexity of off-loading to GPU, which I have found very complex, which is not the OpenMP specification’s fault.
We need to push for a standardisation of the instruction set for use of GPU, which looks to be to be a bit of the “Wild West” of operation. This interface needs a standard for GPU developers to adopt, as at the moment we have different Fortran compilers for each GPU.
A standard interface is required.
My other problem with converting DO CONCURRENT to multi-threading is the need to make it practical. (I recall) Ifort had a test to estimate if the multi-threading would produce a better result. Most of the DO CONCURRENT examples I see appear to fail this test, which shows some ignorance of what is needed. Perhaps the restrictions on DO CONCURRENT should also be reviewed, especially as new locality-spec options are introduced.