Subject: Gaussian 94 on Linux

From: Jussi Eloranta <[email-masked]>
Date: Sun, 27 Aug 1995 14:17:30 +0300 (EET DST)

Hi,

There was some discussion of g94 for Linux recently. I thougth to
share some hacks I made last night to get the thing started.

If you find errors or problems let me know.

Regards,

Jussi Eloranta

ps. ... I will not be responsible if these patches destroy your computer
or cause any other damage... -jme

----- LINUX.INSTALL ------

g94 installation instructions for Linux 1.{2,3}.x with gcc 2.6.3 and
g77 0.5.15.

--------

Required software

The gcc 2.6.3 and g77 0.5.15 binaries are available from
ftp.chem.jyu.fi:/pub/linux/gcc-2.6.3+g77-0.5.15.tar.gz .
Unpack this under /usr directory. NOTE: If you have gcc already
installed then you may wish to backups of it first because this
will overwrite it. And also this is not in ELF format!

The Linux (Slackware) is available via anonymous ftp from ftp.funet.fi or 
sunsite.unc.edu. There are also number of CDROM distributions available
(the prices are around $20 depending how many CDs there are). The latest
slackware release contains g77 0.5.14 which may work as well but this
has not been tested yet! The g77 binary will probably be updated soon.
For those who are not familiar with Linux: Linux is a free U*IX clone
which runs on ibm pc compatibles (386, 486, 586). It will also run 
on digital ALPHA machines. Linux is created by Linus Torvalds & many
other unix hackers.

g94 (Gaussian 94) is copyright by Gaussian, Inc. The g94 license and the
source code must be obtained from Gaussian, Inc. There is a note in
the license agreenment (1.) : ".... designed for use on all supported
Unix Workstation computer systems." Of course, this Linux version is
not among the supported ones so I'm not really sure if one allowed to
run this code...? Anyone from Gaussian, Inc. care to comment on this?

IMPORTANT: I haven't done any testing yet. The code will compile without
errors and, well, yes I did actually run it for couple of times to make
sure it doesn't core dump ;-) I haven't check if the modifications I've
made can cause errorneous behavior of the g94! So this is *very* preliminary
work! I thougth to release it to get the Linux version going ;-) Read the
comments I've written to see where there are problems.

-----------

Compiling g94 on Linux

0) Be sure you are not editing the *only* copy of the source you have...
   Then cd to the directory where your gaussian 94 source is.

