Sunday, December 02, 2007

“Units”

The other day I had to convert the quantity 150 wavenumbers (the inverse of the wavelength of a certain frequency of light) to meV (the energy of a photon of that wavelength, in milli-electron Volts). I have a spreadsheet somewhere that does this, as it has the values of Planck's constant and the speed of light encoded. I could also have gotten the current best value of these constants and done the calculation on a calculator. However, this time I had an epiphany: I opened up a terminal window and entered:

$ units
2438 units, 71 prefixes, 32 nonlinear units

You have: 150 wavenumbers
You want: meV
        * 18.597628
        / 0.053770298

A yes, I'd finally remembered the old unix command units, available in Ubuntu with the command

$ sudo apt-get install units

It's a pretty powerful program. It has some weird roundoff errors, though. For example

$ units
2438 units, 71 prefixes, 32 nonlinear units

You have: 1 mile^2
You want: acre
        * 639.99744
        / 0.0015625063

Instead of 640 acres exactly. But you can ask the age old question of what is the speed of light in a somewhat popular unit:

$ units
2438 units, 71 prefixes, 32 nonlinear units

You have: 299792458 m/sec
You want: furlongs/fortnight
        * 1.8026175e+12
        / 5.5474886e-13

Tuesday, February 27, 2007

Hi, Rocky Mountains!

I'm off to Kansas to see the family and then to Denver for the American Physical Society March Meeting. I'll try to post something next week.

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.