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

problem with intel fortran debugger when using modules, global variables, and multiple files

Alexandros_Gezerlis
408 Views

Hey there,

I am trying to use the debugger (idb) on the head node of a linux cluster when compiling with intel fortran (ifort 10.1.011). I have multiple files, each one of which contains one module. This is a simplified test, not a production code, in which I am trying to see if I can access global variables when using idb on my program executable.

In more detail: I have three files/modules,

a) global.f90 which defines a module called global, containing a number of constants (parameter, public).

b) functions.f90 which defines a module called functions, and also uses the global module.

c) prog.f90 which contains the main program, and also uses the global and functions modules.

All of the above files include "implicit none". I compile the first two files by saying

[bash]ifort global.f90 -g -c[/bash]

(and similarly for functions.f90). If I try to use only the -g flag, I get:

[bash]/opt/intel/fce/10.1.011/lib/for_main.o(.text+0x26): In function `main':
: undefined reference to `MAIN__'[/bash]

which I assume is there because these files don't contain a program but only define a module each.

Then I link by saying

[bash]ifort -g global.o functions.o prog.f90 -o prog[/bash]

After this, I invoke the intel debugger by saying

[bash]idb prog[/bash]

and when I am in the debugger, I write

[bash]break 40[/bash]

which was kind of arbitrarily chosen, and then I say

[sectionBody]
run[/sectionBody]

If I then type

[sectionBody]
print progVariable[/sectionBody]


where progVariable is a variable that is contained in the prog.f90 file in the first 40 lines, I see as output the value that this variable has already been given by my program up to that point.

So here is my question (finally!): when I try to print the value of a global variable (i.e. a parameter defined in the global module which is used by my program.f90 file) by saying

[bash]print globalVariable[/bash]

I get

[sectionBody]
No symbol "globalVariable" in current context.
cannot evaluate globalVariable[/sectionBody]

I read somewhere in the documentation that when trying to access a variable from a different scope I should use "%%", so I also tried
[sectionBody]
print global%%globalVariable [/sectionBody]

but that now says

[sectionBody]
[/sectionBody]
[bash]No symbol "global" in current context.
cannot evaluate global%%globalVariable[/bash]

I have also tried compiling the global.f90 and the functions.f90 files using only the -c flag (i.e. not -c -g) but exactly the same thing happens.

I feel that there must be something trivial I am missing. Any feedback?

Alex Gezerlis


0 Kudos
5 Replies
Ron_Green
Moderator
408 Views

Alex,


The version of the compiler and IDB you are using is ancient, from November 2007. There were a number of issues with IDB debugging Fortran 90 codes with module data in the 10.1 compiler. There was a substantial effort put into 11.0 and 11.1 versions to correct these problems.

If you are licensed, download a new version from https://registrationcenter.intel.com. If your license has expired, download the newest version of the compiler that your license will allow. Also, you can try an evaluation version to see if you still see the problems you mention.

If you want to attach your program, one of us would be happy to see if there is still a problem with the latest compilers.

ron

0 Kudos
Alexandros_Gezerlis
408 Views

Hi Ron,

Thanks for your response. I'm going to contact my sys admin regarding the license we have at work, and also try to install the latest version of ifort on my personal laptop. In the meantime, here is a bare-bones version of the test case:

global.f90

[bash]module global

implicit none

integer, parameter, public :: globalVariable = 25

end module global
[/bash]

prog.f90

[bash]program prog

use global

implicit none

double precision progVariable

progVariable = 3.D0

stop

end[/bash]


As I explained in my previous post, I have tried doing the following in turn:

[bash]ifort global.f90 -g -c

ifort -g global.o prog.f90 -o prog

idb prog

break 10

run

print progVariable

print globalVariable

print global%%globalVariable[/bash]

Thanks for all your help, I appreciate it.

Alex

PS: Some of the code appears weird when I post it here, but I hope getting the right version is straightforward.

0 Kudos
Ron_Green
Moderator
408 Views

Well, first: PARAMETER variables are removed by the compiler, so no matter what version you use you cannot examine the values of PARAMETERs. It's an optimization, all occurances of a parameterized variable are replaced with the value during compilation. So by the time the objects are created, those symbol names are gone.

BUT if you have something like this:

global.f90

[bash]module global
implicit none

integer, public :: globalVariable = 25

end module global
[/bash]

prog.f90

[fortran]program prog

use global

implicit none

real (kind=8) :: progVariable
integer :: tellme

progVariable = 3.0_8
tellme = globalVariable

stop
end
[/fortran]

where the STOP is line 13 in the main:

[rwgreen@dpd22 72739]$ ifort -g -c global.f90
[rwgreen@dpd22 72739]$ ifort -g -o prog prog.f90 global.o
[rwgreen@dpd22 72739]$ idbc ./prog
Intel Debugger for applications running on Intel 64, Version 11.1, Build [1.2097.2.333]
------------------
object file name: ./prog
Reading symbols from /net/spd64/var/quad/rwgreen/forums/72739/prog...done.
(idb) list
5 implicit none
6
7 real (kind=8) :: progVariable
8 integer :: tellme
9
10 progVariable = 3.0_8
11 tellme = globalVariable
12
13 stop
14 end
(idb) break 13
Breakpoint 1 at 0x402b0d: file /net/spd64/var/quad/rwgreen/forums/72739/prog.f90, line 13.
(idb) run
[New Thread 46912496307200 (LWP 31634)]
[New Thread 46912496307200 (LWP 31634)]
Starting program: /net/spd64/var/quad/rwgreen/forums/72739/prog

Breakpoint 1, prog () at /net/spd64/var/quad/rwgreen/forums/72739/prog.f90:13
13 stop

(idb) print tellme
$1 = 25
(idb) print globalVariable
$2 = 25
(idb) print progVariable
$3 = 3
(idb)

Starting with the 11.0 compiler, the command 'idb' starts an X11 GUI front end to the compiler, whereas 'idbc' brings up the old command line version (above). Usually I use the graphical IDB these days, but thought it would be easier to demonstrate with command line.

So module variables are easy to view, but PARAMETERs are removed by the compiler.

ron

0 Kudos
Steven_L_Intel1
Employee
408 Views

-debug parameters

lets you view PARAMETER (and ENUMERATOR) constants in the debugger.

0 Kudos
Alexandros_Gezerlis
408 Views

To Ron: it makes sense that parameters would be optimized away. Thanks for pointing this out. I just checked my code (removing "parameter") and it works for ifort 10.1.011 similarly to what you show, but I have to say "global%%globalVariable", not just "globalVariable".


To Steve: thanks for the pointer (I guess the missing hyphen is a typo). Your post made me go through the ifort man pages, and there I found "-debug-parameters all" which does exactly what you say. Thanks! I still have to say "global%%globalVariable", instead of "globalVariable" but a) as I said above that is probably a 10.1.011 issue, and b) it works, so it doesn't really matter that I have to use a scope operator.

Thanks again to both of you. I really appreciate your help.

Alex

0 Kudos
Reply