Tagged: Fortran

MacOS Sierra for Computational Materials Science in 2017

An update of previous entries for setting up an Apple computer for scientific computing. It is not an absolute guide, but simply one way to get going.  I started with a clean install of Mac OS 10.12 (Sierra).

  • Awaken UNIX

The first step is to install the command line tools. Open a Terminal and type make which triggers the system to install Xcode (if missing) and the command line tools module (basic UNIX commands including a gcc compiler). Be sure to set up your bash_profile, ssh config, and vimrc files to make working faster and more comfortable.

  • Basics

My essential applications include: (standard office) Dropbox, Slack, MS Office (Imperial link), Mactex, Texmaker, Mendeley; (scientific computing) latest gcc/gfortraniTerm, Textmate, XQuartz, Atom, Cyberduck, GitHub client(materials modelling) VESTA, Avogadro.

  • Python

Python package and environment maintenance can cause headaches, so this time I went with Conda for Mac. I am happy with the results so far, and the standard install gives a good base set of packages.

  • Fortran and C

It is possible to survive using gnu compilers and freely available maths libraries, but Intel Fortran and MKL tend to be faster and better tested (easier to compile). For non-commericial purposes Intel Composer is now free for OS X. The package installs in a few clicks, but be sure source the variables in your .bash_profile:
source /opt/intel/mkl/bin/mklvars.sh intel64
source /opt/intel/bin/compilervars.sh intel64


The outcome:
% which ifort
/usr/local/bin/ifort
% ifort --version
ifort (IFORT) 17.0.4 20170411

  • Openmpi

To enable parallelism, I downloaded the latest source code of openmpi (2.1.1).
./configure -prefix=/usr/local/openmpi-2.1.1 CC=icc FC=ifort F77=ifort
make
sudo make install

be patient… it can easily take 20 minutes. Finally add to your .bash_profile:
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/openmpi-2.1.1/lib/
export PATH=./:/usr/local/openmpi-2.1.1/bin:$PATH
export OMP_NUM_THREADS=1

The outcome:
% which mpif90
/usr/local/openmpi-2.1.1/bin/mpif90
% mpif90 --version
ifort (IFORT) 17.0.4 20170411

  • Phonopy

I use this open-source lattice-dynamics package a lot. The installation used to be multi-step, but Conda makes life easier (adapted from Togo’s official guide):
% conda install numpy scipy h5py pyyaml matplotlib openblas
% git clone https://github.com/atztogo/phonopy.git
% export CC=gcc
% cd phonopy
% python setup.py install --user

To run: phonopy

If harmonic phonons are not enough for you, then Phono3py lets you calculate phonon-phonon interactions, but it gets very expensive to compute.
% git clone https://github.com/atztogo/phono3py.git
% cd phono3py
% python setup.py install --user

To run: phono3py

  • VASP

I use a range of electronic structure packages, but VASP is the old reliable. I downloaded the latest version (5.4.4), which has streamlined the install process. Enter the main folder and
cp ./arch/makefile.include.linux_intel ./makefile.include

The file needs to be modified to point to the correct compilers (I used icc, icpc, and mpifort). We will also remove DscaLAPACK from the pre-compiler options and set SCALAPACK =  . There is one bug to fix before you type make: in ./src/lib/getshmem.c add #define SHM_NORESERVE 010000 to the end of the include statements.

The outcome:
% mpirun -np 4 ../vasp_std
running on 4 total cores
distrk: each k-point on 4 cores, 1 groups
distr: one band on 1 cores, 4 groups
using from now: INCAR
vasp.5.4.4

  • ASE

The atomistic simulation environment is a useful set of Python tools and modules. It now installs, including the gui, in one command:
pip install --upgrade --user ase

The outcome:
ase-gui

ASE

I will update with more codes and tools as I find time, and always happy to receive suggestions.

Advertisements

El Capitan for Computational Materials Science in 2016

Every few years, I give my laptop a fresh start and remove all the debris (applications, libraries, updates) that have built up. This time I started with a clean install of Mac OS 10.11 (El Capitan).

  • Basics

The first step is to install the essentials including Dropbox, Evernote, Todoist, Xcode (with xcode-select --install), Slack, Mendeley, MS Office, gcc/gfortranPython superpack, VESTA, Transmission, Mactex, Texmaker, Unrar, VLC, Adobe Creative Suite, iTerm, Textmate, XQuartz.

  • Fortran

While it is possible to survive using gfortan and freely available maths libraries, Intel Fortran and MKL tend to be faster and better tested (easier to compile) in my experience. For non-commericial purposes Intel Composer is now free for OS X. The package installs in a few clicks, but be sure source the variables in your .bash_profile:
source /opt/intel/mkl/bin/mklvars.sh intel64
source /opt/intel/bin/ifortvars.sh intel64

Finally you will need to make the MKL fast fourier transforms (FFTs) for use in most solid-state simulation packages:
cd $MKLROOT/interfaces/fftw3xf/
sudo make libintel64 CC=gcc

The outcome:
Arons-Air-V:~ aron$ which ifort
/usr/local/bin/ifort
Arons-Air-V:~ aron$ ifort --version
ifort (IFORT) 16.0.1 20151020

  • Openmpi

