For Programmers: Free Programming Magazines  


Home > Archive > Fortran > February 2005 > [Intel compiler][Linux] Nan problem









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 [Intel compiler][Linux] Nan problem
Apprenti Debutant

2005-02-04, 3:59 pm

Hello,

First I would like to apologize for my poor english. I have to face to
a problem that I would like to solve.

Let be a program that has been written few years ago in fortran 90. I
have partially rewritten the code and know I tried to compare the
results given by the old one and the new one. In that code a hankel
transform is computed via a fast hankel transform (Algorithm 588 from
ACM).

Both codes have been compiled using the Intel Fortran compiler for
32-bit applications version 8.1 Build 20041019Z Package ID:
l_fc_pu_8.1.021. One (the old one) is going through the hankel
transform without any problem but the new one crash.

After some hours I think that I have found where the problem is but I
do not know how to solve it. At the end of the message the output the
code juste before the crash. The first column is the integration
variable k and the second column is a part f(k) (exponentialy
decreasing with respect to the integration variable) of the function
to be integrated. As you can see in the old code when k increase f(k)
goes to zero (which is normal) but in the new code instead of stopping
at (0.,0) I got a NaN. I thought that a NaN appears when you try to
divide A/B with A=0 and B=0 but in my case f(k) is the substraction of
two exponentialy decreasing functions.

Do You have any idea to overcome this problem ?

Thank you in advance for your help and have a nice WE,


L'appenti débutant



Output of the old code
2210.786 (524.5057,95.05350)
2700.260 (403.2547,65.37638)
3298.105 (279.6035,39.52051)
4028.315 (170.7313,20.66542)
4920.195 (89.26336,9.138274)
6009.539 (38.62191,3.315619)
7340.068 (13.26630,0.9494179)
8965.179 (3.438428,0.2042981)
10950.09 (0.6319523,3.1082707E-02)
13374.48 (7.6338604E-02,3.1014946E-03)
16335.62 (5.5237589E-03,1.8506707E-04)
19952.37 (2.1375317E-04,5.8978976E-06)
24369.88 (3.8514104E-06,8.7423409E-08)
29765.44 (2.7281786E-08,5.0900689E-10)
36355.59 (6.1789796E-11,9.4689198E-13)
44404.82 (3.4762557E-14,4.3729529E-16)
54236.17 (3.5690664E-18,3.6837493E-20)
66244.21 (4.5885915E-23,3.8843472E-25)
80910.86 (4.6635557E-29,3.2368349E-31)
98824.75 (0.0000000E+00,0.0000000E+00)

Output of the new code
k 2210.786 (524.5057,95.05348)
k 2700.260 (403.2547,65.37637)
k 3298.105 (279.6035,39.52050)
k 4028.315 (170.7313,20.66542)
k 4920.195 (89.26336,9.138273)
k 6009.539 (38.62191,3.315619)
k 7340.068 (13.26630,0.9494178)
k 8965.179 (3.438428,0.2042980)
k 10950.09 (0.6319523,3.1082703E-02)
k 13374.48 (7.6338612E-02,3.1014944E-03)
k 16335.62 (5.5237589E-03,1.8506705E-04)
k 19952.37 (2.1375317E-04,5.8978981E-06)
k 24369.88 (3.8514104E-06,8.7423395E-08)
k 29765.44 (2.7281786E-08,5.0900689E-10)
k 36355.59 (6.1789802E-11,9.4689187E-13)
k 44404.82 (3.4762557E-14,4.3729524E-16)
k 54236.17 (3.5690664E-18,3.6837490E-20)
k 66244.21 (4.5885915E-23,3.8843467E-25)
k 80910.86 (4.6635557E-29,3.2368347E-31)
k 98824.75 (NaN,NaN)
FX

2005-02-05, 8:58 am

> Do You have any idea to overcome this problem ?

What compiler options did you compile the new code with? Did you try
without optimization? And, the most important thing is, you should
compile and run your code with floating point exceptions trapping
("-fpe <n>", if I recall correctly, for a value of <n> I don't remember
(see the doc)). This should tell you where the first NaN appears in the
calculation.

--
FX
Apprenti Debutant

2005-02-08, 3:59 am

