Fortran Program Porting Issues

Japanese version is here.



Prerequisites

Of course, you have to set up some FORTRAN compiler on your MkLinux box before you can start porting fortran programs. In the following, I am going to use "g77", the GNU version of f77. The version of g77 that is compatible with the "gcc" coming with MkLinux DR2.1update4(+shared library support) is g77-0.5.19.

  1. Shared Library Setup
  2. I have built a set of RPM packages (gcc Suite for C, C++, Objective C, and FORTRAN), which require the shared library support provided by DR2.1update4(+shared library support). You have to thus set up shared library environment before you can go further.
    You can find here how I installed the DR2.1update4+shared library support.

  3. Compiler Setup
  4. Once the DR2.1update4+shared library support is installed, the rest is easy. Get the following RPMs to <somewhere> on your local disk:

    $ cd <somewhere>
    $ ls
    gcc-2.7.2.fu.1-1C.ppc.rpm
    gcc-c++-2.7.2.fu.1-1C.ppc.rpm
    gcc-g77-2.7.2.fu.1-1C.ppc.rpm
    gcc-objc-2.7.2.fu.1-1C.ppc.rpm

    If you are interested in how I built the RPMs, take a look at this.

    To install them do the following:

    $ su
    # rpm -i --force <somewhre>/gcc*-2.7.2.fu.1-1C.ppc.rpm

    Caution: This overwrites your existing gcc triplet (C, C++, and Objective C) and might destroy your compiling environment. As always install them at your own risk. You had better read this before installation.

Getting Started with G77

  1. Simple Test
  2. Congratulation! Now you are ready to try "g77" to compile your fortran programs. You had better start with something rather simple to test if "g77" works at all.

    $ cat simple.f
    	  real*4  a, b, c
    	  a = 1.
    	  b = 2.
    	  c = a + b
    	  print *, ' a, b, c = ', a, b, c
    	  end
    	
    $ g77 simple.f -o simpletest
    $ simpletest

  3. In Case of Trouble
  4. If it doesn't, you are in trouble. If what you got is something like:

    simpletest: error in loading shared libraries
    libf2c.so: cannot open shared object file: No such file or directory

    It should be relatively easy to fix as follows.
    First check if you have /etc/ld.so.conf. If you do, you will get:

    $ cat /etc/ld.so.conf
    /lib
    /usr/lib
    /usr/X11/lib
    /usr/local/lib

    I suspect you don't. You have to create one for example by

    $ su
    # cat > /etc/ld.so.conf
    /lib
    /usr/lib
    /usr/X11/lib
    /usr/local/lib
    /usr/lib/gcc-lib/powerpc-unknown-linux/2.7.2.1-ppclinux
    ^D

    where "^D" is CTRL+d. Once you have created /etc/ld.so.conf, you should be able to register your libf2c.so to /etc/ld.so.cache.

    # /sbin/ldconfig -v
    ......
    libf2c.so => libf2c.so
    ......

    I should have included in the RPM package a symbolic link to /usr/lib/libf2c.so (I supposed I did, but didn't as pointed out by Matsumura at Osaka University), so that libf2c.so would have been automatically registered in the rpm installation. I'm sorry for inconvenience. I promise the next version will include this symboic link. Meanwhile you have to do the above and try simpletest again (97/12/07: 2.7.2.fu.1-1C now includes the symbolic link and you do not have to do the above, I hope).

    If it failed again or if what you got was something different, you are in a real trouble.
    I'm sorry but in this case you have to restore your old "gcc" triplet (gcc-2.7.2.1-2J.ppc.rpm, gcc-c++-2.7.2.1-2J.ppc.rpm, gcc-objc-2.7.2.1-2J.ppc.rpm) from the RPMS/ppc directory of DR2.1update4. Then you may want to try compiling "g77" from its SRPM.

    $ su
    # rpm --rebuild gcc-2.7.2.fu.1-1C.src.rpm

    I hope you don't have to do this.

    Passing this simple test, you can now proceed to more complicated programs. Then you may encounter various problems like I did.

Experience with G77 on MkLinux

I was brave enough to jump directly to a really huge program package called CERNLIB. This, of course, caused a lot of problems that I suffered from.

  1. If Linux Source Is Available
  2. If somebody already ported your favorite fortran program to a Linux box, your are lucky, since the source code is very likely to be g77-compilable. If you have to deal with bits, bytes, or integer*2s embedded in an I*4, however, you need to be careful. Intel chips and PPC chips have different byte orders. The software package I mentioned above (CERNLIB) falls into this category. Although the source codes are g77-compilable except for some trivial problems inherent in porting any package to a MkLinux box, the porting was a pains-taking process, because of the byte order difference. This only requires patience and carefulness not to miss any place of swapping bytes or equivalencing I*4 with I*2s.

  3. Otherwise
  4. You are on your own. Porting issues then include

G77 Performance

I don't have enough time to carry out any systematic performance check of my MkLinux box (PowerMac 8115/110: ppc601). Instead, I have just compared the computing time for a few physics programs that run both on the MkLinux box and a HP workstation (C100: pa7200 + HP-UX10.10 + HP Fortran).

  1. Description of Sample Programs
  2. Results
  3. Maybe you are just interested in this table:

    C100 (HP-UX) 8115/100 (MkLinux)
    TTH_GEN:BASES 140.73 sec
    (2.94834 +/- 0.00927 fb)
    850.05 sec
    (2.94811 +/- 0.00927 fb)
    TTH_GEN:SPRING 402.19 sec
    (output data: 35MB)
    813.35 sec
    (output data: 35MB)
    TTH_ANL: 8J 218.53 sec 435.08 sec
    TTH_ANL: L+6J 166.2 sec 306.2 sec
    TT_GEN:BASES 410.27 sec
    (0.40153 +/- 0.00061 fb)
    2485.85 sec
    (0.40153 +/- 0.00061 fb)
    TT_GEN:SPRING 103.62 sec
    (output data: 5.6MB)
    244.45 sec
    (output data: 5.6MB)

    where the center of mass energy has been set at 700(340) GeV for TTH (TT) and the top mass is chosen to be 170 GeV. In the SPRING stage, 1000(200) events were generated for TTH (TT). Notice that TT_GEN takes into account the threshold enhancement thus has a finite cross section even at the production threshold.

    Comments

    Except for the BASES step, the difference is about a factor of two, which is probably consistent with the CPU speed difference (I'm not sure though). In the BASES step, the factor becomes about six instead. The performance of the MkLinux box is significantly worse than the other cases. This is probably due to the BASES's randomly accessing a huge array that exceeds a tiny cache. I am going to test this, if time allows.

Back to Keisuke Fujii's MkLinux Page
fujiik@jlcuxf.kek.jp July 29, 1997