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

Debug and Release compiler directives

elquin
Beginner
929 Views

In building code by debug mode, PRINT or WRITE of variables on screen are needed but not in release mode.

If possible, I want to make this PRINT routine control by compiler directives such as

!DEC$ ()...

   SOME PRINT STATEMENT ONLY ACTIVATE IN DEBUG MODE, NOT IN RELEASE MODE

!DEC$ ()

 

Thanks,

HK

 

0 Kudos
6 Replies
onkelhotte
New Contributor II
929 Views

You need to set a value in

Project Properties - Fortran - General - Preprocessor Definitions

For example I have set these two:

ONLINE; DEBUG

In my code I can now check:

[fortran]

!DEC$ IF DEFINED (ONLINE)

i = 1

!DEC$ ELSE

i = 2

!DEC$ END IF

!DEC$ IF .NOT. DEFINED (ONLINE)

i = 2

!DEC$ END IF

!DEC$ IF DEFINED (DEBUG)

nz = nz * 4

!DEC$ END IF

[/fortran]

I don´t think that this is case senstive.

Markus

0 Kudos
andrew_4619
Honored Contributor II
929 Views

Id there any way to use !DEC$ IF  for debug without having to actual set a Pre-processor Definitions. It would be good to have some code that is only for debug but without some auto detection there is more risk of  getting it wrong....

 

0 Kudos
FortranFan
Honored Contributor II
929 Views

app4619 wrote:

Id there any way to use !DEC$ IF  for debug without having to actual set a Pre-processor Definitions. It would be good to have some code that is only for debug but without some auto detection there is more risk of  getting it wrong....

I believe _DEBUG gets defined by default in Visual Studio if the configuration is DEBUG.  But you would still need !DEC$ IF DEFINED (_DEBUG) in your code to make use of it.  But then another problem is one can undefine this definition in a Visual Studio setting and if that's done, the code will not process as intended.  Also, a thing to note is at the command-line level, everything is based on selected options whether by Visual Studio or by the user directly.  As far as I know, there is no built-in setting if -g (debug compile) option is specified at the command level.  So I'm not sure there is any way to ensure reliable "auto detection".  It is probably better for code developers to be conscious about it and do things correctly.

0 Kudos
andrew_4619
Honored Contributor II
929 Views

Thanks for the thoughts I will check that out and have a play with this area to find the compromise that works best for me.

FortranFan wrote:
!DEC$ IF   It is probably better for code developers to be conscious about it and do things correctly.

This is clearly true, however, many things can and do go wrong so reducing the list of things that can go wrong stands a good chance reducing the number of things that do go wrong. 

Perhaps setting defining mydebug=0 or 1 in the release and debug settings and in the case that mydebug is undefined have a line of dependant code the causes the compiler to cough and throw its teddy out of the pram. That is pure theorising as I have not yet investigated what is possible....

0 Kudos
Xj_Kong
Novice
929 Views

I tested (DEBUG) is not working. It is true that _DEBUG gets defined by default in Visual Studio if the configuration is DEBUG.

Thanks,

 

0 Kudos
Steven_L_Intel1
Employee
929 Views

_DEBUG is defined if you link to the debug libraries - it is not a sufficient test for a debug configuration. You would probably want to add your own preprocessor symbol to test for configurations.

0 Kudos
Reply