To enable parallelism, I downloaded the latest source code of openmpi (1.10.1).
./configure -prefix=/usr/local/openmpi-1.10.1 CC=gcc FC=ifort F77=ifort
make
sudo make install

be patient… it can easily take 20 minutes. Finally add to your .bash_profile:
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/openmpi-1.10.1/lib/
export PATH=./:/usr/local/openmpi-1.10.1/bin:$PATH

The outcome:
Arons-Air-V:~ aron$ which mpif90
/usr/local/openmpi-1.10.1/bin/mpif90
Arons-Air-V:~ aron$ mpif90 --version
ifort (IFORT) 16.0.1 20151020

  • Phonopy

We use this open-source lattice-dynamics package a lot in our research. There are a few more libraries to install first:
sudo easy_install pip
pip2 install lxml
pip2 install pyyaml
export CC=/usr/local/bin/gcc

then after expanding the source code, simply type:
python setup.py install

The outcome:
Arons-Air-V:~ aron$ phonopy
_
_ __ | |__ ___ _ __ ___ _ __ _ _
| '_ \| '_ \ / _ \| '_ \ / _ \ | '_ \| | | |
| |_) | | | | (_) | | | | (_) || |_) | |_| |
| .__/|_| |_|\___/|_| |_|\___(_) .__/ \__, |
|_| |_| |___/
1.10.9

  • Phono3py

If harmonic phonons are not enough for you, then Phono3py lets you calculate phonon-phonon interactions, but it gets very computationally expensive. We need to install hdf5 (for more efficient data management):
pip2 install h5py

and lapacke for faster code. Download the latest version of lapack and:
cp make.inc.example make.inc
make lapackelib

Then you are ready to compile. Download Phono3py and modify setup3.py to link to your compiled lapacke library.
if platform.system() == 'Darwin':
include_dirs += ['/Users/aron/Documents/progs/lapack/lapack-3.6.1/lapacke/include']
extra_link_args = ['/Users/aron/Documents/progs/lapack/lapack-3.6.1/liblapacke.a']
followed by:
python setup3.py install

The outcome:
Arons-Air-V:~ aron$ phono3py
_ _____
_ __ | |__ ___ _ __ ___|___ / _ __ _ _
| '_ \| '_ \ / _ \| '_ \ / _ \ |_ \| '_ \| | | |
| |_) | | | | (_) | | | | (_) |__) | |_) | |_| |
| .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, |
|_| |_| |___/
1.10.9

  • VASP

While we use a range of electronic structure packages, VASP is the old reliable. I downloaded the latest version (5.4.1), which has streamlined the install process.
cp ./arch/makefile.include.linux_intel ./makefile.include

which needs to be modified to point to the correct compilers (here gcc, ifort and mpifort). We will also remove -DscaLAPACK from the precompiler options and set SCALAPACK = . There are now three patches/bug fixes to install:
patch -p1 < patch.5.4.1.08072015
patch -p1 < patch.5.4.1.27082015
patch -p1 < patch.5.4.1.06112015

and one fix to sort out a gcc error. To the file ./src/lib/getshmem.c add one line at the end of the include statements:
#define SHM_NORESERVE 010000

The outcome:
Arons-Air-V:test aron$ mpirun -np 4 ../vasp_std
running on 4 total cores
distrk: each k-point on 4 cores, 1 groups
distr: one band on 1 cores, 4 groups
using from now: INCAR
vasp.5.4.1 24Jun15 (build Jan 02 2016 21:20:37) complex

  • ASE

The atomistic simulation environment is a useful set of Python tools and modules. It now installs, including the gui, in two lines:
brew install pygtk
pip install python-ase

The outcome:
ase-gui

ASE

I will update with more codes and tools as I find time (posted in January; revised in July).

Mountain Lions like OpenMPI

Following the previous post on installing Fortran compilers in OSX 10.8 (Mountain Lions like Fortran), the next step is to efficiently exploit all of those lovely i7 cores for computational chemistry.

1. OpenMPI
– Forget any version that comes with XCode as you need to compile OpenMPI against your new Fortran installation.
– Download the binary from http://www.open-mpi.org/ (current version 1.6.3).
– Unzip and enter directory.
– Run “./configure –prefix=/usr/local/openmpi-1.6.3 CC=gcc FC=ifort F77=ifort”.
– Run “make”.
– Run “sudo make install”.
– Add to your .bashrc or .bash_profile:
export PATH=./:/usr/local/openmpi-1.6.3/bin:~/bin:/opt/intel/bin:$PATH
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/openmpi-1.6.3/lib

Result:
$ which mpif90
/usr/local/openmpi-1.6.3/bin/mpif90

2. FHI-AIMS
– A popular quantum chemistry package (from here; current version 081912).
– Update the Makefile to include:

FC = ifort
FFLAGS = -O3 -ip
F90FLAGS = $(FFLAGS)
ARCHITECTURE = Generic
LAPACKBLAS = -L/opt/intel/mkl/lib \
-I/opt/intel/mkl/include -lmkl_intel_lp64 \
-lmkl_sequential -lmkl_core
USE_MPI = yes
MPIFC = mpif90

