Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > weird g77 and g...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 18 Topic 8211 of 8551
Post > Topic >>

weird g77 and gfortran

by K-9 <rick.peng.du@[EMAIL PROTECTED] > May 5, 2008 at 07:55 PM

Hi guys....I've spent the whole night trying to figure out about this
question. Please help me if you have any clue. Thanks a lot.

The code is very easy. I'm trying to call a fortran function from C.

The code is as follow:

=========C code=========
#include "stdio.h"

extern float r_ (int * d, float *b);

main ()
{
     float a = 1.5, b = 1.05, c = 1;
     int d = 2;
     c = r_ (&d, &b);
     printf ("%f\n", c);
}

==========Fortran Code===========
      real function r(m,t)
      integer m
      real t

      print *, m, t
      r = 0.1*t+46
      print *, r

      return
      end
================================

It doesn't matter what the fortran code does...but when I compile it
with g77, the result can't be passed back to the C code, but with
gfortran, it can. Here are the outputs:

***fortran code compiled by gfortran****
[du@[EMAIL PROTECTED]
 qr]$ gfortran -funroll-all-loops -O3 -c ceiling.f -o
ceiling.o;gcc -funroll-all-loops -O3 -c testint.c -o testint.o;g77 -o
testint.x testint.o ceiling.o -L/pkgs/intel/mkl/9.0/lib/em64t -L/home/
du/lib/hpl/lib/LINUX_XEON_QUAD -L/usr/lib/gcc/x86_64-redhat-linux/
3.4.6/ -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1 -L. -lgfortran

[du@[EMAIL PROTECTED]
 qr]$ ./testint.x
           2   1.050000
   46.10500   <----------- result in Fortran function
46.105000  <--------- result received by C code

***fortran code compiled by g77****
[du@[EMAIL PROTECTED]
 qr]$ g77 -funroll-all-loops -O3 -c ceiling.f -o
ceiling.o;gcc -funroll-all-loops -O3 -c testint.c -o testint.o;g77 -o
testint.x testint.o ceiling.o -L/pkgs/intel/mkl/9.0/lib/em64t -L/home/
du/lib/hpl/lib/LINUX_XEON_QUAD -L/usr/lib/gcc/x86_64-redhat-linux/
3.4.6/ -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1 -L. -lgfortran
[du@[EMAIL PROTECTED]
 qr]$ ./testint.x
 2  1.04999995
  46.1049995
-0.000000 <----------- but here I get 0, with the only difference in
the way the fortran code is compiled.

Here are the versions:
[du@[EMAIL PROTECTED]
 qr]$ g77 -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
disable-checking --with-system-zlib --enable-__cxa_atexit --disable-
libunwind-exceptions --enable-languages=c,c++,f77 --disable-libgcj --
host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-4)

[du@[EMAIL PROTECTED]
 qr]$ gfortran -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
enable-checking=release --with-system-zlib --enable-__cxa_atexit --
disable-libunwind-exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --
disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-
gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)


[du@[EMAIL PROTECTED]
 qr]$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --
enable-checking=release --with-system-zlib --enable-__cxa_atexit --
disable-libunwind-exceptions --enable-libgcj-multifile --enable-
languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --
disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-
gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)


THANKS AGAIN FOR THE HELP!
 




 18 Posts in Topic:
weird g77 and gfortran
K-9 <rick.peng.du@[EMA  2008-05-05 19:55:53 
Re: weird g77 and gfortran
e p chandler <epc8@[EM  2008-05-05 20:26:33 
Re: weird g77 and gfortran
Craig Powers <enigma@[  2008-05-06 13:34:32 
Re: weird g77 and gfortran
Ingo Thies <ingo.thies  2008-05-13 14:09:52 
Re: weird g77 and gfortran
K-9 <rick.peng.du@[EMA  2008-05-05 20:35:13 
Re: weird g77 and gfortran
lindahl@[EMAIL PROTECTED]  2008-05-05 21:22:41 
Re: weird g77 and gfortran
Charles Coldwell <cold  2008-05-07 03:10:21 
Re: weird g77 and gfortran
Catherine Rees Lay <ca  2008-05-07 09:47:42 
Re: weird g77 and gfortran
kargl@[EMAIL PROTECTED]   2008-05-06 17:38:15 
Re: weird g77 and gfortran
stevenb.gcc@[EMAIL PROTEC  2008-05-13 05:50:59 
Re: weird g77 and gfortran
Ingo Thies <ingo.thies  2008-05-13 16:16:31 
Re: weird g77 and gfortran
lindahl@[EMAIL PROTECTED]  2008-05-13 11:55:07 
Re: weird g77 and gfortran
kargl@[EMAIL PROTECTED]   2008-05-13 14:36:29 
Re: weird g77 and gfortran
Thomas Koenig <tkoenig  2008-05-13 18:24:21 
Re: weird g77 and gfortran
Ingo Thies <ingo.thies  2008-05-14 14:37:54 
Re: weird g77 and gfortran
Thomas Koenig <tkoenig  2008-05-15 16:48:20 
Re: weird g77 and gfortran
Ingo Thies <ingo.thies  2008-05-16 10:20:17 
Re: weird g77 and gfortran
stevenb.gcc@[EMAIL PROTEC  2008-05-16 15:57:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 17:04:57 CDT 2008.