NAMD

How to build NAMD with Arm Compiler for HPC.

Introduction

NAMD is a parallel molecular dynamics code designed for high-performance simulation of large biomolecular systems. Leveraging the Charm++ parallel programming framework, NAMD scales to hundreds of cores for typical simulations and beyond 500,000 cores for the largest simulations.

Charm++ is a machine independent parallel programming system. Programs written using this system run unchanged on MIMD machines with or without a shared memory. It provides high-level mechanisms and strategies to facilitate the task of developing even highly complex parallel applications.

For more information on Charm++ or NAMD, visit the Charm++ or NAMD webpages, respectively.

Version information

These instructions focus on building NAMD for a single node, multicore platform.

For the purposes of this build, the following components are used:

Component
Form
NAMD Version 2.12
Charm++ Version 6.8.0
Arm Performance Libraries
Version 18.2
Arm Compiler for HPC
Version 18.2
Operating System
Ubuntu 16.04
Hardware Cavium ThunderX2

Prerequisites

The NAMD build instructions are dependent on Charm++. Ensure, Charm++ is built and installed on your system.

Note: Instructions to build and install Charm++ are provided in this tutorial.

Setup directories

Create a new directory called NAMD and change into it:

mkdir ~/NAMD
cd ~/NAMD

Create a new build and install directories, using:

mkdir build
mkdir install

Setup the variables BUILD_DIR and INSTALL_DIR, using:

BUILD_DIR=~/NAMD/build
INSTALL_DIR=~/NAMD/install

Compiler configuration

Ensure that your paths are set up appropriately for Arm Compiler for HPC, for example:

export PATH=/path/to/ArmCompiler/bin:$PATH
export LD_LIBRARY_PATH=/path/to/ArmCompiler/lib:$LD_LIBRARY_PATH

To configure your installation of Arm Compiler for HPC, use:

export CC=armclang
export CXX=armclang++
export FC=armflang

(Optional) Set tuning flags:

TUNE="-march=armv8.1-a -mcpu=native -ffp-contract=fast -fsimdmath"

(Optional) Disable some compiler warnings:

WARN="-Wno-parentheses-equality -Wno-writable-strings -Wno-return-type -Wno-logical-op-parentheses -Wno-writable-strings -Wno-deprecated-register "

Download and unpack Charm

Change into your build directory:

cd $BUILD_DIR

Download and unpack the source files for Charm++, using:

wget https://charm.cs.illinois.edu/distrib/charm-6.8.0.tar.bz2 
tar -jxf charm-6.8.0.tar.bz2

Build and install Charm with Arm Compiler for HPC

  1. Change into the charm-6.8.0 directory, using:

    cd charm-6.8.0
  2. Generate an armclang configuration for the required architecture based on the existing one in src/arch/, for example src/arch/multicore-linux64, using:

    CHARMARCH=multicore-linux-aarch64

    cp -R src/arch/multicore-linux64 src/arch/$CHARMARCH

    FILE=src/arch/$CHARMARCH/conv-mach.sh
    sed -i "s|^CMK_CPP_CHARM=.*|CMK_CPP_CHARM='cpp -P'|g" $FILE
    sed -i "s|^CMK_NATIVE_CC=.*|CMK_NATIVE_CC='$CC '|g" $FILE
    sed -i "s|^CMK_NATIVE_CXX=.*|CMK_NATIVE_CXX='$CXX '|g" $FILE
    sed -i "s|^CMK_NATIVE_LD=.*|CMK_NATIVE_LD='$CC '|g" $FILE
    sed -i "s|^CMK_NATIVE_LDXX=.*|CMK_NATIVE_LDXX='$CXX '|g" $FILE
    sed -i "s|^CMK_QT=.*|CMK_QT='generic64-light '|g" $FILE
    sed -i "s|^CMK_CF77=.*|CMK_CF77='$FC '|g" $FILE
    sed -i "s|^CMK_CF90=.*|CMK_CF90='$FC '|g" $FILE
    sed -i "s|^CMK_CF90_FIXED=.*|CMK_CF90_FIXED='$FC -Mfixed '|g" $FILE

    sed -i "/#endif/i #define CMK_THREADS_USE_CONTEXT                            1" ${FILE%%.sh}.h
    sed -i "/#endif/i #define CMK_THREADS_USE_PTHREADS                           0" ${FILE%%.sh}.h
    sed -i "/#endif/i #define CMK_64BIT                                          1" ${FILE%%.sh}.h

    sed -i "s|cc-gcc|cc-armclang|g" $FILE

    cp src/arch/common/cc-gcc.sh src/arch/common/cc-armclang.sh

    sed -i "s|gcc|armclang|g" src/arch/common/cc-armclang.sh
    sed -i "s|g++|armclang++|g" src/arch/common/cc-armclang.sh
  3. Configure and build Charm++, using:

    mkdir ${INSTALL_DIR}/charm680/
    ./build charm++ $CHARMARCH --with-production --destination=${INSTALL_DIR}/charm680/${CHARMARCH} -j

