Fortran programs on Linux* are susceptible to suffering a run-time segmentation fault when using the RAND or RANDOM portability functions.
While not required, the recommend usage of the Intel Fortran portability library functions is to access these either by inserting a USE IFPORT in the calling program, or by including iflport.f90 from the INCLUDE directory of your compiler distribution as part of your program.
Following this recommended usage can help avoid confusing and hard-to-debug errors when using the RAND or RANDOM portability functions on Linux* where their use *without* the USE IFPORT (or iflport.f90) in conjunction with high-level optimizations may cause programs to suffer a run-time segmentation fault associated with calling the portability function. This is not a compiler defect.
The following sample program compiles and runs successfully using the Intel Fortran compiler for Linux*:
write (*,*) rand()
Simply removing the USE IFPORT from the sample program above and compiling with high-level optimizations like –xP causes the program to suffer a run-time segmentation fault as demonstrated below. Using RAN (or RANDOM) in the sample without accessing the function via the IFPORT module affects preparation of the call stack with the appropriate arguments, which leads to a segmentation fault when calling the RAN (or RANDOM) function.
$ ifort -V -xP sample.f90
Intel® Fortran Compiler for applications running on IA-32, Version 10.1 Build 20080801 Package ID: l_fc_p_10.1.018
Copyright (C) 1985-2008 Intel Corporation. All rights reserved.
Intel Fortran 10.1-2051
GNU ld version 18.104.22.168.4 20030523
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 08049DC8 Unknown Unknown Unknown
a.out 08049CB9 Unknown Unknown Unknown
libc.so.6 006EB79A Unknown Unknown Unknown
a.out 08049BF1 Unknown Unknown Unknown
Please refer to the Intel Fortran compiler User Guide or this Knowledge Base article for a complete discussion on using the RAND, RANDOM and other Intel Fortran compiler portability library functions.