Saturday, May 22, 2010

Ubuntu 10.04: Installing the 64-bit Intel Fortran Compiler

OK, let's get take care of this right up front: Warning: This page discusses the installation of free-as-in-beer, but not free-as-in-speech, software. If you want to keep such software off your system, then don't install this compiler. Also note that the license is pretty restrictive, i.e. Non-commercial means you are not getting compensated in any form for the products and services you develop using these Intel® Software Development Products. However, the installation process should work for the commercial version of this compiler.

I first learned to program in Fortran. I still have my original WATFOR/WATFIV textbook, though I later graduated to Fortran 77 and occasionally write some Fortran 90. I still do a lot of things in Fortran 77, just because I'm comfortable writing code starting in column 7.

Now there is an open-source Fortran 77/90/95 compiler, gfortran. It's reasonably fast, portable, nice — did I mention free? But it has a few quirks. For example, one of my old codes has a subroutine second which measures elapsed time. gfortran assumes that I'm calling the intrinsic function second, and bombs the compile because I don't have a proper calling statement. So I have to go in and declare

      external second

in every subroutine that calls my second.

But Intel makes its Linux Fortran compiler free-as-in-beer for non-commercial development. And the 64-bit version of the code includes Intel's optimized Math Kernel Library (MKL). It's a fairly simple registration, and you don't sign over much of your soul. However, in Ubuntu it's a fairly difficult installation. What's more, it changes every time you install a new version of the compiler.

The installation steps for the current compiler and Ubuntu are straightforward, but there's a lot of fine print, and the 64 bit version has a couple of quirks in the install. So let's go over it step by step. Note that I'm only referring to the 64-bit install in all of this. If you're running in 32-bit mode, your mileage will vary.

  1. Register. It's easy. You'll get a link to the download page an a serial number. Save the email, you'll need it.
  2. Download the appropriate tar file. I used the Genuine Intel® 64 bit version. There's another one called IA64, but I didn't try that.
  3. Now set up your machine to compile code. Run:
    sudo apt-get install build-essential gcc g++ rpm ia32-libs
    and either
    sudo apt-get install sun-java6-jre
    which requires you to accept Sun's Java license, or
    sudo apt-get install openjdk-6-jre-headless.
  4. Now you need a package called libstdc++5 which isn't included in Ubuntu. Worse, if you're on a 64 bit machine, you need to install the 32-bit version as well. So click on these
    the 64-bit code, libstdc++5_3.3.6-18_amd64.deb
    and
    the 32-bit code, libstdc++5_3.3.6-18_i386.deb
    
  5. Install the 64-bit version:
    $ sudo dpkg -i libstdc++5_3.3.6-18_amd64.deb
  6. DO NOT INSTALL THE 32-BIT VERSION. Instead:
    $ dpkg --extract libstdc++5_3.3.6-18_i386.deb ./
    $ cd usr/lib
    $ sudo -i
    # cp libstdc++.so.5.0.7 /usr/lib32
    # cd /usr/lib32
    # ln -s libstdc++.so.5.0.7 libstdc++.so.5
    # exit
    
  7. Now we can do the install. Go back and find your Fortran tarball
    $ tar xvzf l_cprof_p_11.1.072_intel64.tgz
    $ cd l_cprof_p_11.1.072_intel64
    $ sudo -i
    # ./install.sh
    
  8. Take all the defaults, and enter your registration number when asked. Note that you'll get some error statements to the effect that you're running this on an unsupported system (Ubuntu) and the option
    1. Skip missing optional pre-requisites [default]
    take that.
  9. Your compiler is now installed in /opt/intel/Compiler/11.1/072/ (the last number will vary), but you're not quite finished.
  10. If you use the bash shell, add the line
    source /opt/intel/Compiler/11.1/072/bin/ifortvars.sh intel64
    to your ~/.bashrc file.
  11. If you use the tcsh shell, add the line
    source /opt/intel/Compiler/11.1/072/bin/ifortvars.csh intel64 to your ~/.cshrc file.
  12. Now you're done. Look at man ifort to see how to use the thing.

My preliminary test indicates that the Intel compiler is about 10% faster than gfortran for a fairly CPU intensive calculation, without the MKL. Not all that much faster, really. If you're not doing a lot of serious computations, installing the Intel compiler might not be worth the trouble.

Thursday, December 14, 2006

Installing the Intel MKL

