Re: Parallel programming with FORALL?



On Jan 11, 5:17 pm, Daniel Carrera <dcarr...@xxxxxxxxx> wrote:
Hello,

I want to write a simple program that uses both my CPU cores in
parallel. I don't care what the program does, I just want to learn how
to use both cores. So I wrote a dumb program with a non-trivial FORALL
statement. Unfortunately, it still uses only one core.

Here is my program. I tried to design it to prevent the compiler from
just pre-computing the result, and I tried to make the FORALL
expensive.

program test
    integer, parameter :: N = 10000
    integer :: i, j
    real :: A(N) , B(N,N)

    ! Generate a pseudo-random "A" seeded with the system clock.
    ! Now the compiler cannot just pre-compute the answer.
    !
    call seed_prng()
    call random_number(A)

    ! Bulk of the program is a FORALL statement.
    !
    forall (i = 1:N, j = 1:N)
        B(i,j) = gamma(A(i) + i/j)
        B(i,j) = cosh(B(j,i)) + tanh(B(i,j) + j/i)
    end forall

    ! Select a random value to print.
    !
    i = floor(1 + A(1)*N)
    j = floor(1 + A(2)*N)
    print *,"B(i,j) = ",B(i,j)

    contains
    ... define seed_prng() here ...
end program

When I compile this with GFortran (flags: -O3 -Wall) and run it, it
only uses one CPU core. I asked on the GFortran list, and someone
suggested that you have to write programs differently to make them
parallel, but didn't know how.

I was hoping that someone here might know something about parallel
programs and could help me get this program running on two cores.

Thanks for the help.

Cheers,
Daniel.

Take a look at the posts under the thread "forall efficiency and
iteration order Options". More specifically, looking at you code and
taking into account the text in a previous post

" Computes the full right handside before doing any assignment."

I think the line

B(i,j) = cosh(B(j,i)) + tanh(B(i,j) + j/i)

is using B without being initialized (I do not remember the correct
wording... I think it is "undefined"...), or I'm losing something...

If you define make the scalar assignments via DOs I think you'll see
some problems and solutions by using OpenMP in order to run in more
than one processor/core.

Fernando.
.



Relevant Pages

  • Re: Hammond Transformers and East German Tubes/Valves
    ... I have read the archives regarding Hammond transformers. ... Cores I bought. ...   Also I just got a pair of East German QQV06-40As for 99p/50c!.. ...
    (rec.audio.tubes)
  • Re: Hammond Transformers and East German Tubes/Valves
    ... I have read the archives regarding Hammond transformers. ... Cores I bought. ... nominaly 6 Ohm speakers on the 8 Ohm tap to get 3.75K A to A, ...   Also I just got a pair of East German QQV06-40As for 99p/50c!. ...
    (rec.audio.tubes)
  • Re: Tasking for Mandelbrot program
    ...   when compared to GNAT.IO.Put. ... parallelizes the computation well, and the remaining ... Here are a few timings on 8 cores. ...
    (comp.lang.ada)
  • Re: Testing cores
    ...   I have just found that the C-Cores I have have re-surfaced on flea ... Just what did you wish to find out about the cores? ... I really want to know what they will do down at 20 odd Hz. ... two QQV06-40 for a quid and two 12E14 for a quid fifty, ...
    (rec.audio.tubes)
  • Re: Hammond Transformers and East German Tubes/Valves
    ... I have read the archives regarding Hammond transformers. ... Cores I bought. ...   Also I just got a pair of East German QQV06-40As for 99p/50c!. ... The Hammonds seem good value, ...
    (rec.audio.tubes)