- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a way to Conditionally compile some Fortran code in 32 bit while the rest of the code compiles
as 64 bit ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
data declarations. Thats what we need. Will try this...
Thanks.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page