Last week I was helping to sort abstracts for the 2007 March Meeting. It's a more or less a tradition, meaning that I can't get out of it until I convince someone else to take over. While I was there, I got into a conversation about electronic structure codes. These are computer programs which more or less accurately solve the Schrödinger equation for the electrons moving in atoms, molecules, and solids. This allows physicists to determine atomic configurations in molecules and solids and to calculate how they would react to external forces. I've used variety of programs in my time, mostly based on the Linearized Augmented Plane Wave (LAPW) method. However, there is another method quite popular with physicists because it is usually faster, but somewhat less accurate, than LAPW, the pseudopotential method. Pseudopotentials are sort of fake atoms, with their shapes fixed up to speed computations.

Some of my colleagues were touting a package of pseudopotential codes called Quantum Espresso (QE). It's released under the GPL, which means you can run it at work, at home, in the car, in the air, etc., without worrying about licensing.

I downloaded the QE code to good old Hal, here. It compiles nicely using version 9.1 of the Intel Fortran compiler for Linux, which is free for non-commercial use. I've discussed how to install the compiler on Ubuntu before. The QE code compiles beautifully and runs quite well.

But it can run faster. Many of the mathematical operations done by QE run more quickly if the code is optimized for the CPU. For Intel chips, this can be done by installing the Intel Math Kernel Library (MKL), which is also free for non-commercial use. But the installation script for MKL/Linux creates and installs an RPM package. You can install RPMs on a Debian system such as Ubuntu, but it's not recommended, since you can't keep it in sync with the Debian package database.

So how to install it? This has bothered others as well. Putting together notes from this forum I was able to figure out the procedure. Now I did this last night and I might have forgotten a step or to, so if I leave something out please correct me:

  1. Download the package from the Intel site and register to get a key.
  2. Uncompress the package:
    tar xvf l_mkl_p_8.1.014.tgz
  3. In the subdirectories thus created, find the install script. Change to that directory and run
    sudo ./install.sh
  4. This will eventually fail, but in the directory /tmp/mkl you'll find a file named intel-mkl-8.1p-14.i386.rpm. If you had a RedHat based distribution it would be installed, but we need to convert it to a Debian package using alien:
    sudo alien --to-deb --scripts intel-mkl-8.1p-14.i386.rpm
  5. This creates a Debian package named intel-mkl_8.1p-15_all.deb that we can install in the standard way:
    dpkg -i intel-mkl_8.1p-15_all.deb
  6. Quantum Espresso automatically finds the package and uses the libraries. For other Fortran programs, say to compile a file named progname.f, you need to do something such as
    ifort -o progname progname.f -L/opt/intel/mkl/8.1/lib/32 -lmkl_lapack -lmkl_ia32 -lguide -lpthread
    Programs written in "C" will link in a similar fashion.

I haven't done timings on the difference between QE and QE+MKL, but it seems significantly faster. Now I just have to figure out how to use the code in the way I want to use it.

Saturday, April 08, 2006

Ubuntu: Installing Intel Fortran

As noted previously, I need a good Fortran compiler for this computer, and the best free (as in beer) compiler is the one from Intel. The problem is that Intel delivers its compiler in a set of (Oh, the Horror!) RPMs. So we need to do a bit of a conversion process.

There are basically two options:

  1. Set up your system to install RPMs (installing the alien package does this anyway), and install away. This isn't a particularly nice way of doing things, but it probably works.
  2. Convert the RPM to DEB format, and install that way. This lets you tweak the system a little bit.

I went the second way. The method is explained here, but it's based on a Debian installation guide, and I'll summarize it here.

We assume that you're going to install the 9.0 version of the compiler.

  1. Register with Intel if you haven't already. You'll get a file in email, called noncommercial_for_l#GarbageString#.lic. Save it someplace. Save the email as well, because it also contains your license number if you need a backup.
  2. Download the package. This also includes a debugger and versions of the compiler and debugger for 64 bit machines. We'll leave these installs as an exercise for the reader.
  3. Download the make_deb_9 script, and save in the same directory as your Fortran RPM.
  4. Open a terminal window, cd to the directory with your RPM and make_deb_9 file, and run the following, entering your password where required:
    $ sudo alien -k intel-ifort9-9.0-031_i386.rpm
    $ sudo ./make_deb_9 intel-ifort9_9.0-031_i386.deb
    $ sudo dpkg -i intel-ifort9_9.0-031_i386.deb
    
  5. Change to the directory where you saved your Intel License file and run
    $ sudo cp noncommercial_for*.lic /opt/intel/fc/9.0/licenses
  6. Add the contents of /opt/intel/fc/9.0/bin/ifortvars.csh to your file ~/.chsrc, if you use csh or tcsh shells. If you run bash, (or sh, which is aliased to bash), add /opt/intel/fc/9.0/bin/ifortvars.sh to your ~/.bashrc file. If you're comfortable doing it, you can edit the contents of these files to fit in better with your system.
  7. Open a new terminal window (this makes sure that all of the statements in the ifortvars script get started properly). cd to a directory with a Fortran program. Picking exactly which options you use to compile is something of an art form, but I find that this works:
    $ ifort -O3 -axN -ip -WB -Vaxlib program.f -o program
    
    creating an executable called program from program.f

