Tuesday, August 9, 2011

LAMMPS, FFTW, JPEGLIB and MPICH2 Installation on MAC OS X

This post shows how to install LAMMPS on MAC. To have parallel build one needs to install some MPI wrapper like OpenMPI or MPICH2. For some type of simulations with LAMMPS you need FFTW too. I wanted to have Jpeg libraries too with LAMMPS. Of course, you need the most important piece, C, C++ and Fortran compilers. If you just need LAMMPS, I mean with out optional packages, then you don't need Fortran compiler. I recommend Intel compilers. Yesterday, I built LAMMPS with all these and thought it might be helpful for someone if I posted it here.

Oho, by the way make sure you download XCODE and install it before you install Intel compilers. Otherwise, you won't be able to create c executables. You can download it from Apple website. It is also there on the CDs that come with your mac. Xcode is not installed by default.

Here is how it goes ...

Jpeg Libraries

You can download the source at http://www.ijg.org/
$ cd Desktop
$ tar xzvf jpegsrc.v8c.tar.gz
$ cd jpeg-8c/
$ mkdir ~/libjpeg
$ ./configure --prefix=/Users/sm4082/libjpeg/ CC=icc \
CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
LDFLAGS='-L/Developer/opt/intel/Compiler/11.1/084/lib/' \
CPPFLAGS='-I/Developer/opt/intel/Compiler/11.1/084/include'
$ make
$ make install
$ make test

MPICH2 Installation

MPICH2 can be downloaded from http://www.mcs.anl.gov/research/projects/mpich2/.
$ cd ~/Desktop
$ tar xzvf mpich2-1.4.tar.gz
$ cd mpich2-1.4
$ mkdir ~/mpich2
$ ./configure --prefix=/Users/sm4082/mpich2 CC=icc \
CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
F77=ifort FFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' FC=ifort \
FCFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' CXX=icpc \
CXXFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' --enable-f77 \
--enable-fc --enable-cxx --enable-totalview --enable-mpe \
--enable-fast=O2 --with-device=ch3:nemesis \
--with-pm=hydra:mpd:gforker --enable-error-checking=all \
--enable-error-messages=all --enable-smpcoll --enable-nmpi-as-mpi \
--enable-timing=all --enable-timer-type=gettimeofday \
--enable-romio --enable-threads=default --enable-debuginfo --enable-g=dbg,log --disable-rpath 2>&1 | tee c.txt
$ make 2>&1 | tee m.txt
$ make install 2>&1 | tee mi.txt

FFTW Installation

LAMMPS doesn't work with FFTW version 3.X version. We need to install version 2.X.X. FFTW can be downloaded from http://www.fftw.org/
$ cd ~/Desktop
$ tar xzvf fftw-2.1.5.tar.gz
$ cd fftw-2.1.5
$ mkdir ~/fftw-2.1.5
$ ./configure CC='icc' CFLAGS='-O2 -fPIC -align -Zp8 -axP -unroll -xP -ip' \
LDFLAGS='-L/Developer/opt/intel/Compiler/11.1/084/lib' \
CPPFLAGS='-I/Developer/opt/intel/Compiler/11.1/084/include' --enable-shared  \
--enable-mpi MPICC=/Users/sm4082/mpich2/bin/mpicc \
LDFLAGS='-L/Users/sm4082/mpich2/lib' \
CPPFLAGS='-I/Users/sm4082/mpich2/include' --with-openmp \
--enable-debug --disable-fortran --prefix=/Users/sm4082/fftw-2.1.5/
$ make
$ make install
$ make check

Finally, LAMMPS Installation

LAMMPS can be downloaded from http://lammps.sandia.gov/
To install packages like MEAM, REAX you need Fortran compiler. I have used Intel Fortran compiler.
$ cd ~/Desktop
$ tar xzvf lammps.tar.gz
$ cd lammps-5Aug11/lib/meam/
$ make -f Makefile.ifort
$ cd ../poems/
$ make -f Makefile.icc
$ cd ../reax/
$ make -f Makefile.ifort
$ cd ../../src/
Next, edit the makefile Makefile.linux in MAKE folder in src directory.
$ more MAKE/Makefile.linux
# linux = RedHat Linux box, Intel icc, Intel ifort, MPICH2, FFTW

