This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
RE: OpenMP do loop with MAXINT
Hi Janne,
But I run with just one OpenMP thread.
The second loop will only execute one time, while the other two execute ten times. Perhaps a write statement instead of an incremented counter would make my test clearer.
Thanks for the "huge" intrinsic btw.
Paul
-----Original Message-----
From: Janne Blomqvist [mailto:blomqvist.janne@gmail.com]
Sent: 18 May 2009 16:29
To: Paul Keir
Cc: fortran@gcc.gnu.org
Subject: Re: OpenMP do loop with MAXINT[MESSAGE NOT SCANNED]
On Mon, May 18, 2009 at 18:11, Paul Keir <pkeir@dcs.gla.ac.uk> wrote:
> Hi all,
>
> The following test program gives different results for the second of its
> three do loops; relative to the first and third. Is this a bug?
It's a bug in your program, yes.
> I've used -fdump-tree-original, and it occurs to me that the use of <=
> to test against a maximal integer may play a part. I run with one
> ($OMP_NUM_THREADS) thread, and my output follows the code.
>
> Regards,
> Paul
>
> -------------------------------------------------------------
>
> program main
>
> ?integer, parameter :: ikind = 4 ! Also for 8
> ?integer(kind=ikind) :: i, maxint, stride, is30or62
> ?integer(kind=ikind) :: normalcount, ompcount1, ompcount2
>
> ?is30or62 = ikind * 8 - 2
> ?maxint = (2**is30or62)+(2**is30or62-1) ! A simpler maxint?
maxint = huge(0_ikind)
[snip]
> ?ompcount1 = 0
> !$omp parallel do
> ?do i = maxint-9, maxint
> ? ?ompcount1 = ompcount1 + 1
> ?end do
> !$end omp parallel do
The problem here is that you must specify that ompcount1 is to be used
as a reduction variable, otherwise the threads are just stomping over
it randomly. Replace the parallel do directive above with
!$omp parallel do reduction(+:ompcount1)
> ?stride = 1
> ?ompcount2 = 0
> !$omp parallel do
> ?do i = maxint-9, maxint,stride
> ? ?ompcount2 = ompcount2 + 1
> ?end do
> !$end omp parallel do
Same here.
--
Janne Blomqvist