And so far it all works. Hope it works for you, too.

Note added 8 Dec 2006: You need the alien step above, which I forgot to include. Note that Intel is now up to the 9.1 compiler. This requires a bit of editing of the make_deb_9 file to make the directory structure right. In the current version I have to change all references of 9.0 to 9.1.036, but that obviously depends on the build you download.

Sunday, November 28, 2004

Intel Fortran Compiler (8.1)

The current version of Intel's Fortran Compiler for Linux is 8.1, up from 8.0 when we installed it in FC1. Let's try again:

  1. Go to the compiler ad page.
  2. Click on Free Non-Commercial Download.
  3. Click on Download Intel® Fortran Compiler for Linux. Answer the survey questions.
  4. Click the "register" button and fill out the form. Use an email address which works.
  5. They remembered I have an active registration, but will send me the information I need to download again. They sent me the same license file again.
  6. Download the software (82.2 MB).
  7. Untar the file and visit directory
    $ tar xvzf l_fc_p_8.1.018.tar.gz
    $ cd l_fc_p_8.1.018
  8. su to root, run the install script, answer the questions. Install Fortran Compiler. Accept license agreement, default placement, RPM flags.
  9. Install debugger.
  10. Exit installation program. Put /opt/intel_fc_80/bin in $path. Compile test program:
    $ cat hello.f 
          program hello
          write(*,*) 'hello world'
          end
    $ ifort  -ccdefault list -tpp7 -W0 hello.f -o hello
    /opt/intel_fc_80/lib/for_main.o(.text+0x1c): In function `main':
    : undefined reference to `MAIN__'
    
  11. .

Hmm. The requirements for this version include the use of the gcc 2.3.2 or below, and we're running 3.4.2. I'll have to look into this.

Saturday, January 03, 2004

Intel Fortran Options

This seems to be a better option string for the Intel Fortran compiler mentioned previously:

ifort -ccdefault list -tpp7 -W0

where -ccdefault list means ignore old-fashioned Fortran carriage controls in column 1 -tpp7 means optimize for Pentium IV, which seems to include the Celeron (-tpp6 for Pentium III). According to man ifort, -tpp7 is the default. -W0 means ignore warning messages, which tend to be noting that certain features of F77 have been depreciated in F90 and F95.

Changes added in proof: I decided that the Celeron is a P-IV class machine, so I changed the processor optimization flag.

Thursday, January 01, 2004

Fortran Compiler

Every computer needs a good Fortran compiler (YMMV). Fedora comes with the g77 compiler as part of the gcc package, but it doesn't produce very efficient code, though it is useful for checking proper Fortran 77 syntax.

Fortunately there is the Intel Fortran Compiler (and debugger) for Linux. When you go to the site, it looks like you have to pay for the compiler, except for a short-lived demo version. However, if you click on the link that says "Free evaluation download" and scroll down to the middle of that page, you'll see a link that says "non-commercial unsupported version". (There is a similarly-licensed c++ compiler, as well.) You'll see that the compiler is free in that "the non-commercial license means the compiler cannot be used to produce products for resale or commercial use."

Go down to the bottom of the page, take the survey, read the license agreement, and register. Eventually you'll get an email from Intel which has your license code, and will tell you where to download the source.

Installation isn't to hard. The code comes in a tar file with a set of RPMs and installation scripts. Run the installation script as root. It will ask you where your license is. It will also ask for any flags you want to pass to the rpm program to install the RPM files. Give in the flag --nodeps, otherwise you won't get a clean install.

After the installation is finished, take the contents of /opt/intel_fc_80/bin/ifortvars.csh into your ~/.cshrc file, if you are using the tcsh or csh shell, or put /opt/intel_fc_80/bin/ifortvars.sh into your ~/.bashrc or ~/.kshrc file if you are using the bash or ksh shell, respectively. This will set up the environmental variables to find the Fortran libraries.

Finally, you can compile your code. I use the following flags to compile the standard "hello world" program: $ ifort -vms -tpp6 -WB hello.f -o hello to compile the executable hello from the source code hello.f. Note that ifort defaults to optimized code, so you don't need the -O flag. To turn optimization off, use -O0. The other flags are what I used for the 7.0 version of the compiler, they work in 8.0 but I don't know if they are necessary. I do know that 8.0 is not as fussy about extensions to the Fortran standards as 7.0 was. 7.0 would flag everything, 8.0 flags nothing, at least with these options.

I'll put up timing information when I get things properly set up.