Reputation: 1660
I have this question. I noticed my fortran 90 program has many subroutines that allocate big matrices in some subroutine. These matrices are local and therefore only used in that subroutines. However, I call that subroutine thousands or more of times. Is their an overhead on doing that? In the sense: does the subroutine allocate at any call the big local matrix? So maybe it would be more efficient to allocate the variables on the main program and either pass it as an argument or putting it in a module? Or no advantage on doing that? Thanks Alberto
Upvotes: 1
Views: 133
Reputation: 1556
The allocation will most likely occur every time you call the subroutine. Depending on how much time is spent inside the subroutine for each call, it may or may not induce significant overhead. Time it and find out! There are some timing routines such as secnds
and cpu_time
. My own preference is to allocate a buffer beforehand and avoid unnecessary reallocations.
Upvotes: 1