SHELL = /bin/sh

# ---------------------------------------------------------------------
# compiler/linker settings
# specify flags and libraries needed for your compiler

CC =            /Users/sm4082/mpich2/bin/mpic++
CCFLAGS =       -O3 -fPIC -align -Zp8 -axP -unroll -xP -ip
DEPFLAGS =      -M
LINK =          /Users/sm4082/mpich2/bin/mpic++
LINKFLAGS =     -O
LIB =           -lstdc++
ARCHIVE =       ar
ARFLAGS =       -rc
SIZE =          size

# ---------------------------------------------------------------------
# LAMMPS-specific settings
# specify settings for LAMMPS features you will use

# LAMMPS ifdef options, see doc/Section_start.html

LMP_INC =       -DLAMMPS_GZIP -DLAMMPS_JPEG

# MPI library, can be src/STUBS dummy lib
# INC = path for mpi.h, MPI compiler settings
# PATH = path for MPI library
# LIB = name of MPI library

MPI_INC =       -DMPICH_SKIP_MPICXX -I/Users/sm4082/mpich2/include
MPI_PATH = -L/Users/sm4082/mpich2/lib
MPI_LIB =       -lmpich -lpthread

# FFT library, can be -DFFT_NONE if not using PPPM from KSPACE package
# INC = -DFFT_FFTW, -DFFT_INTEL, -DFFT_NONE, etc, FFT compiler settings
# PATH = path for FFT library
# LIB = name of FFT library

FFT_INC =       -DFFT_FFTW -I/Users/sm4082/fftw-2.1.5/include
FFT_PATH = -L/Users/sm4082/fftw-2.1.5/lib
FFT_LIB =       -lfftw

# JPEG library, only needed if -DLAMMPS_JPEG listed with LMP_INC
# INC = path for jpeglib.h
# PATH = path for JPEG library
# LIB = name of JPEG library

JPG_INC =      -I/Users/sm4082/libjpeg/include 
JPG_PATH =      -L/Users/sm4082/libjpeg/lib
JPG_LIB =       -ljpeg

# additional system libraries needed by LAMMPS package libraries
# these settings are IGNORED if the corresponding LAMMPS package
#   (e.g. gpu, meam) is NOT included in the LAMMPS build
# SYSINC = settings to compile with
# SYSLIB = libraries to link with
# SYSPATH = paths to libraries

gpu_SYSINC =
meam_SYSINC =
reax_SYSINC =
user-atc_SYSINC =
user-awpmd_SYSINC =

gpu_SYSLIB =       -lcudart -lcuda
meam_SYSLIB =      -lifcore -lsvml -lompstub -limf
poems_SYSLIB =     -lifcore -lsvml -lompstub -limf
reax_SYSLIB =      -lifcore -lsvml -lompstub -limf
user-atc_SYSLIB =  -lblas -llapack
user-awpmd_SYSLIB =  -lblas -llapack

gpu_SYSPATH =      -L/usr/local/cuda/lib64
meam_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
poems_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
reax_SYSPATH =     -L/Developer/opt/intel/Compiler/11.1/084/lib
user-atc_SYSPATH =
user-awpmd_SYSPATH =

# ---------------------------------------------------------------------
# build rules and dependencies
# no need to edit this section

include Makefile.package

EXTRA_INC = $(LMP_INC) $(PKG_INC) $(MPI_INC) $(FFT_INC) $(JPG_INC) $(PKG_SYSINC)
EXTRA_PATH = $(PKG_PATH) $(MPI_PATH) $(FFT_PATH) $(JPG_PATH) $(PKG_SYSPATH)
EXTRA_LIB = $(PKG_LIB) $(MPI_LIB) $(FFT_LIB) $(JPG_LIB) $(PKG_SYSLIB)

# Link target

$(EXE): $(OBJ)
        $(LINK) $(LINKFLAGS) $(EXTRA_PATH) $(OBJ) $(EXTRA_LIB) $(LIB) -o $(EXE)
        $(SIZE) $(EXE)

