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

Segmentation fault with multiple large arrays declared COMMON

catp
Beginner
873 Views

Hello,

I am getting a segmentation fault error using seven (7) large arrays declared as COMMON variables (see =CASE 1= below); No segmentation fault occurs if I comment out the COMMON declaration line in the same program (See =CASE 2= below); And even more interesting, if I change the code such that I use only one array declared as COMMON variable, even if I set the dimensions of this array so it is larger that the sum of all the seven arrays in my previous case, it does not give a segmentation fault!! (see =CASE 3= below).

I am using Intel EM64T Fortran Compiler 8.1 Build 20040922 on SuSE Linux 9.0 (x86-64) with 7433 MB RAM. I compiled with the options ifort -i_dynamic -traceback -mcmodel=large

Could anybody help me understand why this is happening? Please see below the details about the three cases:

Thanks,

Cat

=== CASE 1 ===

**********

PROGRAM MAIN

 

INTEGER MAXEL

PARAMETER (MAXEL=100000)

 

INTEGER MAXGP

PARAMETER (MAXGP=4)

 

INTEGER MAXLAY

PARAMETER (MAXLAY=21)

 

COMMON KARRAY1,KARRAY2,KARRAY3,KARRAY4,KARRAY5,KARRAY6,KARRAY7

DOUBLE PRECISION KARRAY1 (MAXEL,MAXGP,MAXLAY,9)

DOUBLE PRECISION KARRAY2 (MAXEL,MAXGP,MAXLAY,9)

DOUBLE PRECISION KARRAY3 (MAXEL,MAXGP,MAXLAY,9)

DOUBLE PRECISION KARRAY4 (MAXEL,MAXGP,MAXLAY,3)

DOUBLE PRECISION KARRAY5 (MAXEL,MAXGP,MAXLAY,3)

DOUBLE PRECISION KARRAY6 (MAXEL,MAXGP,MAXLAY,3)

DOUBLE PRECISION KARRAY7 (MAXEL,MAXGP,MAXLAY,9)

 

INTEGER I, J, LOP

LOP = 0

IF (LOP .EQ. 0) THEN

DO I = 1, 10

DO J = 1, 9

KARRAY1(I,1,1,J) = 1.0D0

KARRAY2(I,1,1,J) = 1.0D0

KARRAY3(I,1,1,J) = 1.0D0

CALL SLEEP(10)

KARRAY7(I,1,1,J) = 1.0D0

ENDDO

 

DO J = 1, 3

KARRAY4(I,1,1,J) = 1.0D0

KARRAY5(I,1,1,J) = 1.0D0

KARRAY6(I,1,1,J) = 1.0D0

ENDDO

ENDDO

END IF

CALL SLEEP(60)

END

**********

So, the 7 COMMON arrays KARRAY1- KARRAY7 should use 100000*4*21*45*8/1024 = 2953125 KB. Instead I get forrtl: severe (174): SIGSEGV, segmentation fault occurred

 

I used the SLEEP() calls above just to give me enough time to run cat /proc//status which returned the following:

**********

Name: 7C-4-2953125.out

State: S (sleeping)

Tgid: 11827

Pid: 11827

PPid: 2485

TracerPid: 0

Uid: 228 228 228 228

Gid: 101 101 101 101

FDSize: 64

Groups: 101

VmSize: 2180640 kB

VmLck: 0 kB

VmRSS: 1216 kB

VmData: 2165836 kB

VmStk: 12 kB

VmExe: 4 kB

VmLib: 4172 kB

**********

=== CASE 2 ===

On the other hand, if I comment out the COMMON declaration line, the same code runs fine without any errors. Here is the result of running it and examining the process with cat /proc/ProcID/status:

**********

Name: 7x-4-2953125.ou

State: S (sleeping)

Tgid: 13823

Pid: 13823

PPid: 2485

TracerPid: 0

Uid: 228 228 228 228

Gid: 101 101 101 101

FDSize: 64

Groups: 101

VmSize: 2968140 kB

VmLck: 0 kB

VmRSS: 1280 kB

VmData: 2953336 kB

VmStk: 12 kB

VmExe: 4 kB

VmLib: 4172 kB

**********

 

=== CASE 3 ===

**********

PROGRAM MAIN

< span>INTEGER MAXEL

PARAMETER (MAXEL=199)

 

INTEGER MAXGP

PARAMETER (MAXGP=100)

 

INTEGER MAXLAY

PARAMETER (MAXLAY=100)

 

COMMON KARRAY1

DOUBLE PRECISION KARRAY1 (MAXEL,MAXGP,MAXLAY,600)

 

INTEGER I, J, LOP

LOP = 0

IF (LOP .EQ. 0) THEN

DO I = 1, MAXEL

DO J = 1, 600

KARRAY1(I,100,1,J) = 1.0D0

ENDDO

 

ENDDO

END IF

CALL SLEEP(60)

END

**********

So this one COMMON array KARRAY1 should use 199*100*100*600*8/1024= 9328125 KB (No Segmentation errors, even if KARRAY1 is much larger than the sum of the 7 common arrays in the previous cases)

>cat /proc/12692/status:

Name: 1C-9328125.out

State: S (sleeping)

Tgid: 12692

Pid: 12692

PPid: 2485

TracerPid: 0

Uid: 228 228 228 228

Gid: 101 101 101 101

FDSize: 64

Groups: 101

VmSize: 9343140 kB

VmLck: 0 kB

VmRSS: 4580 kB

VmData: 9328336 kB

VmStk: 12 kB

VmExe: 4 kB

VmLib: 4172 kB

0 Kudos
4 Replies
joseph-krahn
New Contributor I
873 Views
Another unexpected result:
When I tried to compile your first test code, I get a segfault in the *compiler* usinf the 32-bit version 9.1. Maybe the size is too lage for 32-bit, but a compiler crash is always bad.

Compiler version and crash message:

Intel Fortran Compiler for 32-bit applications, Version 9.0 Build 20051201Z Package ID: l_fc_c_9.0.031

fortcom: Severe: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line given may not be explicit cause of this error.
---------------------------------------------------

If I reduce the size of MAXEL, it compiles and runs successfully, so it is likely a compiler bug. A reasonable fix is to upgrade, but it looks like there may be a related bug in the newer version.

Some things to try:
Have you tried an named common?
What if you put the common statement after the array declarations?
You can always declare one named common for each array.
0 Kudos
Steven_L_Intel1
Employee
873 Views
The IA-32 compiler failure I have reported to the developers.

Did you build your test case with "-mcmodel medium"? This is required to get large data address space.
0 Kudos
catp
Beginner
873 Views
Steve,
I used ifort -i_dynamic -traceback -mcmodel=large. Is "-mcmodel medium" a better option?
Thanks,
Cat
0 Kudos
Steven_L_Intel1
Employee
873 Views
For you, I would say medium is a better choice, unless your code is so large it requires more than 2GB of address space. "medium" lets you have big address space for data but not code.

If you can't solve the problem, file a report to Intel Premier Support.
0 Kudos
Reply