- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry just ignore me....
Message Edited by judd on 08-04-2005 10:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Alexis
Message Edited by alexismor on 08-04-2005 10:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's no guarantee that the second case will continue to work. FORALL is not appropriate for this purpose.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page