Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Conditional Compile 32bit vs 64bit

fbalderasintel
1,780 Views

Is there a way to Conditionally compile some Fortran code in 32 bit while the rest of the code compiles
as 64 bit ?

0 Kudos
1 Solution
John4
Valued Contributor I
1,780 Views
intkind and floatkind should be parameters, e.g.:

[fortran]#ifdef Dx64mode

integer, parameter :: intkind = selected_int_kind(12)

integer, parameter :: floatkind = selected_real_kind(12)

#else

integer, parameter :: intkind = selected_int_kind(6)

integer, parameter :: floatkind = selected_real_kind(6)

#endif
[/fortran]

Also, keep in mind that with you must enable cpp-like preprocessing. Alternatively, you could use compiler directives:

[fortran]!DEC$IF DEFINED(Dx64mode)

integer, parameter :: intkind = selected_int_kind(12)

integer, parameter :: floatkind = selected_real_kind(12)

!DEC$ELSE

integer, parameter :: intkind = selected_int_kind(6)

integer, parameter :: floatkind = selected_real_kind(6)

!DEC$ENDIF[/fortran]

In any case, the compiler defines certain variables by default (e.g.,_WIN64, _M_X64, etc.). Check "Building Applications>Preprocessing" in the documentation for further details.

View solution in original post

0 Kudos
5 Replies
TimP
Honored Contributor III
1,780 Views
You've posed a confusing question.
If you mean use of 32- and 64-bit mode in different parts of the same project, it would require a change of compilers, which certainly could be done in a Makefile, but is not commonly useful.
If you mean changing data declarations between 32- and 64-bit data types, several ways are in routine use, such as
using -fpp -D64mode


#ifdef 64mode
integer,parameter :: intkind=selected_int_kind(12)
integer,parameter :: floatkind=selected_real_kind(12)
#else
integer,parameter :: intkind=selected_int_kind(6)
integer,parameter :: floatkind=selected_real_kind(6)
#endif

real(floatkind) yourfloatvars
integer(intkind) yourintvars
...

or set up a Makefile to invoke your compiler's options to promote default kinds to 64 bits.

Incorporating correction kindly pointed out in subsequent response
0 Kudos
fbalderasintel
1,780 Views
Sorry for the confusion, actually my first draft was so lengthy, that I thought it would be too confusing
so I went for the simple question approach, which I see was equally confusing. However you did cut through the haze and I appreciate that.

Actually, your second option is the one we've been looking for. Yes changing
data declarations. Thats what we need. Will try this...
Thanks.
0 Kudos
Les_Neilson
Valued Contributor II
1,780 Views
Actually, your second option is the one we've been looking for. Yes changing
data declarations. Thats what we need. Will try this...
Thanks.

To state the obvious : You willneed to be careful to check if any variables are passed as arguments to a subroutine compiled with a different size. Otherwise you will get stack corruption.

Les
0 Kudos
fbalderasintel
1,780 Views

Thanks for the heads up on that one. Sometimes we focus on the problem at hand and get broadsided
by another.



The code snippet posted earlier gives me a compiler error on the last two lines.
But I don't think I should move those two lines inside the ifdef as that would
defeat the purspose. I'm now not sure if the snippet was just "conceptual" or
should actually compile.

error #6236: A specification statement cannot appear in the executable section.
error #6236: A specification statement cannot appear in the executable section.

This is the test console program "Hello World".
! I set up -fpp and x64Mode in the preprocessor property page
! For preprocessor I had to begin with non integer so used x64mode

program MixedBitMode

implicit none

! Variables

integer intkind,floatkind

#ifdef Dx64mode

intkind=selected_int_kind(12)

floatkind=selected_real_kind(12)

#else

intkind=selected_int_kind(6)

floatkind=selected_real_kind(6)

#endif

real(floatkind) yourfloatvars

integer(intkind) yourintvars

! Body of MixedBitMode

print *, 'Hello World'

end program MixedBitMode

0 Kudos
John4
Valued Contributor I
1,781 Views
intkind and floatkind should be parameters, e.g.:

[fortran]#ifdef Dx64mode

integer, parameter :: intkind = selected_int_kind(12)

integer, parameter :: floatkind = selected_real_kind(12)

#else

integer, parameter :: intkind = selected_int_kind(6)

integer, parameter :: floatkind = selected_real_kind(6)

#endif
[/fortran]

Also, keep in mind that with you must enable cpp-like preprocessing. Alternatively, you could use compiler directives:

[fortran]!DEC$IF DEFINED(Dx64mode)

integer, parameter :: intkind = selected_int_kind(12)

integer, parameter :: floatkind = selected_real_kind(12)

!DEC$ELSE

integer, parameter :: intkind = selected_int_kind(6)

integer, parameter :: floatkind = selected_real_kind(6)

!DEC$ENDIF[/fortran]

In any case, the compiler defines certain variables by default (e.g.,_WIN64, _M_X64, etc.). Check "Building Applications>Preprocessing" in the documentation for further details.

0 Kudos
Reply