Compiling LAMMPS (3Apr13, But Likely Others) In Ubuntu 10.04 Part 1. Using MPICH2 And FFTW2 (And Ubuntu Notes On Installing Intel Fortran And C++ Composers XE for Linux)

I'll qualify this post by saying that (1) I have given up on Ubuntu 11.x and 12.x because they are consistently unstable on my hardware (so, if you have issues running this installation on those versions, I may not be of much help (although I suspect things should work)), (2) I am starting this install from a fresh 32-bit Desktop Ubuntu 10.04 install (so do not know if there are any issues with other software one might have installed on a Linux box if a problem comes up), and (3) the procedure comes out of the current lack of an Ubuntu binary currently listed as available (as of 6 April 2013) from the LAMMPS website (lammps.sandia.gov/download.html#ubuntu). If (3) changes and is available in an MPI form, what's below will hopefully be unnecessary.

Building Trouble And Solutions

My initial "just unzip, untar, and make linux" attempt on a fresh 10.04 install produced the following error (which I'm reproducing in the expectation that you found this page by typing one of the errors below into a search engine, so you'll find the error and the solutions). NOTE: I build all my programs in /opt for organizational purposes (so replace accordingly):

user@machine:/opt/lammps-3Apr13/src$ sudo make linux

make[1]: Entering directory `/opt/lammps-3Apr13/src/Obj_linux'
icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../write_restart.cpp > write_restart.d
/bin/sh: icc: not found
icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../write_data.cpp > write_data.d
/bin/sh: icc: not found
icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../verlet.cpp > verlet.d
/bin/sh: icc: not found
icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../velocity.cpp > velocity.d
/bin/sh: icc: not found
...
icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../angle_charmm.cpp > angle_charmm.d
/bin/sh: icc: not found
icc -O  -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -c ../angle_charmm.cpp
make[1]: icc: Command not found
make[1]: *** [angle_charmm.o] Error 127
make[1]: Leaving directory `/opt/lammps-3Apr13/src/Obj_linux'
make: *** [linux] Error 2

Obviously, problem Number 1 is the lack of the Intel C Compiler (icc). My solution to this was to download the non-commercial version of the Intel C++ Composer XE for Linux (then I grabbed the Intel Fortran Composer XE for Linux because, well, why not?) currently available from software.intel.com/en-us/non-commercial-software-development (which means this link may be subject to change, so search for "intel c++ noncommercial" in the event).

Unzipping, untaring, and running ./install.sh will, on a fresh Ubuntu install, give you errors that g++ and a proper Java runtime environment are not available on the computer (as part of the pre-requisite search). This is easily solved before the Intel installs by the following (one of which is needed for LAMMPS anyway). I specifically chose the openJDK, but Java 6 or 7 should also do.

sudo apt-get install build-essential openjdk-6-*

After these installs, both Intel Composers should install just fine. If you're installing LAMMPS into a directory that you, the user, has access to, then adding /opt/intel/bin to your PATH will provide you no compiler errors (related to location). If you attempt to install LAMMPS in a directory you, the user, do not have access to, you have to run the install with sudo, which then doesn't likely have the /opt/intel/bin directory in the root PATH, in which case the solution is simply to add a symbolic link for icc into /user/local/bin.

sudo ln -s /opt/intel/bin/icc /usr/local/bin

With icc accessible, running another sudo make linux produces the following errors:

sudo make clean-all
sudo make linux

make[1]: Entering directory `/opt/lammps-3Apr13/src/Obj_linux'
icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../write_restart.cpp > write_restart.d
../write_restart.cpp(15): catastrophic error: cannot open source file "mpi.h"
  #include "mpi.h"
                  ^

icc -O -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../write_data.cpp > write_data.d
../write_data.cpp(15): catastrophic error: cannot open source file "mpi.h"
  #include "mpi.h"
                  ^
...

icc -O  -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -c ../angle_charmm.cpp
../pointers.h(25): catastrophic error: cannot open source file "mpi.h"
  #include "mpi.h"
                  ^

compilation aborted for ../angle_charmm.cpp (code 4)
make[1]: *** [angle_charmm.o] Error 4
make[1]: Leaving directory `/opt/lammps-3Apr13/src/Obj_linux'
make: *** [linux] Error 2

