Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29279 Discussions

Size and adress of named common blocks

phil31
Beginner
1,102 Views
Because I want to save a lot of commons at one time, I would like to know if it is possible to know the exact size of a given common block and its starting adress (if it is different to the one of its first element). Because I use a lot of commons blocks which have not necessarily the same dimension/content in all the subroutines where they are used. I guess (because I use this code since many years) that the real size corresponds to the max size the compileror linker find at build time. I have though to use the map file, but it will be more convenient if it would be possible to get the size with a function like sizeof().
0 Kudos
6 Replies
jim_dempsey
Beginner
1,102 Views

If you create two dummy variables in the named common block, one you force to load first, and the second you force to load last. e.g. DummyFirst and DummyLast. Then you can use LOC on the variables to get the information you want.

iSizeOfCommon

0 Kudos
jim_dempsey
Beginner
1,102 Views

If you create two dummy variables in the named common block, one you force to load first, and the second you force to load last. e.g. DummyFirst and DummyLast. Then you can use LOC on the variables to get the information you want.

iSizeOfCommon =

0 Kudos
jim_dempsey
Beginner
1,102 Views

iSizeOfCommon = LOC(DummyLast) - LOC(DummyFirst)

0 Kudos
phil31
Beginner
1,102 Views

Thank you for your reply. That was a good idea; but because I don't want to browse all my source code to find the larger declaration for a particular common (because in this caseI could read the declaration and compute the common's size), I have expected to find some function that takes the name of the common and returns its size, something like that:

common /blablabla/ first, scnd, third, ..., last
...
iSozeOfCommon = SizeOfCommon(blablabla)
or some artefact that gives the same results. I'm not sure that it's possible to proceed that way.

To be more precise, I have some declarations like:

common /THPUR/ PUR(LDTH1,NPUR) (size = LDTH1*NPUR*8)

in the main source, and in some other sources, I have:

common /THPUR/ PUR(1) (size ?)

or

real(8) PUR(LDTH1,NPUR)
common /THPUR/ PUR           (size ?)
if I look only for common declarations, I will not be able to be sure of all sizes.

					
				
			
			
				
			
			
			
			
			
			
			
		
0 Kudos
Les_Neilson
Valued Contributor II
1,102 Views
If you are only concerned with ensuring that the common blocks are defined consistently then you could consider using include files.
Have the common declared once fully inone file which is then #included by anything that needs it.
This often helps expose bugswhere variable names have been inadvertently transposed, or a "new" variable has been added but not everywhere.
Of course if the codehas different waysof looking at the data (eg PUR(J) in one place and PUR(K,L) somewhere else) then this won't work without some further rewriting :-(
If you have the time and effort - then modules is the way to go :-)
Les
0 Kudos
phil31
Beginner
1,102 Views
Yes I know that using include files or modules is a best way to solve this, but unfortunately I have not the time to develop this functionnality and the number of commons is quite big (about 160) and the references to these commons much bigger (about 2200 refs). Thank you for your advice.
0 Kudos
Reply