Setting up OpenMX
Please refer to the OpenMX website for detailed documentation. The installation options will depend on your system architecture and available libraries.
Using GNU libraries
I used the following script to build OpenMX using GNU libraries:
scripts/openmx_gnu.sh
#!/bin/bash
# this script is not compatible with Bourne shell (sh), use bash instead:
# bash openmx_gnu.sh
# tested on ubuntu 24.04
# exit upon any command failure
set -e
OPENMX_VER="4.0"
DOWNLOAD_URL="https://www.openmx-square.org/openmx${OPENMX_VER}.tar.gz"
INSTALL_DIR="${HOME}/openmx${OPENMX_VER}"
NUM_PROCS=$(nproc)
BUILD_DIR=/tmp/_build_$(date +'%Y%m%d%H%M%S')
CWD=${PWD}
mkdir ${BUILD_DIR} && cd $_
sudo apt update && sudo apt upgrade -y
sudo apt install --no-install-recommends -y \
autoconf \
build-essential \
ca-certificates \
gfortran \
libblas3 \
libopenblas-dev \
libc6 \
libfftw3-dev \
libgcc-s1 \
liblapack-dev \
libopenmpi-dev \
libscalapack-openmpi-dev \
libelpa-dev \
wget
if ! [ -f /usr/lib/x86_64-linux-gnu/libscalapack.so ] ; then
if ! [ -h /usr/lib/x86_64-linux-gnu/libscalapack.so ] ; then
sudo ln -s /usr/lib/x86_64-linux-gnu/libscalapack-openmpi.so /usr/lib/x86_64-linux-gnu/libscalapack.so
fi
fi
wget ${DOWNLOAD_URL}
tar -xf openmx${OPENMX_VER}.tar.gz
rm openmx${OPENMX_VER}.tar.gz
cd openmx${OPENMX_VER}/source
# edit makefile
# to find specific paths try: apt search fftw3; dpkg -L libfftw3-dev; ompi_info
# CC = mpicc -O3 -ffast-math -fcommon -fopenmp
# FC = mpif90 -O3 -ffast-math -fallow-argument-mismatch -fopenmp
# LIB = -lfftw3 -lmpi -lmpi_mpifh -lscalapack -llapack -lblas -lgfortran
sed -i 's/^\s*CC\s*=.*/CC = mpicc -O3 -ffast-math -fcommon -fopenmp/' ${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile
sed -i '/^\s*MKLROOT/d' ${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile
sed -i 's/^\s*FC\s*=.*/FC = mpif90 -O3 -ffast-math -fallow-argument-mismatch -fopenmp/' ${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile
sed -i 's/^\s*LIB\s*=.*/LIB = -lfftw3 -lmpi -lmpi_mpifh -lscalapack -llapack -lblas -lgfortran/' ${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile
make all # have issues with parallel make
make install
if [ ! -d ${INSTALL_DIR} ]; then
mkdir -p ${INSTALL_DIR}
fi
cp -r ${BUILD_DIR}/openmx${OPENMX_VER}/* ${INSTALL_DIR}
rm -rf ${BUILD_DIR}
# run tests (calculations need to be launched from ${INSTALL_DIR}/work)
# cd ${INSTALL_DIR}/work
# mpirun -np ${NUM_PROCS} ./openmx -runtest -nt 1
cd ${CWD}
Using Intel libraries
Intel OneAPI libraries give better performance compared to GNU libraries.
scripts/openmx_intel.sh
#!/bin/bash
# this script is not compatible with Bourne shell (sh), use bash instead:
# bash openmx_intel.sh
# tested on ubuntu 24.04
# exit upon any command failure
set -e
OPENMX_VER="4.0"
DOWNLOAD_URL="https://www.openmx-square.org/openmx${OPENMX_VER}.tar.gz"
INSTALL_DIR="${HOME}/openmx${OPENMX_VER}"
NUM_PROCS=$(nproc)
ONEAPI_ROOT=/opt/intel-2025.3.1
BUILD_DIR=/tmp/_build_$(date +'%Y%m%d%H%M%S')
CWD=${PWD}
mkdir ${BUILD_DIR} && cd $_
# install oneapi deps
sudo apt update
sudo apt install -y --no-install-recommends \
ca-certificates \
gawk \
g++ \
gcc \
gfortran \
ncurses-term \
wget
# install oneapi
pkgs=(
"https://registrationcenter-download.intel.com/akdlm/IRC_NAS/233a8b7a-ec95-4e51-bc5f-9dcd4f0d1dc3/intel-onetbb-2022.3.1.402_offline.sh"
"https://registrationcenter-download.intel.com/akdlm/IRC_NAS/0d61d48a-4fe8-4cb2-bd9d-94d2c19c6227/intel-dpcpp-cpp-compiler-2025.3.2.26_offline.sh"
"https://registrationcenter-download.intel.com/akdlm/IRC_NAS/3e53d136-2870-4836-adb1-892b558fa34a/intel-fortran-compiler-2025.3.2.25_offline.sh"
"https://registrationcenter-download.intel.com/akdlm/IRC_NAS/c477188f-0ba1-4213-8945-22f16ebc8ecb/intel-oneccl-2021.17.2.6_offline.sh"
"https://registrationcenter-download.intel.com/akdlm/IRC_NAS/6a17080f-f0de-41b9-b587-52f92512c59a/intel-onemkl-2025.3.1.11_offline.sh"
)
for pkg in "${pkgs[@]}"; do
wget $pkg
sudo sh ./$( basename $pkg ) -a --silent --eula accept --install-dir $ONEAPI_ROOT
rm -f $( basename $pkg )
done
source ${ONEAPI_ROOT}/setvars.sh
wget ${DOWNLOAD_URL}
tar -xf openmx${OPENMX_VER}.tar.gz
rm openmx${OPENMX_VER}.tar.gz
cd openmx${OPENMX_VER}/source
# edit the makefile
# MKLROOT = /opt/intel-2025.3.1/mkl/2025.3
# CC = mpiicx -O3 -qopenmp -fcommon -Wno-error=implicit-function-declaration -ipo -I${MKLROOT}/include/fftw -I${MKLROOT}/include
# FC = mpiifx -O3 -qopenmp -ipo
# LIB = -L${MKLROOT}/lib/intel64 -lmkl_scalapack_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lifcore -lmkl_blacs_intelmpi_lp64 -liomp5 -lpthread -lm -ldl
sed -i "s|^[[:space:]]*MKLROOT[[:space:]]*=.*|MKLROOT = ${ONEAPI_ROOT}/mkl/2025.3|" "${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile"
sed -i 's|^[[:space:]]*CC[[:space:]]*=.*|CC = mpiicx -O3 -qopenmp -fcommon -Wno-error=implicit-function-declaration -ipo -I${MKLROOT}/include/fftw -I${MKLROOT}/include|' "${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile"
sed -i 's|^[[:space:]]*FC[[:space:]]*=.*|FC = mpiifx -O3 -qopenmp -ipo|' "${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile"
sed -i 's|^[[:space:]]*LIB[[:space:]]*=.*|LIB = -L${MKLROOT}/lib/intel64 -lmkl_scalapack_lp64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lifcore -lmkl_blacs_intelmpi_lp64 -liomp5 -lpthread -lm -ldl|' "${BUILD_DIR}/openmx${OPENMX_VER}/source/makefile"
make all
make install
if [ ! -d ${INSTALL_DIR} ]; then
mkdir -p ${INSTALL_DIR}
fi
cd ${CWD}
cp -r ${BUILD_DIR}/openmx${OPENMX_VER}/* ${INSTALL_DIR}
rm -rf ${BUILD_DIR}
# run tests (calculations need to be launched from ${INSTALL_DIR}/work)
# cd ${INSTALL_DIR}/work
# source ${ONEAPI_ROOT}/setvars.sh
# mpirun -np ${NUM_PROCS} ./openmx -runtest -nt 1
Verify installation
You can verify your installation by running the included tests:
cd openmx4.0/work
# specify number of OpenMP threads with `-nt` flag
mpirun -np 4 ./openmx -runtest -nt 1
Optionally you may add the openmx4.0/work to the PATH via ~/.bashrc.
export PATH="${INSTALL_DIR}/openmx4.0/work:$PATH"
You may compare CPU times with other machines.
Example PBS script
Here is a sample PBS job script for NUS HPC cluster:
scripts/job.pbs
#!/bin/bash
#PBS -q parallel12
#PBS -l select=2:ncpus=12:mpiprocs=12:mem=45GB
#PBS -j eo
#PBS -N openmx-test
source /etc/profile.d/rec_modules.sh
module load oneapi_2025.3.1
cd $PBS_O_WORKDIR;
np=$( cat ${PBS_NODEFILE} | wc -l );
mpirun -np $np -f ${PBS_NODEFILE} openmx input.txt > output.txt
Input files, Jupyter notebooks, and other source files used in this tutorial can be found in my GitHub repository: pranabdas/openmx.
References
- Read through the OpenMX manual for various details.
- OpenMX viewer can help you choose certain parameters for the input file e.g., basis configuration. You may also consult this reference table.
- SeeK-path tool can help you build the k-path.
- The
workdirectory under OpenMX installation contains lots of examples for your reference.