The new problem is now an MPI problem, requiring the installation of (as recommended from the LAMMPS linux Makefile) MPICH. Reading the Makefile (you mean you didn't check this first?) also indicates the need for FFTW2. We can install all of the needed files in one shot with apt-get (and I include build-essential here for completeness, as you either did or didn't install it while trying to solve the icc problem above).

sudo apt-get install build-essential mpich-bin libmpich1.0-dev mpi-doc fftw2 fftw-dev libxaw7-dev libmpich2-dev

This still does not solve the mpi.h issue above, which is a problem with the settings in Makefile.linux (which, apparently, are not Ubuntu-compatible). The solution is, and this is why this is Part 1, to change Makefile.linux to make it compatible with the mpicc compiler in Ubuntu (I will attempt to get it working with icc next). The tweak to my Makefile.linux is provided below (an amalgam of some other Makefile settings. Comment out or delete what's there and add the sections without the "#" to the file):

#######################################################################
## My modified settings are below:

CC = mpicxx
CCFLAGS = -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK
DEPFLAGS =	-M

LINK = $(CC)
LINKFLAGS = -O
SIZE = size

USRLIB = -lfftw

ARCHIVE =	ar
ARFLAGS =	-rc

#######################################################################
## Comment the following out or delete them:

# CC =		icc
# CCFLAGS =	-O
# SHFLAGS =	-fPIC
# DEPFLAGS =	-M

# LINK =		icc
# LINKFLAGS =	-O
# LIB =           -lstdc++
# SIZE =		size

# ARCHIVE =	ar
# ARFLAGS =	-rc
# SHLIBFLAGS =	-shared

I will say that, in some of my searches, I found reference to the use of USRLIB -lmpi. If this is included in the Makefile.linux, you will get the following error upon mpicc (MPICH2) compilation:

/usr/bin/ld: cannot find -lmpl
collect2: ld returned 1 exit status
make[1]: *** [../lmp_linux] Error 1
make[1]: Leaving directory `/opt/lammps-3Apr13/src/Obj_linux'
make: *** [linux] Error 2

So, don't include -lmpi.

With the above Makefile modifications, building of LAMMPS seems to go quite well until the following error is produced:

mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK  -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -c ../dump_dcd.cpp
mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK  -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -c ../dump_image.cpp
../dump_image.cpp:32:21: error: jpeglib.h: No such file or directory
../dump_image.cpp: In member function ‘virtual int LAMMPS_NS::DumpImage::modify_param(int, char**)':
../dump_image.cpp:904: warning: suggest parentheses around assignment used as truth value
../dump_image.cpp:911: warning: suggest parentheses around assignment used as truth value
../dump_image.cpp:964: warning: suggest parentheses around assignment used as truth value
../dump_image.cpp:971: warning: suggest parentheses around assignment used as truth value
../dump_image.cpp: In member function ‘void LAMMPS_NS::DumpImage::create_image()':
../dump_image.cpp:611: warning: ‘diameter' may be used uninitialized in this function
../dump_image.cpp:612: warning: ‘color' may be used uninitialized in this function
../dump_image.cpp:612: warning: ‘color1' may be used uninitialized in this function
../dump_image.cpp:612: warning: ‘color2' may be used uninitialized in this function
make[1]: *** [dump_image.o] Error 1
make[1]: Leaving directory `/opt/lammps-3Apr13/src/Obj_linux'
make: *** [linux] Error 2

The jpeglib.h error can likely be solved by installing only one of the libraries below, but I didn't bother to identify which one, instead indiscriminately installing a whole set based on the recommendation of dev.xonotic.org/projects/xonotic/wiki/Repository_Access (having found this link at forums.xonotic.org/showthread.php?tid=1252 – but I removed some of the install that I'm sure was not needed):

