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.

QSORT Segmentation Fault

chauvjo
Novice
777 Views

The following code is generating a segmentation fault during the call to QSORT.  It appears QSORT is calling the routine COMPARE without assigning a value to arg1. I tried adding USE IFPORT to the main routine but this did not solve the problem.  This identical code worked without errors on another UNIX system.  I have compiled the code using Intel Compiler Version 2013 SP1 Update 4 and Intel Compiler Version 2015 Update 1 without success. I am running on RHEL 6.6.  Any ideas?   Thanks...

      SUBROUTINE BuildArray(array_values,number_values,min_value,max_value,delta_value,special_array,n_special_array)

      IMPLICIT NONE
C     ..
C     .. Scalar Arguments ..
      DOUBLE PRECISION min_value,max_value,delta_value
      INTEGER number_values,n_special_array
C     ..
C     .. Array Arguments ..
      DOUBLE PRECISION array_values(2000),special_array(10)
C     ..
C     .. Local Scalars ..
      INTEGER J,K
C     ..
C     .. External Functions ..
      EXTERNAL QSORT,Compare
      INTEGER*2 Compare
C     ..
C     .. Executable Statements ..

      number_values = (INT((max_value - min_value) / delta_value) + 1) 

      DO J=1,number_values
          array_values(J) = min_value + DBLE(J-1) * delta_value
      END DO

      DO J=1,n_special_array
         K = number_values + J
         array_values(K) = special_array(J) 
      END DO

      number_values = number_values + n_special_array

      CALL QSORT(array_values,number_values,8,Compare)

      RETURN
      END
      INTEGER*2 FUNCTION Compare(arg1,arg2)

      IMPLICIT NONE
C     ..
C     .. Scalar Arguments ..
      DOUBLE PRECISION arg1,arg2
C     ..
C     .. Executable Statements ..
C
      IF(arg1.LT.arg2) THEN
          Compare = -1
      ELSE IF(arg1.EQ.arg2) THEN
          Compare = 0
      ELSE IF(arg1.GT.arg2) THEN
          Compare = 1
      ENDIF

      RETURN
      END

 

0 Kudos
3 Replies
chauvjo
Novice
777 Views

I forgot to add the compiler options:

-O0 -fpe0 -extend_source 132 -g -check bounds -u -traceback

Thanks....

0 Kudos
mecej4
Honored Contributor III
777 Views

If you are targeting x64 rather than IA32, you need to declare the integer arguments to QSORT as integer(8), or use a compiler option to select as default 8-byte integers. Failing to do so is probably the cause of the failure that you noted. Perhaps, the "another Unix system" is a 32-bit installation?

0 Kudos
jimdempseyatthecove
Honored Contributor III
777 Views

mecej4 is likely correct.

You should have (make one if you do not) a module defining the interface to QSORT. Had you USEed this, it would have told you of the incorrect types.

Avoid using EXTERNAL if at all possible.

Jim Dempsey

0 Kudos
Reply