- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If I have the derived type below :
type test
integer :: k,ij(2)
real :: xy(2)
end type test
type(test) :: t1(10,10)
Are the variables aligned in this way :
t1(1,1)%k,t1(1,1)%ij(1),t1(1,1)%ij(2),t1(1,1)%xy(1),t1(1,1)%xy(2)
t1(1,2)%k,t1(1,2)%ij(1),t1(1,2)%ij(2),t1(1,2)%xy(1),t1(1,2)%xy(2) ... ?
or
t1(1,1)%k,t1(1,2)%k,t1(1,3)%k, ...
t1(1,1)%ij(1),t1(1,2)%ij(1),t1(1,3)%ij(1) ... ?
or even
t1(1,1)%k,t1(1,2)%k,t1(1,3)%k, ...
t1(1,1)%ij(1),t1(1,1)%ij(2),t1(1,2)%ij(1),t1(1,2)%ij(2) ... ?
Can I choose how the variables are stored in memory?
Also, do I need to use -align records during compilation whenever I have derived types?
thank you!
If I have the derived type below :
type test
integer :: k,ij(2)
real :: xy(2)
end type test
type(test) :: t1(10,10)
Are the variables aligned in this way :
t1(1,1)%k,t1(1,1)%ij(1),t1(1,1)%ij(2),t1(1,1)%xy(1),t1(1,1)%xy(2)
t1(1,2)%k,t1(1,2)%ij(1),t1(1,2)%ij(2),t1(1,2)%xy(1),t1(1,2)%xy(2) ... ?
or
t1(1,1)%k,t1(1,2)%k,t1(1,3)%k, ...
t1(1,1)%ij(1),t1(1,2)%ij(1),t1(1,3)%ij(1) ... ?
or even
t1(1,1)%k,t1(1,2)%k,t1(1,3)%k, ...
t1(1,1)%ij(1),t1(1,1)%ij(2),t1(1,2)%ij(1),t1(1,2)%ij(2) ... ?
Can I choose how the variables are stored in memory?
Also, do I need to use -align records during compilation whenever I have derived types?
thank you!
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SEQUENCE will give you the first layout. I would not use the word "aligned" here, as it means something different than I think you are using.
I don't see a problem, offhand, with the current layout and your proposed code. I suggest that you write your program for clarity and correctness first. Run the program through Intel VTune Amplifier to see if you are getting memory contention or cache miss issues. Ideally you want to keep your memory references near each other if they are small.
I don't see a problem, offhand, with the current layout and your proposed code. I suggest that you write your program for clarity and correctness first. Run the program through Intel VTune Amplifier to see if you are getting memory contention or cache miss issues. Ideally you want to keep your memory references near each other if they are small.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look in the documentation for SEQUENCE
Jim Dempsey
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Without SEQUENCE or BIND(C), you cannot depend on the relative order of components within the derived type, but the answer to your general question is that the first layout you show is what you get. Within each element of t1, each of its components are together.
SEQUENCE prevents the compiler from rearranging the components, but does not necessarily prevent padding between components for alignment. Intel Fortran does not add padding, by default, for SEQUENCE types, though you can request that with -align sequence.
BIND(C) specifies that the order of the components, and alignment padding, is exactly the same as what the "companion C compiler" would do for an equivalent struct (though array components are still laid out in Fortran's column-major order.)
You do not "need" to use -align records - but you can if you wish. For the type you show, no alignment would be added even if you added that option, since all the components are naturally aligned.
SEQUENCE prevents the compiler from rearranging the components, but does not necessarily prevent padding between components for alignment. Intel Fortran does not add padding, by default, for SEQUENCE types, though you can request that with -align sequence.
BIND(C) specifies that the order of the components, and alignment padding, is exactly the same as what the "companion C compiler" would do for an equivalent struct (though array components are still laid out in Fortran's column-major order.)
You do not "need" to use -align records - but you can if you wish. For the type you show, no alignment would be added even if you added that option, since all the components are naturally aligned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I googled for the use of SEQUENCE and it gives me the idea that it will ensure that the memory will be aligned according to the first layout, is that so?
Is there anyway I can get layout 2 or even 3 thru some means?
This is because in my code, I have something like:
do j = 1,10
do i = 1,10
ii = t1(i,j)%ij(1); jj = t1(i,j)%ij(2)
expression involving ii,jj ....
end do
end do
Is it better/faster if I just declare the array ij(2,10,10)?
thank you!
I googled for the use of SEQUENCE and it gives me the idea that it will ensure that the memory will be aligned according to the first layout, is that so?
Is there anyway I can get layout 2 or even 3 thru some means?
This is because in my code, I have something like:
do j = 1,10
do i = 1,10
ii = t1(i,j)%ij(1); jj = t1(i,j)%ij(2)
expression involving ii,jj ....
end do
end do
Is it better/faster if I just declare the array ij(2,10,10)?
thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SEQUENCE will give you the first layout. I would not use the word "aligned" here, as it means something different than I think you are using.
I don't see a problem, offhand, with the current layout and your proposed code. I suggest that you write your program for clarity and correctness first. Run the program through Intel VTune Amplifier to see if you are getting memory contention or cache miss issues. Ideally you want to keep your memory references near each other if they are small.
I don't see a problem, offhand, with the current layout and your proposed code. I suggest that you write your program for clarity and correctness first. Run the program through Intel VTune Amplifier to see if you are getting memory contention or cache miss issues. Ideally you want to keep your memory references near each other if they are small.

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