"FX" <coudert@alussinan.org> wrote in message news:<cu24fv$9jt$1@nef.ens.fr>...
>
> What compiler options did you compile the new code with? Did you try
> without optimization? And, the most important thing is, you should
> compile and run your code with floating point exceptions trapping
> ("-fpe <n>", if I recall correctly, for a value of <n> I don't remember
> (see the doc)). This should tell you where the first NaN appears in the
> calculation.


Thank you for you answer,

First note that both codes have been compiled with the same compiler
(Intel Fortran compiler for 32-bit applications version 8.1 Build
20041019Z Package ID: l_fc_pu_8.1.021) with the same options (I have
added your suggested option) on the same computer. The old one go
through without any problem whereas the new one stop.

With your suggestion (-fpe0) I have found that the new code stopped
earlier (k = 36355.59) than found before but I still don't understand
why.

The old one juste put the value f(k) to zero (as expected) for k >
36355.59 wheras the new one begin to do the same and but replace with
(NaN,NaN). The two output are presented below as illustration.

How to avoid such problem and why the two codes which are very closed
the one to the other did not get the same results ?


Thank you again for any help,

Have nice day,

Sincerely yours,


L'apprenti Débutant

Old one
2210.786 (3.2302620E-12,9.9564627E-13)
2700.260 (7.9488136E-13,1.9578196E-13)
3298.105 (1.7445123E-14,3.4405269E-15)
4028.315 (-4.7626457E-14,-7.5348392E-15)
4920.195 (-7.9747839E-15,-1.0139685E-15)
6009.539 (2.1380882E-16,2.1891264E-17)
7340.068 (-4.2868304E-17,-3.5418526E-18)
8965.179 (-2.1561164E-18,-1.4405623E-19)
10950.09 (1.6266407E-19,8.8061438E-21)
13374.48 (1.4674607E-21,6.4486874E-23)
16335.62 (-3.4913797E-23,-1.2473157E-24)
19952.37 (-5.7227545E-26,-1.6642225E-27)
24369.88 (-4.9766201E-29,-1.1792949E-30)
29765.44 (1.4311022E-32,2.7657497E-34)
36355.59 (-7.0684746E-37,0.0000000E+00)
44404.82 (0.0000000E+00,0.0000000E+00)
54236.17 (0.0000000E+00,0.0000000E+00)
66244.21 (0.0000000E+00,0.0000000E+00)
80910.86 (0.0000000E+00,0.0000000E+00)
98824.75 (0.0000000E+00,0.0000000E+00)


With the new one
k 2210.786 (3.2302618E-12,9.9564606E-13)
k 2700.260 (7.9488163E-13,1.9578202E-13)
k 3298.105 (1.7445120E-14,3.4405250E-15)
k 4028.315 (-4.7626457E-14,-7.5348383E-15)
k 4920.195 (-7.9747881E-15,-1.0139688E-15)
k 6009.539 (2.1380841E-16,2.1891219E-17)
k 7340.068 (-4.2868235E-17,-3.5418463E-18)
k 8965.179 (-2.1561205E-18,-1.4405650E-19)
k 10950.09 (1.6266441E-19,8.8061616E-21)
k 13374.48 (1.4674563E-21,6.4486665E-23)
k 16335.62 (-3.4913845E-23,-1.2473172E-24)
k 19952.37 (-5.7227508E-26,-1.6642213E-27)
k 24369.88 (-4.9766382E-29,-1.1792990E-30)
k 29765.44 (1.4311021E-32,2.7657493E-34)
k 36355.59 (-7.0684943E-37,-1.1148813E-38)
k 44404.82 (1.5694543E-43,1.4012985E-45)
k 54236.17 (0.0000000E+00,0.0000000E+00)
k 66244.21 (0.0000000E+00,0.0000000E+00)
k 80910.86 (0.0000000E+00,0.0000000E+00)
k 98824.75 (NaN,NaN)
Joost

2005-02-08, 9:01 am


> k 80910.86 (0.0000000E+00,0.0000000E+00)
> k 98824.75 (NaN,NaN)


Just one question, are these indeed complex numbers of small magnitude
? Some compilers have a problem doing division with small complex
numbers (i.e. use a fast algorithm that causes Inf/NaN) for these.

Joost

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com