Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

rand() function behaviour

V_Koch1
Beginner
1,196 Views

Dear developers,

the input

$cat test_rand.f

program test_rand
implicit none
real rand
write (*,*) rand()
end

compiles and executes fine with

$ ifort -O0 -xP test_rand.f
$ ./a.out

2.2477936E-05

but better optimization breaks it for me.

$ ifort -O1 -xP test_rand.f
$ ./a.out

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 08049F3C Unknown Unknown Unknown
a.out 08049E31 Unknown Unknown Unknown
libc.so.6 F7E275F5 Unknown Unknown Unknown
a.out 08049D61 Unknown Unknown Unknown

This happens with the 32bit version of ifort 10.1.018 under 64bit SUSE Linux 11.0, and also with the 32bit version of ifort 10.1.013 under 32bit SUSE Linux 10.1

Is this a misunderstanding of rand() (i.e. bad fortran code) or a compiler bug?

Regards,

Volker Koch

0 Kudos
3 Replies
Kevin_D_Intel
Employee
1,196 Views
The segmentation fault relates to preparation of arguments on the call stack ahead of calling rand_. It requires a bit more investigation, but the -O0 case appears to unintentionally avoid the fault related to an additional popping of the stack ahead of calling rand_.

The documented usage of RAND and RANDOM requires accessing these portability routines with USE IFPORT. The program runs successfully if you modify the program as shown below.

[cpp]program test_rand
USE IFPORT
implicit none
write (*,*) rand()
end[/cpp]

0 Kudos
TimP
Honored Contributor III
1,196 Views
Quoting - V.Koch

Dear developers,

the input

$cat test_rand.f

program test_rand
implicit none
real rand
write (*,*) rand()
end

compiles and executes fine with

$ ifort -O0 -xP test_rand.f
$ ./a.out

2.2477936E-05

but better optimization breaks it for me.

$ ifort -O1 -xP test_rand.f
$ ./a.out

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 08049F3C Unknown Unknown Unknown
a.out 08049E31 Unknown Unknown Unknown
libc.so.6 F7E275F5 Unknown Unknown Unknown
a.out 08049D61 Unknown Unknown Unknown

This happens with the 32bit version of ifort 10.1.018 under 64bit SUSE Linux 11.0, and also with the 32bit version of ifort 10.1.013 under 32bit SUSE Linux 10.1

Is this a misunderstanding of rand() (i.e. bad fortran code) or a compiler bug?

Regards,

Volker Koch

0 Kudos
TimP
Honored Contributor III
1,196 Views

USE IFPORT is required, to supply an interface block to enable a call with no argument. Debug mode is more tolerant of caller/callee stack mis-match. This one has been discussed before, probably on the Windows side.

0 Kudos
Reply