LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2009, 07:21 AM   #1
Matz
Member
 
Registered: Oct 2006
Distribution: Kubuntu 9.04, Debian Etch
Posts: 178

Rep: Reputation: 31
Fortran code on 32/64bit machine


Hi all,

I'm not a Fortran coder but I need to call the sub-routine ADAPT.f from a c code.

This subroutine calculates a multiple integral of a given function.

My problem is that the c code works with no problem in a 32 bit machine but it does not in a 64 bit machine, and the problem seems to be related to adapt, which calculations gives a NA rather than the result of integration.

Since fortran is quite obscure for me, I don't know why is this happening. Maybe I should change some data type (from real to double), but I'm not sure. Does anyone have a clue?

Thanks in advance
 
Old 06-10-2009, 08:08 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Matz View Post
My problem is that the c code works with no problem in a 32 bit machine but it does not in a 64 bit machine
I assume you mean you recompiled both the C code and the fortran code for 64 bit mode to run on the 64 bit machine.

Depending on your real objective, you might have been better off keeping the 32 bit binary that worked on a 32 bit machine and using that on the 64 bit machine. You might need some extra library installed first, but in general it is easy to use 32 bit executables on a 64 bit Linux.

You could even recompile a 32 bit executable on a 64 bit Linux (again maybe needing some extra packages installed first).

But if you have good reason to want the executable to be 64 bit, that also ought to be possible.

There is an outside chance you are running into some calling convention issue, such that the passing of data between the C code and the Fortan is compiled correctly for 32 bit mode, but not for 64 bit mode. I don't think so, but I can't rule it out.

Other than that, I can only think of one theory that fits the symptoms and I can't follow the Fortran code well enough to estimate whether that theory fits:

In x86 32 bit architecture, the optimizer can use 80 bit floating point for intermediate values even when the code specifies float (32 bit floating point) or double (64 bit floating point). The code may accidentally depend on the extra precision. I can't follow the code, but it may compute some small difference that rounds to zero in 32 bit but nonzero in 80 bit, then use that as a divisor destroying the rest of the computation.

In x86-64 architecture, float or double each use exactly the nominal number of bits (32 or 64) never 80. So you don't get the extra precision that code might need.

Quote:
Maybe I should change some data type (from real to double), but I'm not sure.
The comments in that code suggest a change from real to double. It has a good chance to help. Why didn't you try before even asking? I'm not sure either.
 
Old 06-12-2009, 02:55 AM   #3
Matz
Member
 
Registered: Oct 2006
Distribution: Kubuntu 9.04, Debian Etch
Posts: 178

Original Poster
Rep: Reputation: 31
Thanks for your response. I tried your suggestions but for several reasons I failed to make it work.

Quote:
Originally Posted by johnsfine View Post
Depending on your real objective, you might have been better off keeping the 32 bit binary that worked on a 32 bit machine and using that on the 64 bit machine. You might need some extra library installed first, but in general it is easy to use 32 bit executables on a 64 bit Linux.
I tried this but I got an error message "wrong ELF class: ELFCLASS32". As far as I can see this shows that I'm pointing to a 32 bit shared object.


Quote:
Originally Posted by johnsfine View Post
In x86 32 bit architecture, the optimizer can use 80 bit floating point for intermediate values even when the code specifies float (32 bit floating point) or double (64 bit floating point). The code may accidentally depend on the extra precision. I can't follow the code, but it may compute some small difference that rounds to zero in 32 bit but nonzero in 80 bit, then use that as a divisor destroying the rest of the computation.

In x86-64 architecture, float or double each use exactly the nominal number of bits (32 or 64) never 80. So you don't get the extra precision that code might need.


The comments in that code suggest a change from real to double. It has a good chance to help. Why didn't you try before even asking? I'm not sure either.
I'm trying to change it but unfortunately the code calls other subroutines, so all the codes should be harmonized. That was an hypothesis but it could be a completely false one. I will try to work in this direction. Thanks for the help
 
Old 06-12-2009, 06:26 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Matz View Post
I tried this but I got an error message "wrong ELF class: ELFCLASS32". As far as I can see this shows that I'm pointing to a 32 bit shared object.
Was that a link time error? Building the 32 bit binaries on a 64 bit system should be possible, but not as easy as taking 32 bit binaries already built from a 32 bit system.

I hope you didn't misunderstand what I said could be mixed. You can run an entirely 32 bit task image on a 64 bit system. That means the main program is a 32 bit binary as is every .so it uses. You cannot mix 32 and 64 in one image. To use a 32 bit .so you need the main program to be 32 bit.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Fortran 95 code in C srunni Programming 2 04-15-2009 08:15 AM
How do I know which fortran complier is installed on my machine? bleed! Linux - Newbie 5 03-27-2009 11:12 PM
Using C Preprocessor on Fortran Code mkrems Programming 4 07-08-2008 10:14 PM
What on Earth is wrong with this fortran code!? Arghhhhh!!! frankie_DJ Programming 5 11-12-2007 06:46 PM
compile old fortran code in linux v2010 Linux - Software 2 12-13-2005 04:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration