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

A bug of ifort for mac?

woshiwuxin
Novice
841 Visites
There is a testing program of two pieces of source code. I compiled them on Linux (Debian 5 and ifort 11.1) and Mac (10.5.8 and ifort 11.1), but the run-time results are quite different. The output on Linux is reasonable, however, the output on Mac is unexpected. Can anyone give me some suggestions?

The following are the same for both Linux and Mac.

Step 1: Write down the code.
Code 1 (block.f):
[plain]      BLOCK DATA
        INTEGER::A,B
        COMMON /G/ A,B
        DATA A, B / 6, 8 /
      END[/plain]
Code 2 (main.f):
[plain]      PROGRAM MAIN
        INTEGER::I,J
        COMMON /G/ I,J
        WRITE(*,*) I,J
        STOP
      END
[/plain]

Step 2: Compile the code.
Makefile:
[plain]all: main.f block.f
	ifort -c main.f
	ifort -c block.f
	ar rcs main.a main.o
	ar rcs block.a block.o
	ifort -o main.exe main.a block.a
[/plain]

Step 3: Run the excutable.
./main.exe

The differences are the output.
On Linux:
[plain]   6   8[/plain]
On Mac:
[plain]   0   0[/plain]
Because it works correct on Linux, is this a bug of ifort for Mac?

Thanks in advance!

PS: If the archives are omitted, and the program is compiled by
[plain]ifort -o main.exe main.o block.o[/plain]
The output on Linux and Mac is identical. However, my real project consists of many pieces of code of the BLOCKDATA constructions. I want to first archieve them and then link them with other archives.
0 Compliments
1 Solution
Kevin_D_Intel
Employé
841 Visites

This is a known issue with the version of ld in Xcode 3.1.x and earlier. Its already fixed in Xcode 3.2. You can refer to the previous threads (here) and (here).

Voir la solution dans l'envoi d'origine

0 Compliments
6 Réponses
Steven_L_Intel1
Employé
841 Visites

This is your bug, sort of. You need to make a reference to the BLOCK DATA subprogram in the main program (or something it references) so that the BLOCK DATA is pulled from the library. The Fortran language says to use the EXTERNAL statement for this.

To do this, you will have to give the BLOCK DATA subprogram a name, for example:

BLOCK DATA BLKD

and then add to the main program:

EXTERNAL BLKD
0 Compliments
woshiwuxin
Novice
841 Visites
Thanks, Steve! However, it does NOT work at all :(

I modified both.

Now main.f is
[plain]      PROGRAM MAIN
INTEGER I,J
EXTERNAL BLKD
COMMON /G/ I,J
WRITE(*,*) I,J
STOP
END[/plain]
and block.f is
[plain]      BLOCK DATA BLKD
INTEGER A,B
COMMON /G/ A,B
DATA A, B / 6, 8 /
END[/plain]
And I compiled the code with the same Makefile. The output is still
[plain]   0   0[/plain]
Any other suggestions?

Is it my bug or Intel's bug? :)
0 Compliments
Steven_L_Intel1
Employé
841 Visites

Oh, now I remember this... I thought it had been fixed on Mac a long time ago. I'll have one of our Mac experts (hint, not me!) dig deeper.

As a workaround, try adding a dummy routine to your main.f that looks like this:

subroutine dummy
call blkd
end

and see if that helps. (Note - do not add a call to "dummy"!)
0 Compliments
woshiwuxin
Novice
841 Visites
It works! Thank you, Steve!

Here, I'd like to add more info about the problem. Hopefully, this trivial, but annoying flaw could be fixed as soon as possible!

Note: It's all on a Mac with Leopard.

Without the dummy subroutine, ifort is not the only one has the unexpected output. I have tested it by using gfortran. gfortran also produces the wrong results.

Moreover, since Mac has its own tool, which is libtool, to create a static library. Besides ar, I have also tested libtool to create the archives. Unfortunately, it fails.

Therefore, without adding the dummy subroutine, all combinations, namely ifort+ar, ifort+libtool, gfortran+ar and gfortran+libtool, can not generate the right output.


0 Compliments
Kevin_D_Intel
Employé
842 Visites

This is a known issue with the version of ld in Xcode 3.1.x and earlier. Its already fixed in Xcode 3.2. You can refer to the previous threads (here) and (here).
0 Compliments
woshiwuxin
Novice
841 Visites
Thank you, Kevin! I'm glad to hear that! However, I'm disappointed to know that XCode 3.2 could only be installed on Snow Leopard and higher :(
0 Compliments
Répondre