- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have a derived type called particle that holds the quantum numbers of a partice like so:
type(particle)
integer :: m,n,s
end type particle
I then made another type to hold an array of these particles, along with another parameter called norm:
type(basis)
type(particle), allocatable :: p(:)
real*8 :: norm
end type basis
Finally, there are different ways of grouping the parameters together (there are multiple basis states) and I need to enumerate them all and remember the results. So in my main code I have something like this:
type(basis), allocatable :: b(:)
Now suppose that I have 10 basis states, and only 3 particles. The way I was initializing my b array is like:
allocate(b(10))
do i=1,3
allocate(b(i)%p(3))
enddo
However, I just noticed when using the debugger in Visual Studio that as soon as I allocate the b array, all the sub-arrays of particles are also allocated to the same size. So instead of ending up with
b(1)%p(1)
b(1)%p(2)
b(1)%p(3)
b(2)%p(1)
b(2)%p(2)
b(2)%p(3)
...
b(10)%p(1)
I get
b(1)%p(1)
...
b(1)%p(10)
b(2)%p(1)
...
b(10)%p(10)
am I doing anything wrong?
Thanks,
Alexis
I have a derived type called particle that holds the quantum numbers of a partice like so:
type(particle)
integer :: m,n,s
end type particle
I then made another type to hold an array of these particles, along with another parameter called norm:
type(basis)
type(particle), allocatable :: p(:)
real*8 :: norm
end type basis
Finally, there are different ways of grouping the parameters together (there are multiple basis states) and I need to enumerate them all and remember the results. So in my main code I have something like this:
type(basis), allocatable :: b(:)
Now suppose that I have 10 basis states, and only 3 particles. The way I was initializing my b array is like:
allocate(b(10))
do i=1,3
allocate(b(i)%p(3))
enddo
However, I just noticed when using the debugger in Visual Studio that as soon as I allocate the b array, all the sub-arrays of particles are also allocated to the same size. So instead of ending up with
b(1)%p(1)
b(1)%p(2)
b(1)%p(3)
b(2)%p(1)
b(2)%p(2)
b(2)%p(3)
...
b(10)%p(1)
I get
b(1)%p(1)
...
b(1)%p(10)
b(2)%p(1)
...
b(10)%p(10)
am I doing anything wrong?
Thanks,
Alexis
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks like this might just be an artifact created by MS Visual Studio. When I test a little program like:
program test
use basis_module
type(basis), allocatable :: b(:)
allocate(b(10))
allocate(b(1)%p(3))
print*,'size(b)=',size(b)
print*,'size(b(1)%p=',size(b(1)%p)
stop
end
I get the expected results.
program test
use basis_module
type(basis), allocatable :: b(:)
allocate(b(10))
allocate(b(1)%p(3))
print*,'size(b)=',size(b)
print*,'size(b(1)%p=',size(b(1)%p)
stop
end
I get the expected results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the similar experience. It seems that in watch window the results displayed are wrong, but the final results of the program are correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can reproduce Alexis' problem and will let the developers know about it. It seems that the debugger is misinterpreting the information the compiler supplies.

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