Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

allocate error with option -fPIC and -O

Dong_Zheng
Beginner
1,082 Views

I'm trying to update my fortran compiler to ifort 2011.5.220 (from 11.0/081). However I got a runtime error for my code. It must be a compiler error since it only happens with ifort 2011 (I tried 2011.4.191 and 2011.5.220) and with both options -fPIC and -O.

It traced down the error and have my code striped down to smaller test files (attached). Basically, when allocate is used to allocate memory for an user defined data type, allocate returns a success code. However, the next present(data) is false. When I assign value to the allocated data, I get segmentation fault. Anyone has similar problem?

Here is the code section.

!!! ===================================================================
!!!bug: the following allocate statement restart 0 (success)
allocate(current%value, stat=ist)
write(*,*) 'allocate stat', ist
!!!bug: however, the following if-statement is false,
!!!bug: if compiled with optimization
if ( associated(current) ) then
write(*,*) 'associated(current)'
if ( associated(current%value) ) then
write(*,*) 'associated(current%value)'
write(*,*) 'write value', current%value
end if
end if
current%temp = tmp
write(*,*) 'save tmp done'
write(*,*) 'write mat ', mat
!!!bug: segmentation fault from the following statement.
!!!bug: if compiled with optimization
current%value = mat
!!! ===================================================================

0 Kudos
6 Replies
Anonymous66
Valued Contributor I
1,082 Views

When I run you code, the error still occurs without the -fPIC option and at the optimization level -O1 but requires -openmp to be set. This is odd since your attached code does not use openmp directives.

I will investigate this issue further

Annalee

0 Kudos
Dong_Zheng
Beginner
1,082 Views
Thanks for your help. About the -openmp, the test code is a simplified code of my original in which the opnemp is used.

On my machine, the error happens only with -fPIC and -O (I did not test without -openmp). The output is as follow.

mattest_g
get_matholder ...
nullify(head_mat)
nullify prev ...
save at end ...
allocate stat 0
associated(current)
associated(current%value)
write value 0 0.000000000000000E+000 0.000000000000000E+000
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
save mat done
save at end done
in mattest 1 1.000000000000000E-005 2.00000000000000
mattest_O
get_matholder ...
nullify(head_mat)
nullify prev ...
save at end ...
allocate stat 0
associated(current)
associated(current%value)
write value 0 0.000000000000000E+000 0.000000000000000E+000
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
save mat done
save at end done
in mattest 1 1.000000000000000E-005 2.00000000000000
mattest_g_PIC
get_matholder ...
nullify(head_mat)
nullify prev ...
save at end ...
allocate stat 0
associated(current)
associated(current%value)
write value 0 0.000000000000000E+000 0.000000000000000E+000
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
save mat done
save at end done
in mattest 1 1.000000000000000E-005 2.00000000000000
mattest_O_PIC
get_matholder ...
nullify(head_mat)
nullify prev ...
save at end ...
allocate stat 0
associated(current)
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
mattest_O_PIC 0000000000403C21 Unknown Unknown Unknown
mattest_O_PIC 00000000004045A6 Unknown Unknown Unknown
mattest_O_PIC 00000000004032AC Unknown Unknown Unknown
libc.so.6 00002B46F1743BC6 Unknown Unknown Unknown
mattest_O_PIC 00000000004031A9 Unknown Unknown Unknown
0 Kudos
Anonymous66
Valued Contributor I
1,082 Views
That is interesting. For me it occurs the first time through the loop. Is the version of the program you are running different from the version you uploaded?

Regardless, Ihave reported this issue to the developers, the issue number is DPD200172797.

Annalee
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,082 Views
Your statement:

current => matholder%abrasion

could potentially receive uninitialized data. IOW the pointer will be non-null junk but somewhat valid virtual address. What this would cause is for current to appear associated. Just before the SIGSEGV your diagnostics displays "associated(current)" but it does NOT display "associated(current%value)". And your code fails on "current%value = mat" due to .NOT.associated(current%value), which is an assumption on your code's part that if current is (appears) associated then current%value must also be associated.

I suggest you add additional diagnostic code to write out the loc of current, current%value, and anything else. Something may show up.

Jim Dempsey

0 Kudos
Dong_Zheng
Beginner
1,082 Views
Hello Jim,

Thanks for your help. I add the write of loc(current) and loc(current%value). It seems loc(current) is fine but loc(current%value) is zero even though the return code from allocate(current%value) is successfull.

!!!===================================================================
!!!bug: the following allocate statement restart 0 (success)
write(*,*) 'loc(current)=',loc(current)
allocate(current%value, stat=ist)
write(*,*) 'allocate stat', ist
write(*,*) 'loc(current%value)=', loc(current%value)
!!!bug: however, the following if-statement is false,
!!!bug: if compiled with optimization
if ( associated(current) ) then
!!!===================================================================

I also did more tests. I changed my code to a non-functional code (remove manycode to only keep the parts used in the test). The test still failed (matdb_n1r.f90). However when I move the above code section out of a search loop, the test passed (matdb_ok1.f90). I also simplied thesubroutine getting the targat of "current", the test still failed (matdb_nr2.f90). However, if I move the same code inline instead calling the subroutine, the test passed. With thoes test, I'm convensed that this is a compiler bug. Here is outout from my new test. Source files are also attached.

mattest_nr1
get_matholder ...
nullify(head_mat)
nullify prev ...
save at end ...
loc(current)= 7249904
allocate stat 0
loc(current%value)= 0
associated(current)
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
mattest_nr1 0000000000403806 Unknown Unknown Unknown
mattest_nr1 0000000000404083 Unknown Unknown Unknown
mattest_nr1 00000000004032AC Unknown Unknown Unknown
libc.so.6 00002B276B5A9BC6 Unknown Unknown Unknown
mattest_nr1 00000000004031A9 Unknown Unknown Unknown
make: [test_all] Error 174 (ignored)
mattest_ok1
get_matholder ...
nullify(head_mat)
nullify prev ...
save at end ...
loc(current)= 7245808
allocate stat 0
loc(current%value)= 7245840
associated(current)
associated(current%value)
write value 0 0.000000000000000E+000 0.000000000000000E+000
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
save mat done
save at end done
mattest_nr2
get_matholder ...
getting new matholder 1
nullify prev ...
loc(current)= 7245808
save at end ...
loc(current)= 7245808
allocate stat 0
loc(current%value)= 0
associated(current)
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
mattest_nr2 0000000000403840 Unknown Unknown Unknown
mattest_nr2 0000000000403E53 Unknown Unknown Unknown
mattest_nr2 00000000004032AC Unknown Unknown Unknown
libc.so.6 00002B5E45644BC6 Unknown Unknown Unknown
mattest_nr2 00000000004031A9 Unknown Unknown Unknown
make: [test_all] Error 174 (ignored)
mattest_ok2
get_matholder ...
getting new matholder 1
nullify prev ...
save at end ...
loc(current)= 7245808
allocate stat 0
loc(current%value)= 7245840
associated(current)
associated(current%value)
write value 0 0.000000000000000E+000 0.000000000000000E+000
save tmp done
write mat 1 1.000000000000000E-005 2.00000000000000
save mat done
save at end done


0 Kudos
Anonymous66
Valued Contributor I
1,082 Views
This is issue has been fixed in Intel® Fortran Composer XE for Linux* 2013 which is now available at the Intel® Registration Center. Regards, Annalee Intel Developer Support * Other names and brands may be claimed as the property of others.
0 Kudos
Reply