Download and unpack NAMD

Change into your build directory:

cd $BUILD_DIR

Download and unpack the source files for NAMD, using:

wget http://www.ks.uiuc.edu/Research/namd/2.12/download/832164/NAMD_2.12_Source.tar.gz
tar -xf NAMD_2.12_Source.tar.gz

Build and install NAMD with Arm Compiler for HPC

Reminder

This recipe for building NAMD requires you to have previously built and installed Charm++ using the instructions provided in this tutorial.

If you have not already, setup the variables BUILD_DIR and INSTALL_DIR, using:

BUILD_DIR=~/NAMD/build
INSTALL_DIR=~/NAMD/install

To build NAMD:

  1. Change into the NAMD_2.12_Source directory, using:

    cd ./NAMD_2.12_Source
  2. Generate an armclang architecture file based on the existing Linux-ARM64-g++.arch file. To generate this file, you need to know the location of the Charm++ build directory NAMD_CHARM_DIR, and the architecture used for the Charm++ build CHARMARCH.

    For example, if Charm++ has been built and installed into ${INSTALL_DIR}/charm680, as described above:

    export CHARMARCH=multicore-linux-aarch64
    export NAMD_CHARM_DIR=${INSTALL_DIR}/charm680

    Copy the Linux-ARM64-g++.arch file, whilst renaming it to Linux-ARM64-armclang.arch using the command:

    cp arch/Linux-ARM64-g++.arch arch/Linux-ARM64-armclang.arch

    and configure this file using:

    sed -i "s|CHARMBASE.*|CHARMBASE = ${NAMD_CHARM_DIR}/|g" Make.charm
    sed -i "s|^CHARMARCH =.*|CHARMARCH = $CHARMARCH|g" arch/Linux-ARM64-armclang.arch
    sed -i "s|^FLOATOPTS =.*|FLOATOPTS = -O3 -fomit-frame-pointer ${WARN} ${TUNE}|g" arch/Linux-ARM64-armclang.arch
    sed -i "s|^CC = gcc|CC = $CC|g" arch/Linux-ARM64-armclang.arch
    sed -i "s|^CXX = g++|CXX = $CXX |g" arch/Linux-ARM64-armclang.arch
  3. NAMD's FFT configuration needs to be set to link to the FFTW interface of the Arm Performance Libraries. Ensure that ARMPL_DIR is set to the location of the installed library, and make a new FFT config file based on the existing x86 one, using:

    cp arch/Linux-x86_64.fftw3 arch/Linux-ARM64.fftw3

    and configure this file using:

    sed -i "s|^FFTDIR=.*|FFTDIR=$ARMPL_DIR|g" arch/Linux-ARM64.fftw3
    sed -i "s|^FFTINCL=.*|FFTINCL=-I$ARMPL_DIR/include|g" arch/Linux-ARM64.fftw3
    sed -i "s|^FFTLIB=.*|FFTLIB=-L$ARMPL_DIR/lib -larmpl -lflang -lflangrti|g" arch/Linux-ARM64.fftw3
  4. Complete the configuration and build NAMD with Arm Compiler for HPC, using:

    ./config Linux-ARM64-armclang --with-fftw3 --without-tcl --charm-arch $CHARMARCH

    cd Linux-ARM64-armclang
    make -j
  5. Create symbolic links to the executables, using:

    cd $INSTALL_DIR
    ln -s $BUILD_DIR/NAMD_2.12_Source/Linux-ARM64-armclang/charmrun charmrun
    ln -s $BUILD_DIR/NAMD_2.12_Source/Linux-ARM64-armclang/namd2 namd2

Run a simple benchmark

The Apoa1 example is a standard NAMD cross-platform benchmark. For more information on the Apoa1 example, see the NAMD website.

To run the Apoa1 example:

  1. Download the Apoa1 example:

    wget http://www.ks.uiuc.edu/Research/namd/utilities/apoa1.tar.gz
  2. Unpack the example:

    tar -xf apoa1.tar.gz
  3. Edit the Apoa1 deck file apoa1.namd, which is located in the unpacked apoa1 directory, to:

    1. Define the full path of the output directory to print to.

    2. Disable the use of FFTW wisdom (the FFTW interface for Arm Performance Libraries does not generate or utilize the FFTW wisdom files).

    using:

    1. outputname /path/to/Apoa1_output_dir/
    2. FFTWEstimate yes
      FFTWUseWisdom no
  4. Configure and run the example, using:

    NP=16
    ${INSTALL_DIR}/namd2 +p${NP} apoa1/apoa1.namd +setcpuaffinity

    Note: Set the number of processors according to your own system availability. In this example, we have run on 16 cores (NP=16).

More resources

For more information on NAMD, visit the NAMD webpage.
For more information on Arm Compiler for HPC, visit the Arm Compiler for HPC page.
For more porting and tuning guides, visit our Porting and Tuning page.