Re: problematic array assignment in double precision (ifort, windows)



mvukovic@xxxxxxxxxxxx wrote:
The following function returns a 3-element vector of cooridnates on a
unit sphere. I use it to generate randomely distributed points on a
sphere.

It works fine when I compile it with a switch /real-size:32. However,
when I use /real-size:64, the vector gets loaded with garbage. I also
tried /align with /real-size:64, but no difference.

This routine lies in a module, but the module header does not contain
any other declarations.

The print statements show the calculation to proceed correctly, until
the last step, when I am loading the vector with the values contained
in cos1,cos2,cos3.

function rn_point_on_sphere()

You should have an 'implicit none' here, to pick up any variable-name typos in
your code.

real,dimension(3)::rn_point_on_sphere
real :: rn_angles(2),x1,x2,cos1,cos2,cos3
real :: one=1. ,two=2.,half=0.5

A suggestion: you might want to add the PARAMETER attribute to your definitions
of one, two and half. This is good defensive programming practice -- if you
inadvertently try to overwrite them elsewhere, the compiler will yell.

!! For uniformly distributed points on a sphere, I picked a method
from:
!! Eric W. Weisstein. "Sphere Point Picking." From MathWorld--A
Wolfram Web Resource.
http://mathworld.wolfram.com/SpherePointPicking.html
DO
call random_number( rn_angles )

How is random_number defined? Does it return 32- or 64-bit reals? If the former,
then when you run with /real-size:64, you will be trying to return two 32-bit
reals into two 64-bit reals. This will cause problems.

print *,'RNs:',rn_angles
x1=two*(rn_angles(1)-half)
x2=two*(rn_angles(2)-half)
! print *,x1,x2,(x1**2+x2**2)
if ((x1**2+x2**2).le. 1) exit
END DO
print *,'X1,2:',x1,x2
cos1=two*x1*sqrt(one-x1**2-x2**2)
cos2=two*x2*sqrt(one-x1**2-x2**2)

Are you sure that the arguments to the sqrt() function are non-negative?

cos3=one-two*(x1**2+x2**2)
rn_point_on_sphere=(/cos1,cos2,cos3/)
print *,cos1,cos2,cos3
print *,'rn:',rn_point_on_sphere
end function rn_point_on_sphere

What am I missing? Many thanks,

Mirko


P.S. Other than using double precision, I am equally bad at inventing
passwords for the intel support web site. After five failures and
multiple reading of the instructions, I had to email their support to
send me samples of acceptable passwords. That is why I am posting this
here and not on their support site.


Try !324fgef:3. That's what I use.
.



Relevant Pages

  • Re: problematic array assignment in double precision (ifort, windows)
    ... unit sphere. ... It works fine when I compile it with a switch /real-size:32. ... Does it return 32- or 64-bit reals? ...
    (comp.lang.fortran)
  • Re: Curious "bug" in F77
    ... forms compile and run. ... I placed a pause after the statement that came BEFORE ... just re-writing that one line as two lines, a calculation of REALS, ... Good pointer to corrupted data - very possible. ...
    (comp.lang.fortran)
  • Re: Skolems Paradox and why is math the way it is?
    ... I think I support your ... pretend a list of all the reals exist, ... I don't have enough money to print my thesis and fly ... a bunch of professors over to ask questions while I defend my thesis, ...
    (sci.math)
  • Re: Integer Coersion
    ... Your compiler supports SIZEOF as do several others including my ... to be other than 8bits when cheap memory came on the scene and BURIED ... models that didnt support it.. ... as the de-facto standard for reals also ...
    (comp.lang.fortran)
  • Re: building slatec with g95
    ... If you built library with g95, compile the caller with g95 also. ... The machine constants are wrong. ... constants are a union of integers and reals. ...
    (comp.lang.fortran)