- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've quite a few subroutines for my cfd code. In most subroutines, I need them to accept input variables such as arrays. One e.g. is
subroutine area(xy,ab,cd,ans)
real(8), intent(in) :: xy(size_x,size_y),ab(size_x,size_y),cd(size_x,size_y)
real(8), intent(out) :: ans(size_x,size_y)
ans=ab*cd+xy
end subroutine area
Another way to do this is:
subroutine area
ans=ab*cd+xy
end subroutine area
where ans,ab,cd,xy are global variables.
If I do it by the 2nd method, will I save speed and memory? I've quite a few of the 1sttypeof subroutines andI wonder if I am wasting memory and slowing the code down. Of cos, for the 1st type, I could input different variables such as xy2,xy3 and it makes my code more compact.
Thank you.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In certain cases, where you pass an array section as an assumed size argument, there is more overhead going on, either to make a local copy at the call site, or for calculations at the top of the subroutine, associated with the size of the array.
Module variables ought to do as well as COMMON variables, but I don't think most people would call them "global."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry about that. By global variables, I mean I have a global.f90 which has:
module global_data
implicit none
save
real(8) :: ab(size_x,size_y) etc..
real(8), allocatable:: xy(:,:) etc...
end module global_data
So if I'm going by the 1st mtd, I will be wasting memory and slowing things down. Is that what you mean?
You also mention "pass an array section as an assumed size argument, there is more overhead going on". So is there a better way? And at the same time enable me to input different variables.
If not, should I try to minimize the use of the 1st mtd and and use the 2nd mtd whenever possible?
Btw, I've not used -opt-report before. I just tried it a while ago. Don't really understand but what does e.g. 5/10 (50%) mean? Just to add that I'm using -O3 and -ip or -ipo for my compilation.
Thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
so you are saying that by passing arrays as argument as in the 1st mtd, it doesn't really make much difference?
I haven't also posted in a CFD forum and one user said that:
It doesn't take up any extra memory since the arrays are not been reallocated/duplicated. Basically the first method simply passes the memory address of where the arrays are stored and then performs the calculation on that area of memory (just as if the arrays were global).
Is he/she correct?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page