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!

GROMACS 4.5.5, OpenMPI 1.6, And FFTW 3.3.2 Compilation Under Mountain Lion (OSX 10.8) With XCode (And A Little Help From Homebrew)

Minus a few glitches easily fixed with the right software, this build wasn't bad at all (and thanks to Adam Lindsay for the title catch).

Now sitting in front of a new Core i7 MacBook Pro, one of the first compilations I wanted to have finished for new projects was GROMACS 4.5.5. As my procedure for compiling GROMACS 3.3.3 had been a highly-traveled page, I wanted to provide a brief summary of my successful 4.5.5 compilation.

A Few Piece Of Info

1. XCode

This used to be disc-download and install, now it's available as a free download from the App Store (1.57 GB download, so plan to do something else while you wait for the download).

2. Homebrew

Having Homebrew installed in Mountain Lion made the installation of FFTW easy and OpenMPI trivial once gfortran was equally trivially installed. Therefore, to make your life easier, I can't recommend a Homebrew installation enough. For additional install tweaks, I followed the following page: gist.github.com/1860902

Installation Procedure

1. Download gromacs 4.5.5

…and place it in your home folder (will go to Downloads most likely, drag it to your home folder for ease of building).

2. Extract into your home holder

…with a double-click, making ~/gromacs-4.5.5.

3. brew install fftw

With the install of Homebrew, you'll simply run the following from a terminal window and produce the following output:

brew install fftw

==> Downloading http://www.fftw.org/fftw-3.3.2.tar.gz
######################################################################## 100.0%
==> ./configure --enable-single --enable-sse --enable-shared --disable-debug 
--prefix=/usr/local/Cellar/fftw/3.3.2 --enable-threads --disable-fortran
==> make install
==> make clean
==> ./configure --enable-sse2 --enable-shared --disable-debug 
--prefix=/usr/local/Cellar/fftw/3.3.2 --enable-threads --disable-fortran
==> make install
==> make clean
==> ./configure --enable-long-double --enable-shared --disable-debug 
--prefix=/usr/local/Cellar/fftw/3.3.2 --enable-threads --disable-fortran
==> make install
/usr/local/Cellar/fftw/3.3.2: 34 files, 13M, built in 2.7 minutes

4. brew install gfortran

If you don't install gfortran FIRST and try to install OpenMPI, you'll get the following error in Homebrew:

==> Downloading http://www.open-mpi.org/software/ompi/v1.6/downloads/openmpi-1.6.tar.bz2
######################################################################## 100.0%
Error: This formula requires a fortran compiler, but we could not find one by
looking at the FC environment variable or searching your PATH for `gfortran`.
Please take one of the following actions:

  - Decide to use the build of gfortran 4.2.x provided by Homebrew using
        `brew install gfortran`

  - Choose another Fortran compiler by setting the FC environment variable:
        export FC=/path/to/some/fortran/compiler
    Using an alternative compiler may produce more efficient code, but we will
    not be able to provide support for build errors.

So don't. Installing gfortran will produce the following:

brew install gfortran

==> Downloading http://r.research.att.com/tools/gcc-42-5666.3-darwin11.pkg
######################################################################## 100.0%
==> Installing gfortran 4.2.4 for XCode 4.2 (build 5666) or higher
==> Caveats
Brews that require a Fortran compiler should not use:
  depends_on 'gfortran'

The preferred method of declaring Fortran support is to use:
  def install
    ...
    ENV.fortran
    ...
  end

==> Summary
/usr/local/Cellar/gfortran/4.2.4-5666.3: 86 files, 72M, built in 39 seconds

5. brew install openmpi

This is what allows you to use all cores on your machine and is not in the default XCode install.

brew install openmpi

==> Downloading http://www.open-mpi.org/software/ompi/v1.6/downloads/openmpi-1.6.tar.bz2
Already downloaded: /Library/Caches/Homebrew/open-mpi-1.6.tar.bz2
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.

==> ./configure --prefix=/usr/local/Cellar/open-mpi/1.6 --enable-ipv6
==> make all
==> make install
/usr/local/Cellar/open-mpi/1.6: 674 files, 21M, built in 5.9 minutes

6. cd gromacs-4.5.5

7. ./configure –enable-float –enable-mpi

You'll produce output such as found in: 2012august29_gromacs455_configure.txt

You'll also get two odd errors at the end of the ./configure run that do not affect the rest of the procedure:

./configure --enable-float --enable-mpi

...
./configure: line 29242: sort: No such file or directory
./configure: line 29239: sed: No such file or directory

So ignore them.

NOTE: If you've been going by my 3.3.3 procedure and used…

./configure --enable-mpi --enable-double

You'll get the following error when you try to run make:

Making all in include
Making all in .
make[2]: Nothing to be done for `all-am'.
Making all in types
make[2]: Nothing to be done for `all'.

...

/bin/sh https://www.somewhereville.com/libtool --tag=CC   --mode=compile mpicc -DHAVE_CONFIG_H -I. -Ihttps://www.somewhereville.com/src -I/usr/include/libxml2 -Ihttps://www.somewhereville.com/include -DGMXLIBDIR=\"/usr/local/gromacs/share/top\"   -O3 -fomit-frame-pointer -finline-functions -Wall -Wno-unused -msse2 -funroll-all-loops -std=gnu99 -MT genborn_sse2_double.lo -MD -MP -MF .deps/genborn_sse2_double.Tpo -c -o genborn_sse2_double.lo genborn_sse2_double.c
 mpicc -DHAVE_CONFIG_H -I. -Ihttps://www.somewhereville.com/src -I/usr/include/libxml2 -Ihttps://www.somewhereville.com/include -DGMXLIBDIR=\"/usr/local/gromacs/share/top\" -O3 -fomit-frame-pointer -finline-functions -Wall -Wno-unused -msse2 -funroll-all-loops -std=gnu99 -MT genborn_sse2_double.lo -MD -MP -MF .deps/genborn_sse2_double.Tpo -c genborn_sse2_double.c  -fno-common -DPIC -o .libs/genborn_sse2_double.o
genborn_sse2_double.c:931: internal compiler error: Segmentation fault: 11
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
make[3]: *** [genborn_sse2_double.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

So don't do that, either. The proper flag is the enable-float.

8. make

This will produce the output available for download at: 2012august29_gromacs455_make.txt

9. make install

This will produce the output available for download at: 2012august29_gromacs455_make_install.txt

10. make links

This will produce the short piece of output reproduced below.

cd /usr/local/gromacs/bin && programs=`ls` && cd /usr/local/bin && \
	for i in $programs; do \
	   (test ! -f $i && ln -s /usr/local/gromacs/bin/$i . ; exit 0); \
	done

And with that, you should be able to run all programs from a terminal window.