Using Intel® MKL in GROMACS

Step 1 - Overview

This guide is intended to help the current GROMACS users to potentialy improve performance by utilizing Intel® Math Kernel Library (Intel® MKL).

This article explains how to build 64-bit GROMACS with Intel® MKL for Intel64 based applications.

GROMACS is a versatile package to perform molecular dynamics, i.e. simulate the Newtonian equations of motion for systems with hundreds to millions of particles.

[Reference: http://www.gromacs.org/About_Gromacs *]

Version Information

This application note was created to help users who use GROMACS to also incorporate the latest versions of Intel MKL 10.3.x or 11.0 on Linux* platforms on

Intel® Xeon® * processor-based systems. Specifically, we'll address Intel MKL version 11.0.

This application note applies to Intel® Composer XE 2013 and GROMACS 4.0.7.

 

Step 2- Downloading GROMACS Source Code

Prerequisites:

  1. Intel® MKL contains highly optimized BLAS, LAPACK, and FFT and also the wrappers for FFTW, to get evaluation/non -commercial/licensed copy of 
    Intel® MKL, refer to  Intel® Math Kernel Library product Page.
  2. To get evaluation/non-commercial/licensed copy of Intel®  Compilers, refer to  Intel C++ and Fortran compilers product page (Intel MKL and Intel Compilers are now available in a single package - Intel Composer XE 2013).
  3. To get GROMACS - http://www.gromacs.org/

Note: This application note is written specifically for use with the Intel Compilers. Though using Intel MKL with GROMACS built with other compilers is also possible.

Unpack:

 Use the following commands to extract the GROMACS files:

 tar -xf gromacs-x.x.x.tar.gz


This will create a directory called gromacs-x.x.x. 


Step 3 - Building GROMACS

Update configure:

Modify configure.ac  from

mkl*)

###########

# Intel Math Kernel Library version 6 and later.

##########

AC_MSG_CHECKING([for mkl_dfti.h])

AC_TRY_COMPILE([#include<mkl_dfti.h>],,AC_MSG_RESULT(yes),AC_MSG_ERROR([Cannot find mkl_dfti.h header from Intel Math Kernel Library>=6.0.]

))

## Check for library

# AC_CHECK_LIB([guide],main,,AC_MSG_ERROR([Cannot find libguide (Intel MKL)]))

AC_CHECK_LIB([mkl],DftiComputeForward,,

AC_MSG_ERROR([Cannot find Intel Math Kernel Library >= 6.0]))

MDLIB_LIBOBJS="$MDLIB_LIBOBJS gmx_fft_mkl.lo"

;;


to

mklfftw3*)

###########

# FFTW3 wrappers in Intel Math Kernel Library version 6 and later.

##########

AC_MSG_CHECKING([for fftw3.h])

AC_TRY_COMPILE([#include<fftw3.h>],,AC_MSG_RESULT(yes),AC_MSG_ERROR([Cannot find fftw3.h header from Intel Math Kernel Library>=6.0.]

))

## Check for library

AC_CHECK_LIB([mkl_intel_ilp64],fftw_execute,LIBS="-lmkl_intel_thread -lmkl_core -liomp5 -lpthread $LIBS",

AC_MSG_ERROR([Cannot find Intel Math Kernel Library >= 6.0]),[-lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread])

MDLIB_LIBOBJS="$MDLIB_LIBOBJS gmx_fft_fftw3.lo"

;;

mkl*)

###########

# Intel Math Kernel Library version 6 and later.

##########

AC_MSG_CHECKING([for mkl_dfti.h])

AC_TRY_COMPILE([#include<mkl_dfti.h>],,AC_MSG_RESULT(yes),AC_MSG_ERROR([Cannot find mkl_dfti.h header from Intel Math Kernel Library>=6.0.]

))

## Check for library

AC_CHECK_LIB([mkl_intel_ilp64],DftiComputeForward,LIBS="-lmkl_intel_thread -lmkl_core -liomp5 -lpthread $LIBS",

AC_MSG_ERROR([Cannot find Intel Math Kernel Library >= 6.0]),[-lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread])

MDLIB_LIBOBJS="$MDLIB_LIBOBJS gmx_fft_mkl.lo"

;;

Run autoreconf without any parameters. Autoconf (that includes autoreconf) could be found here http://www.gnu.org/software/autoconf/

Set environment:

  • Make sure that C/C++ and Fortran compilers are installed properly and <PATH> environment variable is set to compiler installation directory.
  • Set <LD_LIBRARY_PATH> to compiler(C/C++ or Fortran) and Intel MKL library installation directory.
  • Make sure that  <MKLROOT>  environment variable to point to the MKL installation directory on your system.
  • Another easy option to configure Intel Compilers and Intel MKL environment to build 64-bit application is to run mklvars.sh script file, which is part of <MKLROOT>/bin directory
  • Also make sure that other environment variables like CC, CXX, F77, CFLAGS, CPPFLAGS, LDFLAGS are set as below.
export CC=icc

export CXX=icc

export F77=ifort

export CFLAGS="-O3 -ipo- -static -std=c99 -fPIC -DMKL_LP64 -DM_PI=3.1415926535897932384"

export CPPFLAGS="-I$MKLROOT/include -I$MKLROOT/include/fftw"

export LDFLAGS="-L$MKLROOT/lib/intel64 -L$MKLROOT/../compiler/lib/intel64"

export LD_LIBRARY_PATH="$MKLROOT/lib/intel64:$MKLROOT/../compiler/lib/intel64:$LD_LIBRARY_PATH"


Configure and make:

Build GROMACS and install it in the standard place

configure --with-fft=mklfftw3

make

make install 

Step 4 - Running GROMACS

Add standard GROMACS path to environment variable <PATH>

You should be able to run GROMACS. For more information about GROMACS, refer to http://www.gromacs.org/About_Gromacs*

For more complete information about compiler optimizations, see our Optimization Notice.

Comments

insikk's picture

In Step 3 - Building GROMACS
Above instruction modifies configure.ac. However I can see there already is mkl option. So I tried configure with

configure --with-fft=mkl

, and it worked with gromacs 4.5.6.
Why bother changing configure.ac?? What is the reason behind the change?

kiran s.'s picture

i followed same steps but gave error

./configure --prefix=/home/kiran/installdir/gromac/installgromacmkl CC=mpiicc CXX=mpiicpc F77=mpiifort --enable-mpi=mpiicc --host=x86_64 --with-fft=mkl

checking for C compiler default output file name...
configure: error: in `/home/kiran/installdir/gromac/gromacs-4.5.4':
configure: error: C compiler cannot create executables
See `config.log' for more details.

please help

 

kiran s.'s picture

above error is solved but another error has come

checking for _FILE_OFFSET_BITS value needed for large files... no
checking for _LARGEFILE_SOURCE value needed for large files... 1
configure: Using built-in math library with intel compiler
./configure: line 27148: syntax error near unexpected token `Cannot'
./configure: line 27148: `  C_MSG_ERROR(Cannot find Intel Math Kernel Library >= 6.0)'