- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am in the process of creating a simulation code for which I end up creating derived data types, construct relatively large arrays of these data types - and manipulate them using different subroutines. To be precise, here's an example:
type compUnit
integer:: index
double precision:: p1, p2
end type compUnit
.....
type(compUnit), dimension(1000):: myUnit
< function definitions etc etc>
I am curious about the following - if I create a pointer to this array myUnit and pass it to the function, would it make the overall speed fatser/slower than if I just pass this array myUnit as it is to the subroutines that manipulate it.
Also, for the actual problem where I want to apply my simulation, there could be more data fields in the derived type compUnit. I guess this might be a naive thing to ask - but does the number of variables grouped into a derived type affect the overall speed of the application when these derived types are passed into subroutines and used in arrays and so on.
Could someone provide me with some advice on this ?
Thank you
I am in the process of creating a simulation code for which I end up creating derived data types, construct relatively large arrays of these data types - and manipulate them using different subroutines. To be precise, here's an example:
type compUnit
integer:: index
double precision:: p1, p2
end type compUnit
.....
type(compUnit), dimension(1000):: myUnit
< function definitions etc etc>
I am curious about the following - if I create a pointer to this array myUnit and pass it to the function, would it make the overall speed fatser/slower than if I just pass this array myUnit as it is to the subroutines that manipulate it.
Also, for the actual problem where I want to apply my simulation, there could be more data fields in the derived type compUnit. I guess this might be a naive thing to ask - but does the number of variables grouped into a derived type affect the overall speed of the application when these derived types are passed into subroutines and used in arrays and so on.
Could someone provide me with some advice on this ?
Thank you
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So far, you have not shown anything that would cause data to be copied. If you just pass myUnit as a whole variable, it will be passed by address, or if the caller expects a deferred-shape array and you have an explicit interface, a descriptor for the array (which is the same, pretty much, as a pointer).
Copying of data would happen if you passed a non-contiguous slice of the array to an argument that is not a deferred-shape array.
Copying of data would happen if you passed a non-contiguous slice of the array to an argument that is not a deferred-shape array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, this means that if now I had a subroutine saying
subroutine manipulate(a_input, a_output)
type(compUnit), dimension(1000), intent(in):: a_Input
.......
end subroutine manipulate
and then call it using
call manipulate(myType, output)
then myType has only it's address passed ?
And also, could you kindly explain the non-contiguous slice of an array bit.
Thank you for your help
subroutine manipulate(a_input, a_output)
type(compUnit), dimension(1000), intent(in):: a_Input
.......
end subroutine manipulate
and then call it using
call manipulate(myType, output)
then myType has only it's address passed ?
And also, could you kindly explain the non-contiguous slice of an array bit.
Thank you for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume you mean myUnit, as you have not declared anything called myType.
Yes, if you just pass myUnit that way, it will just pass the address of the array. If however you did this:
call manipulate(myType(1:999:3),output)
then this is passing every third element of the array, a non-contiguous slice, and the compiler would have to copy these elements into a temporary array and pass that. However, if there was an explicit interface for manipulate available that declared the a_input argument as DIMENSION(:), then a descriptor would be passed and no copy of the data would be done.
Yes, if you just pass myUnit that way, it will just pass the address of the array. If however you did this:
call manipulate(myType(1:999:3),output)
then this is passing every third element of the array, a non-contiguous slice, and the compiler would have to copy these elements into a temporary array and pass that. However, if there was an explicit interface for manipulate available that declared the a_input argument as DIMENSION(:), then a descriptor would be passed and no copy of the data would be done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks for helping me out with this. I think I had trouble understanding the non-contiguous slices bit for a while now - thanks for clarifying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Everybody,
>>...
>>And also, could you kindly explain the non-contiguous slice of an array bit.
>>...
It means:
call manipulate(myType(1:999:3),output
a stride, i.e. each step youmake to access a new element in the array,is equal to 3.
Here is another view on 'the non-contiguous slice of an array':
Consider acase when a huge array of data can't fit into physical memory ( RAM )of a computer and because of this some data has to be saved in Virtual Memory ( VM )file. Thisis the worst case because data will be fragmented andoverall performance of an application will go down.
Whena computerhas 32GB ofRAMplus 32GB ofVMI wouldn't worry.
But, when resources are verylimited, for example 512MB of RAM plus 32MB of VMon an abstractEmbedded Real-Time system,any fragmentation of data inRAMcreates a negative effect on the performance. It makes a difference if a matrix multiplication is done in 0.001sec or 0.005sec ( 5x slower! ).
Best regards,
Sergey
>>...
>>And also, could you kindly explain the non-contiguous slice of an array bit.
>>...
It means:
call manipulate(myType(1:999:3),output
a stride, i.e. each step youmake to access a new element in the array,is equal to 3.
Here is another view on 'the non-contiguous slice of an array':
Consider acase when a huge array of data can't fit into physical memory ( RAM )of a computer and because of this some data has to be saved in Virtual Memory ( VM )file. Thisis the worst case because data will be fragmented andoverall performance of an application will go down.
Whena computerhas 32GB ofRAMplus 32GB ofVMI wouldn't worry.
But, when resources are verylimited, for example 512MB of RAM plus 32MB of VMon an abstractEmbedded Real-Time system,any fragmentation of data inRAMcreates a negative effect on the performance. It makes a difference if a matrix multiplication is done in 0.001sec or 0.005sec ( 5x slower! ).
Best regards,
Sergey

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