This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FORALL Under GFORTRAN Concurrency Test


Joseph North wrote:
> On 10/16/07, kupfem@rpi.edu <kupfem@rpi.edu> wrote:
>   
>> ==============Original message text===============
>> On Mon, 15 Oct 2007 9:27:10 EDT "Joseph North" wrote:
>>    When I tried a simple forall, it ran for ~ 4 s but only on CPU1!
>>     
FORALL is a nice idea, but its constrains make it rather difficult to
implement; it is extremely hard to make it faster than a do loop; FORALL
is translated to a loop construct by the Fortran compiler.

Note that FORALL by itself is only an assignment, there is nothing which
implies concurrency. FORALL is specified such that it allows for
concurrency, but some of the fine prints make the analysis of the code
in some cases difficult - which results in inefficient code (e.g. a
temporary array is used although it is not needed).

I have to admit I find either full-array operations  (like "a =
matmul(transpose(b),c)+d(1:100:2)") or do loops usually more readable,
which is more important than a tiny speed grain. Additionally,
full-array operations and do loops are also more likely to produce
faster code.

Up to GCC 4.2.0, it is not supported to parallize the loop. GCC 4.3.0
(not released, but the source and binaries of the experimental can be
downloaded, e.g., from the gfortran wiki,
http://gcc.gnu.org/wiki/GFortranBinaries .)

Using GCC 4.3.0 one can use -ftree-parallelize-loops=n where "n" stands
for the number of threats to be used (on a shared memory system).

This options (tries to) parallelizes all loops, including those
generated from FORALL constructs. Like all automatic parallelization
techniques, it is not guaranteed to be faster than the serial program -
it might even be slower.

For manual parallelization, one can use OpenMP or MPI. OpenMP is easier
if you have a shared-memory system and only a few loops. I think in
order to use OpenMP the FORALL assignment has to be converted into a DO
loop.

OpenMP (-fopenmp) is supported since GCC 4.2.0 and should thus work on
your system.

See http://www.openmp.org/drupal/ and
http://en.wikipedia.org/wiki/OpenMP for details.
And http://gcc.gnu.org/onlinedocs/gcc-4.2.2/libgomp/ for the GCC
defaults and environment variables.

Tobias

PS: Using "!$omp workshare"/"!$omp end workshare" around FORALL, should
work when using OpenMP. [Note 1: you need something more like !$omp
parallel etc, see any OpenMP manual. Note 2: Not tried.]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]