From: mecej4 on
rth wrote:

> Hello,
>
> I have following configuration in my Makefile:
>
> FC = gfortran
> FCFLAGS = -Wall -O3 -m32 -march=pentium-m -ffast-math -funroll-loops -
> ftree-loop-linear -ftree-vectorize -fdefault-real-8 -fexternal-blas
> FCFLAGS += -I/usr/include
> LDFLAGS = -llapack -L/usr/lib/blas/atlas/ -latlas
>

What happens if you leave out -fdefault-real-8?

> it works fine without the -fexternal-blas flag. However when I add it,
> I get a zero matrix every time a matmul() is done. I guess there is
> something wrong in linking with blas. I tried first to use standard
> Gentoo library with LDFLAGS = -llapack -lblas, had the same results
> as with blas-atlas.
> After installing blas-atlas I selected it with the eselect tool, so
> guess -lblas should now also be linked to atlas.

I don't know what 'eselect' does. The problem with behind-the-scenes
configurations is that one does not know which options are in play and may
have contributed to the problem.

>
> gfortran version: 4.3.4.
>
> I rather new to fortran, have I done something wrong in my
> Makefile ?
>
> Thank you in advance,
> --
> Roman.

-- mecej4
From: rth on
On Jun 6, 1:32 pm, mecej4 <mecej4.nyets...(a)operamail.com> wrote:

> What happens if you leave out -fdefault-real-8?

Well, then it works. Thank you, haven't taught about it...
However there is another problem then. If I leave out -fdefault-
real-8,
even thought I declare all my variables as real (kind=8), I still get
a single
precision. For instance for pi defined as:
real (kind=8), parameter :: pi = 3.141592653589793238462643383279
cos(pi/2) gives me 4e-8 instead of 1e-16, as before...


Thank you for your help,
--
Roman.


From: rth on
On Jun 6, 1:32 pm, mecej4 <mecej4.nyets...(a)operamail.com> wrote:

> What happens if you leave out -fdefault-real-8?

Well, then it works. Thank you, haven't taught about it...
However there is another problem then. If I leave out -fdefault-
real-8,
even thought I declare all my variables as real (kind=8), I still get
a single
precision. For instance for pi defined as:
real (kind=8), parameter :: pi = 3.141592653589793238462643383279
cos(pi/2) gives me 4e-8 instead of 1e-16, as before...


Thank you for your help,
--
Roman.


From: steve on
On Jun 6, 1:09 pm, rth <rth.yurc...(a)gmail.com> wrote:
> On Jun 6, 1:32 pm, mecej4 <mecej4.nyets...(a)operamail.com> wrote:
>
> > What happens if you leave out -fdefault-real-8?
>
> Well, then it works. Thank you, haven't taught about it...
> However there is another problem then. If I leave out  -fdefault-
> real-8,
> even thought I declare all my variables as real (kind=8), I still get
> a single
> precision.  For instance for pi defined as:
> real (kind=8), parameter ::  pi = 3.141592653589793238462643383279
> cos(pi/2) gives me 4e-8 instead of 1e-16, as before...

Well, that long string of numbers is a single precision literal
constant. If you want double precision add d0 to the end or
_8 (yes, -8 is gfortran's processor dependent kind parameter for
double precision).

PS: you don't want to use -fdefault-real-8 unless you absolutely
know what it does.

PPS: Yes, I know what I talking about as I'm one of the people
responsible for the writing the -fdefault-real-8 code.

--
steve
From: Richard Maine on
rth <rth.yurchak(a)gmail.com> wrote:

> On Jun 6, 1:32 pm, mecej4 <mecej4.nyets...(a)operamail.com> wrote:
>
> > What happens if you leave out -fdefault-real-8?
>
> Well, then it works.

Makes sense. You probably had argument disagreements when compiling with
that.

> If I leave out -fdefault- real-8,
> even thought I declare all my variables as real (kind=8), I still get
> a single
> precision. For instance for pi defined as:
> real (kind=8), parameter :: pi = 3.141592653589793238462643383279
> cos(pi/2) gives me 4e-8 instead of 1e-16, as before...

That is a very common and basic problem. It is important to understand
what is going on or you will forgever encounter lots of problems.

A fundamental concept of Fortran is that you do not have to look at the
context when evaluating an expression. That is so even for trivial
expressions such as your 3.141592653589793238462643383279. That
expression is a single precision real. Don't go trying to explain that
pi is declared as kind=8. That would be context, which you don't look at
(yet). The literal constant all by itself is a single precision real
regardless of what context you are using it in.

In this case, that means most of those digits are irrelevant. The
constant has only whatever precision single precision real has (normally
about 7 decimal digits). *AFTER* the expression is evaluated as a single
precision real, we look at the context and see that the result is
assigned to the parameter pi. Pi has kind=8, so the value is converted
to that kind. But that conversion is *AFTER* the single precision result
was evaluated. The precision that was lost in that earlier step does not
magically reappear. Precision, like virginity, does not return once
lost.

You need to make the literal constant have kind 8, which you could do by
writing it as 3.141592653589793238462643383279_8. Note the _8 on the
end.

Better yet would be to use a named parameter for the kind value instead
of the literal value 8. The standard does not guarantee that a real of
kind=8 even exists. With some compilers, for example, the real kinds are
1, 2, and 3 (for the 3 kinds single, double, and quad). You can use the
selected_real_kind intrinsic to find the right kind value for the
precision you need. For example, in one of my modules that I use
everywhere I have

!-- Kinds for specified real precisions.
integer, parameter :: r4_kind = selected_real_kind(6,30) !-- 6
digits
integer, parameter :: r8_kind = selected_real_kind(12,30) !-- 12
digits
....
!-- Kind for working real precision.
integer, parameter :: r_kind = r8_kind

Then I would write your literal constant as
3.141592653589793238462643383279_r8_kind

That has the advantage of working on all compilers. Even if you don't
want to fuss with selected_real_kind, I recommend at least using a
parameter for the kind value anyway. If you define, for example

integer, parameter :: r8 = 8

and use the r8 parameter throughout, then you would have to change only
that one line to move your program to a compiler that used, for example,
a kind value of 2 for that precision. For that matter, it would also
make it easier of you ever needed to change your code to quad precision.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain