Forran for all restrictions

I tried using forall to distribute dynamic arrays, but gfortran didn't like it. I also found that write expressions are forbidden in << 20>, and I suspect read expressions too.

What other functions / operations are not allowed in the forall block?

Exactly, what kind of construction is this, except sometimes replacing do loops when the order doesn't matter? I thought this would make the encoding clearer and more elegant, especially showing that the order of operations is not important, but it seems pretty restrictive with what operations can be performed inside forall .

What are the reasons for these restrictions, that is, that they protect / prevent user intervention? Is forall useful? If so, for what purpose?

Right now, there is only one forall block in the code I'm working on, and if I completely translated it into do loops, it would give four nested loops. Which way is better?

+6
source share
2 answers

There is currently no need for FORALL or WHERE FORALL . They were introduced as part of Fortran 95 (a minor extension to Fortran 90), mainly with the goal of optimizing when vexerization of vectors was an important thing in HPC. The reason FORALL so limited in the application is precisely because it was designed to optimize the loop. Also note that FORALL not a loop line, but an assignment. Thus, only assignment operators are allowed inside a block. Theoretically, DO loops give explicit instructions on the order of indices that the processor is about to loop over. The FORALL construct allows the compiler to choose the most optimal order based on how the array is stored in memory. However, this has lost its meaning over time, since modern compilers are very good at vectorizing DO loops, and you are unlikely to notice improvements with FORALL .

See a good discussion of FORALL and WHERE here

If you are concerned about code performance, you might want to consider another compiler - PGI or ifort . From our own experience, gfortran is suitable for development, but not for HPC. You will notice several times faster execution with code compiled using pgf90 or ifort.

+11
source
Design

Forall turned out to be really too restrictive and mostly useful only for operations with arrays. For exact limits, see IBM Fortran - FORALL . Less restrictive is the do concurrent Fortran 2008 constructor. Even read and write tags are allowed there. See Intel Fortran - DO CONCURRENT and New Fortran 2008 Features .

+6
source

Source: https://habr.com/ru/post/904306/


All Articles