- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear All,
I have a mixed cpp / fortran project and I want that (in debug mode) the program stops as soon as a floating point exception occurs. Probably a classic problem but I cannot find a solution.
When I have only a Fotran program -fpe0 works perfectly (with -g and -traceback I get the correct location)
program tst
double precision dd
double precision ee
dd = 1
ee = 0
write(*,*) dd / ee
end
Compile with: ifort aaa.f90 -g -traceback -fpe0 -o aaa
Run: ./aaa
forrtl: error (73): floating divide by zero
Image PC Routine Line Source
aaa 000000000040295C MAIN__ 7 aaa.f90
aaa 0000000000402902 Unknown Unknown Unknown
libc.so.6 00000036C301D994 Unknown Unknown Unknown
aaa 0000000000402829 Unknown Unknown Unknown
Abort
When I have a cpp main program (bb.cpp) and a subroutine (aa.f90) I cannot get similar behaviour:
bb.cpp:
extern "C" {
void tst_(void);
}
main()
{
tst_();
}
aa.f90:
subroutine tst
double precision dd
double precision ee
dd = 1
ee = 0
write(*,*) dd / ee
end
Compilation:
ifort -c aa.f90 -g -traceback -fpe0
icpc -c bb.cpp -g -traceback
icpc -g -traceback -shared-intel ./bb.o ./aa.o -lguide -lpthread -lrt -ldl -lifcoremt /usr/lib64/libstdc++.so.5 -o aa
run: ./aa
Infinity
Compiler information:
> ifort --version
ifort (IFORT) 10.1 20080112
Copyright (C) 1985-2007 Intel Corporation. All rights reserved.
> icpc --version
icpc (ICC) 10.1 20080112
Copyright (C) 1985-2007 Intel Corporation. All rights reserved.
System: 64-bit linux
Has anybody a suggestion to solve this problem ?
Best Regards,
Albert
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With the 10.1 compiler, no. With this compiler, fpe0 sets up FP exception handling at the Fortran MAIN program startup. In your mixed language case, you do not have a Fortran MAIN and thus fpe0 has no effect.
This was solved in the 11.1 compiler with the -fpe-all option. This option does this: on entry to every Fortran procedure, the existing FP mask is saved, the FP mask is set to the configuration set up by the argument to fpe-all, the routine is entered and run. On exit, the FP mask is restored to it's previous value.
Note: this allows fp trapping in the Fortran routines.
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the answer, one more reason to push the migration to the 11.1 compiler.
Is there with the Intel 10.1 compiler a possibility to accomplish something that is done automatically in version 11.1 i.e. can I make a call in the C / Cpp function before calling the Fortran routine or in the Fortran routine so the floating point exception is caught.
Best Regards,
Albert
- 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
Thank you for the answer.
I get a message now: "Floatingpoint exception", with gdb I can find the place but is it also possible to have a traceback straight away (like with the Fortran only program ) ?
Albert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortran supports the nice feature -traceback, but I'm afraid there is no complete equivalent for the C/C++ compiler. The C/C++ compiler does support a -traceback option for use in mixed language programs, (see documentation), so that tracebacks get propagated through a mixed C and Fortran stack, but I'm not sure whether it works when the main program is in C, you'd have to experiment. I also suspect that it might only give the detailed function name and line number for the Fortran routines in the traceback.
You might get more suggestions for generating stack traces in the C/C++ compiler forum...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page