sudo apt-get install libxxf86dga-dev libxcb-xf86dri0-dev libxpm-dev libxxf86vm-dev libsdl1.2-dev libsdl-image1.2-dev libclalsadrv-dev libasound2-dev libxext-dev

Finally, a successful build!

make[1]: Entering directory `/opt/lammps-3Apr13/src/Obj_linux'
mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../write_restart.cpp > write_restart.d
mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../write_data.cpp > write_data.d
mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../verlet.cpp > verlet.d
mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../velocity.cpp > velocity.d
mpicxx -O -DFFT_FFTW -DLAMMPS_GZIP -DMPICH_IGNORE_CXX_SEEK -DLAMMPS_GZIP -DLAMMPS_JPEG  -DMPICH_SKIP_MPICXX  -DFFT_FFTW   -M ../variable.cpp > variable.d
...
write_data.o write_restart.o  -lmpich -lpthread -lfftw -ljpeg   -o ../lmp_linux
size ../lmp_linux
   text	   data	    bss	    dec	    hex	filename
3654398	   6928	    264	3661590	 37df16	../lmp_linux
make[1]: Leaving directory `/opt/lammps-3Apr13/src/Obj_linux'

At this point, you can move the lmp_linux executable anywhere (or, as I find myself doing, just keep it in the lammps-DATE/src folder for when you perform subsequent builds).

Running An MPI Calculations

If you've never run through an MPI calculation, you'll get the following errors when you first try to run lmp_linux:

cannot connect to local mpd (/tmp/mpd2.console_user); possible causes:
  1. no mpd is running on this host
  2. an mpd is running but was started without a "console" (-n option)
In case 1, you can start an mpd on this host with:
    mpd &
and you will be able to run jobs just on this host.
For more details on starting mpds on a set of hosts, see
the MPICH2 Installation Guide.

**********

user@machine:/opt/lammps-3Apr13/src$ mpd &

configuration file /home/damianallis/.mpd.conf not found
A file named .mpd.conf file must be present in the user's home
directory (/etc/mpd.conf if root) with read and write access
only for the user, and must contain at least a line with:
MPD_SECRETWORD=
One way to safely create this file is to do the following:
  cd $HOME
  touch .mpd.conf
  chmod 600 .mpd.conf
and then use an editor to insert a line like
  MPD_SECRETWORD=mr45-j9z
into the file.  (Of course use some other secret word than mr45-j9z.)

[1]+  Exit 255                mpd

Simply follow the instructions to put a .mdp.conf in your ~/ folder, start mpd with "mpd &," and run LAMMPS with the following command below (which uses 2 cores (-np 2)).

NOTE: My LAMMPS test (being brand new to it) was to run the first test available from icme.hpc.msstate.edu/mediawiki/index.php/LAMMPS_Help. Following the instructions therein (DOWNLOAD: Al99.eam.alloy (780 KB) and calc_fcc.in (1 KB)):

sudo mpirun -np 2 ./lmp_linux < calc_fcc.in

Which should produce the following output:

LAMMPS (3 Apr 2013)
Lattice spacing in x,y,z = 4 4 4
Created orthogonal box = (0 0 0) to (4 4 4)
  1 by 1 by 2 MPI processor grid
Lattice spacing in x,y,z = 4 4 4
Created 4 atoms
Replicating atoms ...
  orthogonal box = (0 0 0) to (4 4 4)
  1 by 1 by 2 MPI processor grid
  4 atoms