– Run “make mpi”.
– Enjoy parallel calculations, e.g. mpirun -np 4 fhi-aims

3. VASP
– A popular materials modelling package (from here; current version 5.3.3).
– In the main src folder, “cp makefile.linux_ifc_P4 Makefile”.
– Update the Makefile to include:

FC=mpif90
FCL=$(FC)
FFLAGS = -FR -assume byterecl
OFLAG=-O3 -ip -ftz
MKL=/opt/intel/mkl
BLAS=-L/$(MKL)/lib -I/$(MKL)/include -lmkl_intel_lp64 \
-lmkl_sequential -lmkl_core -lmkl_lapack95_lp64

– Run “make”.
– Enjoy parallel calculations, e.g. mpirun -np 4 vasp

Mountain Lions like Fortran

A slow running laptop was a good excuse to play around with a fresh install of OSX 10.8 (Mountain Lion). The implementation of Xcode has been changing over the last few versions, so here are the few straight forward steps required to get command-line Fortran running on your Mac.

1. Download Xcode from the App Store
– Run application to Install
– Xcode Preferences -> Downloads -> Command Line Tools

2. GNU Compilers
– Download 10.8 gcc and gfortran binaries and libraries from http://hpc.sourceforge.net.
– In terminal run “sudo tar -xvf gcc-mlion.tar -C /”
– Ensure the line “export PATH=/usr/local/bin:$PATH” is in your .bash_profile.

Result:
$ gfortran –version
GNU Fortran (GCC) 4.8.0 20120722 (experimental)
$ gcc –version
gcc (GCC) 4.8.0 20120722 (experimental)

3. Intel Compilers (Fortran Composer 2011)
– Install package.
– For install environment choose “Command line install only”.
– If write permission issues arise, run “sudo chmod u+rwx /Users/Shared/Library/Application\ Support/”.
– source /opt/intel/bin/ifortvars.sh intel64
– source /opt/intel/mkl/bin/intel64/mklvars_intel64.sh
– Run once as “sudo ifort” to overcome some permissions issues with the libraries.

Result:
$ ifort –version
ifort (IFORT) 12.1.0 20111011

Example Makefile (FHI-AIMS):
FC = ifort
FFLAGS = -O3 -ip
F90FLAGS = $(FFLAGS)
ARCHITECTURE = Generic
LAPACKBLAS = -L/opt/intel/mkl/lib \
-I/opt/intel/mkl/include -lmkl_intel_lp64 \
-lmkl_sequential -lmkl_core

Apple for science

For my research, Mac offers a nice compromise between the functionality of Windows and the power of Linux.  Chemistry comfort software like Chemdraw, Endnote, Mendeley, MS Office and LaTEX are all available. For scientific computing, there are a few quirks that you need to get around:

(i) Where is .bashrc? It hides in /etc/bashrc. For a splash of colour, add export TERM=xterm-color to your .bash_profile.

(ii) Package managers: no Yum, but Macports and Fink work well.

(iii) How to hide folders from Finder? Away from the command line, some folders really should remain hidden from view. One good example is the ‘Microsoft_User_Data’ folder. Solution: SetFile -a V [folder]

(iv) Free useful applications? Mendeley (references); Vesta (visualisation); Inkscape (vector art); Gimp (bitmap art); Open Babel (structure conversion);  GeoGebra (geometric fun); Texmaker (LaTex GUI).

(v) Free C and Fortran compilers? You would expect to have standard compilers installed by default. Well no, but fortunately the good people at Mac HPC and Mac Research are there to help. First you need to install XCode (from the AppStore, or directly from here), and for the newer versions you need to install the command line tools add-on separately. This sets up a basic gcc compiler. Binaries for the latest versions of gcc/gfortran are available here. Be sure to download both binaries, and remember to add the path to your shell: export PATH=/usr/local/bin:$PATH

(vi) Materials modelling codes (FHI-AIMS, VASP, GULP)? For GULP, an OSX binary is available. Once gfortran is installed, you can download and compile standard Unix distributions of GotoBLAS and LAPACK. For FHI-AIMS, the makefile is straightforward, and the binary runs perfectly:

FC = gfortran -m64
FFLAGS = -O2 -ffree-line-length-none
F90FLAGS = $(FFLAGS)
ARCH = arch_generic.f90
LAPACKBLAS = /progs/lapack-3.2.1/lapack_LINUX.a /progs/GotoBLAS2/libgoto2-r1.13.a

For VASP 5, the following gives a serial binary that works quite well:

FC = gfortran -m64
OFLAG  = -O2
FFLAGS = -ffree-form -ffree-line-length-none
BLAS = /progs/GotoBLAS2/libgoto2-r1.13.a
LAPACK = /progs/lapack-3.2.1/lapack_LINUX.a

In my experience OpenMPI works well, with efficient use of four cores on i7 iMacs, and as expected for the premium price, the Intel fortran compiler (and MKL libraries) result in a significant (~20%) performance boost.  Unfortunately, no non-commercial version of ifort is available for Macs.