Re: Parallel programming with FORALL?
- From: gmail-unlp <ftinetti@xxxxxxxxx>
- Date: Tue, 11 Jan 2011 13:09:53 -0800 (PST)
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.
.
- Follow-Ups:
- Re: Parallel programming with FORALL?
- From: Daniel Carrera
- Re: Parallel programming with FORALL?
- References:
- Parallel programming with FORALL?
- From: Daniel Carrera
- Parallel programming with FORALL?
- Prev by Date: Re: Parallel programming with FORALL?
- Next by Date: Re: Parallel programming with FORALL?
- Previous by thread: Re: Parallel programming with FORALL?
- Next by thread: Re: Parallel programming with FORALL?
- Index(es):
Relevant Pages
|