1) First we must remove all integer*2 types. The g77 0.5.15 does not support
   this data type yet. I really haven't checked if this causes any serious
   problems but I haven't run into any yet. To see which files contain
   this data type, do:
           % fgrep -l -i 'integer*2' *.F bsd/*.F
           <a list of file names should appear>
           <in these files change: integer*2 -> integer>
           
   and just in case you could do:
           % fgrep -l -i 'integer *2' *.F bsd/*.F
           <if any file is reported then do the same thing as above>
   When g77 develops (in 0.6?) this restriction will go away.

2) Create g94 makefile for Linux. Enter bsd directory and copy the sun.make
   to linux.make (ie. cp sun.make linux.make). Then edit the following
   definitions:

   a) Remove the -D_SUN_ -DGAUSS_PAR from the PP_FLAGS and the line below
      that which adds definitions to PP_FLAGS from gau-machine program.
   b) Change RUNF77 from f77 to g77. Remove the line which says SUN_FLAGS = ...
      and the O1_OPT definition. Set FFLAGS = -O.
   c) Set RUNCPP = gau-cpp -D__linux__ -D__LINUX__ -DEXTRACT_INT -DLITTLE_END
   d) Change RUNCC from cc to gcc. Remove ACC definition. Add -O to CFLAGS.
   e) Change RUNLD from f77 to g77 and remove -fast.
   
3) Modifications to mdutil.c:
   a) Right after #define FALSE 0 and #define TRUE 1 add:
      #ifdef __linux__
      #define NONBSD
      #define NEED_FDATE
      #define NEED_LOC
      #define NEED_GSR48
      #define DO_GETCWD
      #include <sys/times.h>
      #include <unistd.h>
      #include <sys/fcntl.h>
      #include <time.h>
      #endif
   b) Add after #ifdef sgi and #endif pari (around line 400 or so):
      #ifdef __linux__
      #define NAMES_DONE
      #define BLKSIZE statbuf.st_blksize
      #define NEED_AND
      #define NEED_ETIME
      #endif
   c) After #ifdef SVR4 and #endif pari (around line 810) add:
      #ifdef __linux__
      #define SV_SETV
      #endif
   d) Add before #ifdef __hppa (around line 2430):
      #ifdef __linux__
      /* TODO: f77 datatypes are not correct... here is one example where
       * we get a floating exception when we use f77_int instead of float
       * (which is the data type for g77 fortran integer).
       */
      float time_() { return ((float) time ((time_t *) 0)); }
      void exit_() { exit(0); }
      void gauabt__() { gauabt_ (&f77i_0); }
      f77_int getpid_() { return getpid();}
      f77_int stat_(path) char *path; {struct stat buff; return stat(path,&buff);}
      f77_int unlink_(path) char *path; {return (unlink(path));}
      #endif
   e) In function galloc_() add before "if(*wordsize != sizeof(f77_wp)...":
      #ifdef __linux__
      char *fish;
      #endif
      and add nbytes by 8 before calling malloc (right after nbytes = ....):
      #ifdef __linux__
      nbytes += 8; /* alignement hack - see below */
      #endif
      and to the end of the function:
      #ifdef __linux__
      /* hack attack: the g77 does not align the f77_wp type on 8 byte boundaries 
       * and therefore we have to adjust gauspace accordingly */
      fish = (char *) gauspace;
      fish = (char *) (((unsigned int) fish) + (((unsigned int) refarray) % sizeof(f77_wp)));
      gauspace = (f77_wp *) fish;
      #else
      n = ...
      if (n != 0) ...
      #endif

      NOTE: The lines "n = ..." and "if (n!=0)..." are the already in the
      g94 code. I just don't want to publish copyrighted code here...

4) Modifications to mdutil.F:

    a) IOInit should not be called. Add:
       #ifndef __LINUX__
       ...
       #endif
       around call IOInit(...)  (near line 2560).

    b) Add:
       #ifdef __LINUX__
       #define USE_DRAND48
       #endif
       before the same def for IBM_RS6K near the line 2630.

    c) Add:
       #ifdef __LINUX__
       #define NO_ERRNO
       #endif
       before the same def form IBM_RS6K near the line 10550.

5) Modifications to the bldg94 script:

   a) Add:
      @ linux = 0
      after @ hi_osf = 0   near the line 100

   b) Add:
      else if ($x == "linux") then
      @ linux = 1
      (cd bsd; ln -s linux.make g94.make)
      else ....
      before the same kind of if for sun_solaris2 around line 107.

    c) Add:
       if ( $generic || $sun || ... || $linux) then
                                    ^^^^^^^^^
       to the if statement near line 202.

6) Get ready for compilation:
   setenv g94root <the dir where g94 subdirectory is>
   cd $g94root/g94
   bsd/bldg94 >& compile.log &
   <wait until compilation finished & check compile.log for errors>

   NOTE: The compilation will bomb on newzmat. Only the g94 and lXXX.exe
   files will compile right now.

Also I run test000.com to see that it got the same results as the
one run on ibm rs6k. The rs6k took about 4.1 CPU seconds to run and
on 586/100MHz about 10.4 CPU seconds. If you have 16 mb or so memory
then it may be a very good idea to limit the amount of memory g94
uses. Otherwise the system will swap heavily.

Jussi Eloranta, Dept. of Chemistry, University of Jyvaskyla, Finland.

[email-masked]