WARNING: Resetting reneighboring criteria during minimization (../min.cpp:173)
Setting up minimization ...
Memory usage per processor = 2.40372 Mbytes
Step PotEng Lx Ly Lz Press Pxx Pyy Pzz eatoms 
       0   -13.417787            4            4            4     29590.11     29590.11     29590.11     29590.11   -13.417787 
      10   -13.439104         4.04         4.04         4.04    5853.9553    5853.9553    5853.9553    5853.9553   -13.439104 
      14       -13.44         4.05         4.05         4.05     2.726913     2.726913     2.726913     2.726913       -13.44 
Loop time of 0.0287241 on 2 procs for 14 steps with 4 atoms

Minimization stats:
  Stopping criterion = linesearch alpha is zero
  Energy initial, next-to-last, final = 
        -13.4177872966     -13.4399999525     -13.4399999525
  Force two-norm initial, final = 3.54599 0.000335006
  Force max component initial, final = 3.54599 0.000335006
  Final line search alpha, max atom move = 0.0625 2.09379e-05
  Iterations, force evaluations = 14 19

Pair  time (%) = 0.00206506 (7.18931)
Neigh time (%) = 0 (0)
Comm  time (%) = 0.00481999 (16.7803)
Outpt time (%) = 0.000162005 (0.564006)
Other time (%) = 0.021677 (75.4664)

Nlocal:    2 ave 2 max 2 min
Histogram: 2 0 0 0 0 0 0 0 0 0
Nghost:    603 ave 603 max 603 min
Histogram: 2 0 0 0 0 0 0 0 0 0
Neighs:    140 ave 162 max 118 min
Histogram: 1 0 0 0 0 0 0 0 0 1

Total # of neighbors = 280
Ave neighs/atom = 70
Neighbor list builds = 0
Dangerous builds = 0
Total energy (eV) = -13.439999952539944061;
Number of atoms = 4;
Lattice constant (Angstoms) = 4.049999999999998046;
Cohesive energy (eV) = -3.3599999881349860154;
All done!

Brief Update: Amber 11 And AmberTools 1.5 In Ubuntu 12.04 LTS

This post is a brief update to a much longer and more involved discussion of Amber 11 and AmberTools installation in Ubuntu 10.04 LTS (Lucid Lynx) (as the changes are minor and the parallelization setup remains largely the same). You can find this more involved discussion at www.somewhereville.com/?p=1422.

Long/Short – the installation under Ubuntu 12.04 LTS (Precise Pangolin) is not much different and goes without hitch provided you keep your locations organized. NOTE 1: I've not a copy of Amber12, so cannot speak for any changes to its installation procedure. NOTE 2: This install assumes 32-bit only.

Updated Procedure

If you tried installing all of the build software from the 10.04 LTS post, you'll receive errors like the following (as usual, I include error messages for those who are searching against error messages)…

user@machine:~$ sudo apt-get install build-essential cmake doxygen freeglut3-dev g++-multilib gcc-multilib gettext gnuplot ia32-libs lib32asound2 lib32gcc1 lib32gcc1-dbg lib32gfortran3 lib32gomp1 lib32mudflap0 lib32ncurses5 lib32nss-mdns lib32z1 libavdevice52 libc6-dev-i386 libc6-i386 libfreeimage-dev libglew1.5-dev libopenal1 libopenexr-dev libpng12-dev libqt4-dev libssl-dev libstdc++6-4.3-dbg libstdc++6-4.3-dev libstdc++6-4.3-doc libxi-dev libxml-simple-perl libxmu-dev mercurial nfs-common nfs-kernel-server portmap python2.6-dev rpm ssh

Errors…

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'rpcbind' instead of 'portmap'
Package libc6-i386 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  libc6

Package libstdc++6-4.3-dbg is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libstdc++6-4.3-doc is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

...

