Home > Archive > Fortran > August 2007 > Can gfortran has the function of define the precision of whole program?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can gfortran has the function of define the precision of whole program?
|
|
| li.simula@gmail.com 2007-08-21, 4:33 am |
| In IVF compiler "!DEC$ REAL:8" can define all real value having
attribute of real(8). SO, you have not to wirte (8) very time in the
following.
Can gfortran has the same function(to change default kind by one
command) and how can I do it?
| |
| Arjen Markus 2007-08-21, 4:33 am |
| On 21 aug, 09:56, li.sim...@gmail.com wrote:
> In IVF compiler "!DEC$ REAL:8" can define all real value having
> attribute of real(8). SO, you have not to wirte (8) very time in the
> following.
>
> Can gfortran has the same function(to change default kind by one
> command) and how can I do it?
It has that option: -fdefault-real-8
But why would you want to do that? It makes your program rely on
parameters outside the source code. While that is almost
inevitable, it seems to me very bad style not to be able
to see from the source code whether single or double precision
is to be used.
What if you encounter a compiler that has no such option?
I would recommend using a construction like:
use precision
....
real(wp) :: x
....
where the module precision defines the working precision "wp"
like:
integer, parameter :: wp = kind(1.0d0)
or something like that.
It then is a matter of redefining wp to switch to another
precision.
Regards,
Arjen
| |
| li.simula@gmail.com 2007-08-21, 8:06 am |
| > But why would you want to do that? It makes your program rely on
> parameters outside the source code. While that is almost
> inevitable, it seems to me very bad style not to be able
> to see from the source code whether single or double precision
> is to be used.
Thanks! Your method is a good choice. However, you must write a
additional "wp" with every real, such as 100.0_wp,25.0wp.....it's a
little inconvenient. If you use "!DEC$ REAL:8" or "-fdefault-
real-8",you can directly write 100.,25. So, very good! And if you want
use real(4),just define it at where you want(it overwrite the "!DEC$
REAL:8)
So, I think it is easy of the method which I mentiond (the only
problem is perhaps it is not easy for compatible with diffrent
operating system. So I ask...).
| |
| Arjen Markus 2007-08-21, 8:06 am |
| On 21 aug, 12:11, li.sim...@gmail.com wrote:
>
> Thanks! Your method is a good choice. However, you must write a
> additional "wp" with every real, such as 100.0_wp,25.0wp.....it's a
> little inconvenient. If you use "!DEC$ REAL:8" or "-fdefault-
> real-8",you can directly write 100.,25. So, very good! And if you want
> use real(4),just define it at where you want(it overwrite the "!DEC$
> REAL:8)
>
> So, I think it is easy of the method which I mentiond (the only
> problem is perhaps it is not easy for compatible with diffrent
> operating system. So I ask...).
Well, real(4) is compiler-dependent too. Not all compilers will
use the kind number 4 to indicate ordinary single-precision
reals. Which is why it is unwise to rely on this notation.
And, yes, it is true that any literal number must be decorated
then with _wp.
Hm, you _could_ combine Glen's solution and mine:
implicit real(wp) a-h,o-z
and leave out declarations that would be covered by the
above statement.
Regards,
Arjen
|
|
|
|
|