0

Do Fortran kind parameter for the same precision change depending on the processor even with the same compiler? I have already read the post here.

The thing I struggle is if we are using the same compiler, say gfortran, why would there be a different set of kind parameter for the same precision? I mean, the compiler's specification is the same, so should't compiler always give us the same precision for a particular kind parameter no matter what operating system or processor I am using?

EDIT: I read some where that for integers, different CPUs support different integral data types, which means some processors might not directly support certain precision of an integer. I also read that programming language like Fortran opt for optimization so the language is implemented in a way that avoid strange precision that are not directly supported by the hardware. Does this has to do with my concern?

Community
  • 1
  • 1
Kun
  • 186
  • 2
  • 12

1 Answers1

1

You are asking "do they change". The answer is "they may".

The meaning of a certain kind value for a certain type is Fortran processor (the language concept - which is not the same thing as a a microprocessor) dependent.

The concept of a Fortran processor covers the entire system that is responsible for processing and executing Fortran source - the hardware, operating system, compiler, libraries, perhaps even the human operator - all of it. Change any part of that system, and you can have a different Fortran processor.

Consequently there is no requirement that the interpretation of a particular kind value for a particular type be the same for the same compiler given variations in compiler options or hardware in use.

If you want your code to be portable, then don't make the code depend on particular kind values.

IanH
  • 21,026
  • 2
  • 37
  • 59
  • Thank you very much for this clarification. Just a specific question about one part of your answer: you said change the hardware may change the meaning of a particular kind parameter, is it because the compiler scans the hardware and decides for this hardware let's treat this kind parameter as some particular precision, say for example double precision, or is it that the compiler is always compiling the same machine code and it is just that certain hardware interpret machine code different from others? – Kun Apr 27 '16 at 04:33
  • "Why do they change?" is not the same question as "Do they change?"!! The specific reasons for a kind value changing with a change in hardware (or whatever) will depend specifically on the circumstances around that change. If you have a specific example in mind, people can address it. – IanH Apr 27 '16 at 04:45
  • @Kun It is more likely they change with a compiler flag. NAG Fortran does that. – Vladimir F Героям слава Apr 27 '16 at 08:56