Package lib32nss-mdns is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'ia32-libs' has no installation candidate
E: Package 'lib32asound2' has no installation candidate
E: Package 'lib32gcc1' has no installation candidate
E: Package 'lib32gcc1-dbg' has no installation candidate
E: Package 'lib32gfortran3' has no installation candidate
E: Package 'lib32gomp1' has no installation candidate
E: Package 'lib32mudflap0' has no installation candidate
E: Package 'lib32ncurses5' has no installation candidate
E: Package 'lib32nss-mdns' has no installation candidate
E: Package 'lib32z1' has no installation candidate
E: Unable to locate package libavdevice52
E: Package 'libc6-dev-i386' has no installation candidate
E: Package 'libc6-i386' has no installation candidate
E: Package 'libstdc++6-4.3-dbg' has no installation candidate
E: Package 'libstdc++6-4.3-dev' has no installation candidate
E: Package 'libstdc++6-4.3-doc' has no installation candidate
E: Unable to locate package python2.6-dev
E: Couldn't find any package by regex 'python2.6-dev'

The actual install list is smaller than above (reproduced below) to install the necessary additionals to the base 12.04 LTS install. The procedure begins with an aptitude install, update, and upgrade (perform or do not perform as you like).

administrator@ChemistryLab:~$ sudo apt-get install aptitude
administrator@ChemistryLab:~$ sudo aptitude update
administrator@ChemistryLab:~$ sudo aptitude upgrade
administrator@ChemistryLab:~$ sudo apt-get install build-essential cmake doxygen freeglut3-dev g++-multilib gcc-multilib gettext gnuplot ia32-libs bison csh flex fort77 g++ gcc gfortran libbz2-dev libnetcdf-dev libopenmpi-dev libxext-dev libxt-dev openmpi-bin patch tcsh xorg-dev zlib1g-dev fftw-dev 

Amber11 and AmberTools 1.5 Install Specifics

Those used to sudo'ing everything will run into a compile complication with Amber11 as the $AMBERHOME assignment is not carried over into the make serial step:

make[1]: Entering directory `/opt/amber11/AmberTools/src/mmpbsa_py'
/bin/bash setup.sh
AMBERHOME is not set.  Assuming it is /opt/amber11
 Using AmberTools' python
Error importing MMPBSA python modules! MMPBSA.py will not work.
make[1]: *** [install] Error 1
make[1]: Leaving directory `/opt/amber11/AmberTools/src/mmpbsa_py'
make: *** [serial] Error 2

This is an avoidable annoyance by simply building in your $HOME directory and copying the resulting ~/amber11 folder to your desired location (and setting $PATH statements accordingly).

AmberTools 1.5 Install

Procedure is as found in the previous post (I am assuming that the files are sitting in your $HOME (cd ~/) fold…

tar xjf AmberTools-1.5.tar.bz2
cd amber11/
echo "export AMBERHOME=$PWD" >> ~/.bashrc
echo "export PATH=$PATH:$AMBERHOME/bin" >> ~/.bashrc
source ~/.bashrc
wget http://ambermd.org/bugfixes/AmberTools/1.5/bugfix.all
patch -p0 < bugfix.all
rm bugfix.all
cd AmberTools/src/
./configure gnu
make install

The Amber11 install is made slightly different than the previous instruction set by the download of the bugfix.all.tar.bz2 file and the different run of apply_bugfix.x. For a serial install...

tar xfj Amber11.tar.bz2
cd ~/
wget http://ambermd.org/bugfixes/11.0/bugfix.all.tar.bz2
wget http://ambermd.org/bugfixes/11.0/apply_bugfix.x
chmod +x ./apply_bugfix.x
./apply_bugfix.x bugfix.all.tar.bz2

You'll get a few CUDA-specific errors during the bugfix. I skipped the last two patches as I'm not compiling a CUDA-specific version.

cd AmberTools/src/
./configure gnu
cd $AMBERHOME
./AT15_Amber11.py
cd src/
make serial

With this completed, move the amber11 folder to /opt (or wherever), modify your .bashrc, and run the tests.

cd ~/
sudo mv amber11 /opt
nano .bashrc

Place the following into the .bashrc file

export AMBERHOME=/opt/amber11

And run the tests…

cd /opt/amber11/test/
make -f Makefile