1

I am actually working on a scientific project in Fortran and the set of employed functions are divided into the 64bit and 32bit version. In addition, some variables are defined with different properties for a same function in two different architectures. For example, in 32bit a variable is INTEGER*4 while in 64 bit it is INTEGER*8.

Now, I saw that in C++ it is possible to check this using #ifndef at the beginning of the file, like it was explained in this post. Is there something available in Fortran? Which possible solutions would you suggest me?

Keep in mind that the project should run on Windows and Linux, with a large variety of architecture. But still any suggestion would be appreciated!

Edit: to reply to some comments, imagine you want to employ PARDISO solver, part of the MKL libraries. There are two subroutines that we can call: pardiso and pardiso_64. Pardiso requires a variable, called PT in the manual (page 6, here), that allows pardiso to work with data. In the 32 bit version, it is a INTEGER*4, while in the 64 bit one is INTEGER*8. Basically, i do not want to allocate memory for the two and then select the right variable with a IF statement.

I immagine now that preprocessing would do the job, but has it to be a C preprocessor even if I am working in Fortran? For example, would Intel Fortran call the C preprocessor as gcc/gfortran does?

Community
  • 1
  • 1
L. B.
  • 97
  • 3
  • 10
  • Yes, you can accomplish this by using preprocessor directives. Look into your compiler's manual for source preprocessing. – milancurcic Jan 04 '13 at 16:42
  • You should use the kind notation for your integers and reals. You can change the working precision easily. – Vladimir F Героям слава Jan 04 '13 at 18:47
  • Re the previous comment: See http://stackoverflow.com/questions/3170239/fortran-integer4-vs-integer4-vs-integerkind-4. If you really want to specify variables by size in bytes, Fortran 2003 provides the ISO_FORTRAN_ENV module with standard types. – M. S. B. Jan 04 '13 at 18:49

1 Answers1

0

You can test the properties of variables with Fortran intrinsic functions, such as range. There is no need to use preprocessor directives for this. The intrinsics, as part of the language, would be standard and portable.

As already answered, most Fortran compilers do support preprocessor directives.

M. S. B.
  • 28,968
  • 2
  • 46
  • 73