Re: problematic array assignment in double precision (ifort, windows)
- From: Rich Townsend <rhdt@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 30 Aug 2006 14:26:56 -0400
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.
.
- Follow-Ups:
- References:
- Prev by Date: problematic array assignment in double precision (ifort, windows)
- Next by Date: Re: problematic array assignment in double precision (ifort, windows)
- Previous by thread: problematic array assignment in double precision (ifort, windows)
- Next by thread: Re: problematic array assignment in double precision (ifort, windows)
- Index(es):
Relevant Pages
|