# Library target

lib:    $(OBJ)
        $(ARCHIVE) $(ARFLAGS) $(EXE) $(OBJ)

# Compilation rules

%.o:%.cpp
        $(CC) $(CCFLAGS) $(EXTRA_INC) -c $<

%.d:%.cpp
        $(CC) $(CCFLAGS) $(EXTRA_INC) $(DEPFLAGS) $< > $@

# Individual dependencies

DEPENDS = $(OBJ:.o=.d)
include $(DEPENDS)
Edit the Makefile.linux following the above makefile. You need Fortran libraries for compiling packages Meam and Reax. The library needed is libifcore. So, I have created a link to this in intel C/C++ lib folder. The advantage of doing this is that you just need to add just intel C/C++ lib to DYLD_LIBRARY_PATH, but not Fortran libraries location. If you want you can include Fortran libraries location for meam_SYSPATH and reax_SYSPATH variables in makefile. But like I said, you need to add both C/C++ and Fortran library locations to DYLD_LIBRARY_PATH.
$ sudo -s
$ ln -s /Developer/opt/intel/composerxe-2011.0.085/compiler/lib/libifcore.a /Developer/opt/intel/Compiler/11.1/084/lib/libifcore.a
$ ln -s /Developer/opt/intel/composerxe-2011.0.085/compiler/lib/libifcore.dylib /Developer/opt/intel/Compiler/11.1/084/lib/libifcore.dylib
$ exit
$ make yes-granular
$ make yes-meam
$ make yes-poems
$ make yes-reax
$ make linux
You should see the lammps executable lmp_linux at the end of the installation.

Running examples with LAMMPS executable

First, we need to make sure the path of Intel libraries, /Developer/opt/intel/Compiler/11.1/084/lib, is added to DYLD_LIBRARY_PATH. You can either do it temporarily for a session or permanently by adding to your ~.bashrc.
Temporary
$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Developer/opt/intel/Compiler/11.1/084/lib
Permanent
$ cd
$ echo "export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Developer/opt/intel/Compiler/11.1/084/lib" >> .bashrc
$ source .bashrc
If you still see library problems while trying to run examples, I suggest add the location of MPICH2, Jpeg and FFTW libraries also to DYLD_LIBRARY_PATH varaible.

LAMMPS Examples

$ cd lammps-5Aug11/examples/meam/
$ ../../src/lmp_linux < in.meam
$ cd ../peptide
$ ../../src/lmp_linux < in.peptide 
$ cd ../micelle/
$ ../../src/lmp_linux < in.micelle 
$ cd ../flow/
$ ../../src/lmp_linux < in.flow.couette 
$ ../../src/lmp_linux < in.flow.pois
For all these runs you should see lammps running successfully outputting details on the screen just like the ones shown in the log files in those respective example directories. Most of the time, the errors come from the library problems like library not found. Which means library location is not added to DYLD_LIBRARY_PATH variable. You can run the same examples with mpi wrapper in parallel.
$ ~/mpich2/bin/mpiexec -n 4 ../../src/lmp_linux < in.flow.couette
or
$ ~/mpich2/bin/mpirun -np 4 ../../src/lmp_linux < in.flow.couette
You should see something like "Loop time of 0.523332 on 4 procs for 10000 steps with 420 atoms" instead of "Loop time of 0.468267 on 1 procs for 10000 steps with 420 atoms".

Sometimes, you need to go to Security pane in the System Preferences and add lmp_linux to allowed incoming connections. Otherwise, it won't let you run any parallel runs. By the way, you need to go to advanced tab on the security pane to do this.

If everything goes well you're done. You got LAMMPS executable to run whole lot of simulations in the days ahead of you. Good luck. If you get problems don't hesitate to drop me a comment and I'll try my best to help you out.

No comments:

PBS Script Generator: Interdependent dropdown/select menus in Javascript

PBS SCRIPT GENERATOR
SH/BASH TCSH/CSH
Begin End Abort

About Me

LA, CA, United States
Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

Sreedhar Manchu

Sreedhar Manchu
Higher Education: Not a simple life anymore