- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm in the process of eliminating all common blocks in my program. The reason for this is many arrays have been created and given the maximum size they could possibly need when I run this program. Instead I wanted to read the size they'd need from a text file and dynamically allocate the arrays. Should moving from common blocks to dynamically allocated arrays make performance better?
Here is an example of what I'm doing:
SUBROUTINE SUB1
COMMON/TEST1/ARRAY1(99),ARRAY2(99),ARRAY3(99)
...
END SUBROUTINE SUB1
REPLACED WITH:
MODULE TESTMOD1
REAL, ALLOCATABLE :: ARRAY1(:),ARRAY2(:),ARRAY3(:)
...
END MODULE TESTMOD1
SUBROUTINE ALLOCATE_ARRAYS()
USE TESTMOD1
ALLOCATE(ARRAY1(SIZE))
ALLOCATE(ARRAY2(SIZE))
ALLOCATE(ARRAY3(SIZE))
END SUBROUTINE ALLOCATE_ARRAYS
PROGRAM TESTPROGRAM
USE TESTMOD1
!CODE TO READ ARRAY SIZE
...
CALL ALLOCATE_ARRAYS()
STOP
END
If my goal is to increase readability/supportability of the code, and to increase performance, is this the best way to eliminate common blocks?
I tried grouping the allocate statements in one line like:
ALLOCATE(ARRAY1(SIZE), ARRAY2(SIZE), ARRAY3(SIZE)...........)
I did this with maybe a hundred arrays. This led me to an error that I had no virtual memory free.
Do I really need a separate ALLOCATE for each array?
Thanks,
EP
I'm in the process of eliminating all common blocks in my program. The reason for this is many arrays have been created and given the maximum size they could possibly need when I run this program. Instead I wanted to read the size they'd need from a text file and dynamically allocate the arrays. Should moving from common blocks to dynamically allocated arrays make performance better?
Here is an example of what I'm doing:
SUBROUTINE SUB1
COMMON/TEST1/ARRAY1(99),ARRAY2(99),ARRAY3(99)
...
END SUBROUTINE SUB1
REPLACED WITH:
MODULE TESTMOD1
REAL, ALLOCATABLE :: ARRAY1(:),ARRAY2(:),ARRAY3(:)
...
END MODULE TESTMOD1
SUBROUTINE ALLOCATE_ARRAYS()
USE TESTMOD1
ALLOCATE(ARRAY1(SIZE))
ALLOCATE(ARRAY2(SIZE))
ALLOCATE(ARRAY3(SIZE))
END SUBROUTINE ALLOCATE_ARRAYS
PROGRAM TESTPROGRAM
USE TESTMOD1
!CODE TO READ ARRAY SIZE
...
CALL ALLOCATE_ARRAYS()
STOP
END
If my goal is to increase readability/supportability of the code, and to increase performance, is this the best way to eliminate common blocks?
I tried grouping the allocate statements in one line like:
ALLOCATE(ARRAY1(SIZE), ARRAY2(SIZE), ARRAY3(SIZE)...........)
I did this with maybe a hundred arrays. This led me to an error that I had no virtual memory free.
Do I really need a separate ALLOCATE for each array?
Thanks,
EP
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd say you have the right approach. As a matter of style, I would use separate ALLOCATE statements as that allows you to use STAT= on each one to detect errors. Otherwise, there is no functional difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Ernie P.
If my goal is to increase readability/supportability of the code, and to increase performance,
As far as increase is performance is concerned, i once did the similar job and got a huge performance uplift. this is generally true if your array size is variable: so, it compiler will not allocate unnecessary memory.(this is how i can explain this...i really dont know the inner working).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
I'd say you have the right approach. As a matter of style, I would use separate ALLOCATE statements as that allows you to use STAT= on each one to detect errors. Otherwise, there is no functional difference.
Thanks for the replies.
A couple other questions:
If I include USE, ONLY to only allow specific variables to be visible to a subroutine, would that increase performance over not including ONLY and making every variable available? Or is ONLY more to keep one from altering a variable they didn't intend to?
Main main goal is increasing performance,more specifically, execution time. Is there a discussion of general ideas/topics related to increasing performance that you're aware of that could help me out? I know there is a lot I could do with compiler settings - I was hoping to be lazy and find similar discussions that people have already had.
Thanks
EP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Ernie P.
If I include USE, ONLY to only allow specific variables to be visible to a subroutine, would that increase performance over not including ONLY and making every variable available?
The performance effects of USE vs COMMON are complicated, so simple generalizations are likely to be wrong.

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