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

segmentation fault with PACK function

Jianming_Y_
Beginner
589 Views

$ cat test_pack.f90
program test

  implicit none
 
  integer, parameter :: m = 1050000
  integer, allocatable :: a(:),b(:),c(:),d(:)

  integer :: i

  allocate(a(0:m),b(0:m),c(0:m),d(0:m))

  do i=0,m
    a(i) = i
    b(i) = 0
  end do

  d = pack(a,b == 1,c)

  deallocate(a,b,c,d)
 
end program test
$ ifort -V test_pack.f90
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.1.132 Build 20161005
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 Intel(R) Fortran 17.0-1632
GNU ld version 2.25.1-22.base.el7
$ ./a.out
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              00000000004744F1  Unknown               Unknown  Unknown
a.out              000000000047262B  Unknown               Unknown  Unknown
a.out              000000000043D3D4  Unknown               Unknown  Unknown
a.out              000000000043D1E6  Unknown               Unknown  Unknown
a.out              000000000041E1F9  Unknown               Unknown  Unknown
a.out              00000000004031C6  Unknown               Unknown  Unknown
libpthread-2.17.s  00007F416A398370  Unknown               Unknown  Unknown
a.out              0000000000402CFE  Unknown               Unknown  Unknown
a.out              000000000040295E  Unknown               Unknown  Unknown
libc-2.17.so       00007F4169FE9B35  __libc_start_main     Unknown  Unknown
a.out              0000000000402869  Unknown               Unknown  Unknown

It works with m = 1040000. the presence of the vector (c in pack(a,b == 1,c)) also has an effect on how large m can be without giving the problem.

 

0 Kudos
2 Replies
Kevin_D_Intel
Employee
589 Views

The segmentation fault is the result of exhausting available shell stack space building the mask array. You could avoid it using the compiler option, -heap-arrays 0 , or increasing the shell’s stack limit (e.g. for bourne shell using:  ulimit –s unlimited).

0 Kudos
Jianming_Y_
Beginner
589 Views

Thanks for the quick reply, Kevin.

0 Kudos
Reply