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

Strange behaviour of MALLOC on Pentium4

deij
Beginner
691 Views
I have come across a problem with MALLOC, which is specific to the P4. Upon MALLOC-ing larger chunks of memory (a few hundred kilobytes), the returned pointer is negative, indicating an error.
The code below reproduces this problem. It tries to MALLOC larger and larger chunks of memory in each iteration and prints the resulting pointer.

When I compile the code below on a Pentium4, it gives me negative pointers when the stacksize is too small (this is a known problem, and increasing the stacksize solves it).
However, when I compile it statically (ifort -static -o test test.f90), the problem persists, even with unlimited stack size.
This problem is not reproducible on a Pentium3 or Athlon-xp, only on P4 so far.

Code:

>cat test.f90

PROGRAM TEST
CALL TEST_SUB
END

SUBROUTINE TEST_SUB
IMPLICIT NONE
INTEGER I,J

DO WHILE (I.LE.30)
PRINT *,'=================='
PRINT *,'I = '
PRINT *,I
J = MALLOC(2**I)
PRINT *,'2**I ='
PRINT *,2**I
PRINT *,'RETURNED POINTER ='
PRINT *,J
CALL FREE(J)
PRINT *,'=================='
I=I+1
ENDDO

END
0 Kudos
2 Replies
TimP
Honored Contributor III
691 Views
You may have chosen a combination of compiler version and glibc for which -static link sets a fixed stack size. If your build uses libguide, there are KMP_ environment variables which you could set. I'm guessing you used different compile options for the various machines, but that guess could be wrong.
0 Kudos
deij
Beginner
691 Views
Ok, I had no idea a fixed stack size was implied when compiling with -static.

But still, when I take the same statically compiled binary it runs fine on a P3, but gives problems on the P4.
Can this still be an issue of different glibc/kernel versions?
0 Kudos
Reply