- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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):
Step 2: Compile the code.
Makefile:
Step 3: Run the excutable.
./main.exe
The differences are the output.
On Linux:
Thanks in advance!
PS: If the archives are omitted, and the program is compiled by
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.
- Balises:
- Intel® Fortran Compiler
1 Solution
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Lien copié
6 Réponses
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Thanks, Steve! However, it does NOT work at all :(
I modified both.
Now main.f is
Is it my bug or Intel's bug? :)
I modified both.
Now main.f is
[plain] PROGRAM MAINand block.f is
INTEGER I,J
EXTERNAL BLKD
COMMON /G/ I,J
WRITE(*,*) I,J
STOP
END[/plain]
[plain] BLOCK DATA BLKDAnd I compiled the code with the same Makefile. The output is still
INTEGER A,B
COMMON /G/ A,B
DATA A, B / 6, 8 /
END[/plain]
[plain] 0 0[/plain]Any other suggestions?
Is it my bug or Intel's bug? :)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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"!)
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
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.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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 :(

Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable