Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Weird compiler bug?

alexismor
Beginner
692 Views
Hi everyone,

Something's weird with the FORALL command with ifort compiler and derived types. Try the little program that I've attached. Basically, I have a derived type that's an array of another. When I do this line


forall (i=1:3) A(b%p(i)%m)=A(b%p(i)%m)+1

where I have declared

type particle
integer :: m,n !Quantum numbers
end type particle
type basis
type(particle), allocatable :: p(:)
end type basis

I don't get what I should. For the life of me, I can't figure out why they aren't. Any ideas? Thanks!

Alexis

Message Edited by alexismor on 08-03-2005 09:32 PM

Message Edited by alexismor on 08-03-2005 09:33 PM

0 Kudos
5 Replies
alexismor
Beginner
692 Views
I'm not sure if the attachement is working...

Here's the program:


Program bla
implicit none
type particle
integer :: m,n !Quantum numbers
end type particle
type basis
type(particle), allocatable :: p(:)
end type basis
type(basis) :: b
integer :: i,j,A(3),list(3)

!Initialization

allocate(b%p(3)) !There are 3 particles in my basis
b%p(1)%m=1
b%p(2)%m=2
b%p(3)%m=2
A=0
list=b%p%m
!Weird result

forall (i=1:3) A(b%p(i)%m)=A(b%p(i)%m)+1
print*,'Wrong!'
print*,'A=',A

!This should give A=(1,2,0), but instead I get A=(1,1,0). If I instead
!use the list, I get:

A=0
forall (i=1:3) A(list(i))=A(list(i))+1
print*,' '
print*,'Right!'
print*,'A=',A
stop
end
0 Kudos
Intel_C_Intel
Employee
692 Views
Sorry just ignore me....

Message Edited by judd on 08-04-2005 10:06 AM

0 Kudos
Steven_L_Intel1
Employee
692 Views
I believe that your program is illegal. One of the FORALL rules is "No element of an array can be assigned a value more than once." You have A(2) assigned twice.
0 Kudos
alexismor
Beginner
692 Views
Thanks for the reply. I didn't know that I wasn't allowed to assign an array value more than once. The purpose for my forall statement was to count the number of times values in an array occured and store them in another array. Still, it's strange that my code works the way I want it to in the second case and not in the first. I guess that I can't complain if it's not legal fortran though...

Alexis

Message Edited by alexismor on 08-04-2005 10:03 AM

0 Kudos
Steven_L_Intel1
Employee
692 Views
There's no guarantee that the second case will continue to work. FORALL is not appropriate for this purpose.
0 Kudos
Reply