Updated 2023-03-31
Running Eigen on the Cluster¶
Overview¶
- Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.
- This guide will cover how to run Eigen on the Cluster.
- The example used in this guide comes from this link.
Summary¶
- Load the
eigen/3.4.0
module. - You can now include any of the headers found in Eigen with
#include <Eigen/<Header>>
in your C++ files. - Compile and run your C++ program normally.
Walkthrough: Run Eigen on the Cluster¶
- This walkthrough will run a C++ script that makes Eigen print out its version.
- The
C++ script
can be found here SBATCH
script can be found here- You can transfer the files to your account on the cluster to follow along. The file transfer guide may be helpful.
Part 1: The SBATCH Script¶
#!/bin/bash
#SBATCH -JeigenTest
#SBATCH -A [Account]
#SBATCH -N1 --ntasks-per-node=2
#SBATCH --mem-per-cpu=2G
#SBATCH -t3
#SBATCH -qinferno
#SBATCH -oReport-%j.out
cd $SLURM_SUBMIT_DIR
module load eigen/3.4.0
g++ eigenTest.cc
./a.out
- The #SBATCH directives are standard, requesting just 3 minutes of walltime and 1 node with 2 cores. More on #SBATCH directives can be found in the Using Slurm on Phoenix Guide
$SLURM_SUBMIT_DIR
is simply a variable that represents the directory you submit the SBATCH script from.- Output Files will also show up in this dir as well
module load eigen/3.4.0
loads the 3.4.0 version of Eigen. To see what Eigen versions are available, runmodule spider eigen
, and load the one you want. The other module are dependencies that must be loaded before Eigen is loaded.g++ eigenTest.cc
compiles the C++ program.p./a.out
runs the C++ program.
Part 2: Submit Job and Check Status¶
- Be sure to change to the directory that contains the
SBATCH
Script - Submit as normal, with
<sbatch scriptname.sbatch>
. In this casesbatch eigen.sbatch
- Check job status with
squeue --job <jobID>
, replacing with the jobid returned after running sbatch - You can delete the job with
scancel <jobID>
, replacing with the jobid returned after running sbatch
Part 3: Collecting Results¶
- In the directory where you submitted the
SBATCH
script, you should see aReport-<jobID>.out
file, which contains the results of the job, aneigenTest.cc
file which contains the C++ code, and ana.out
executable. Use catReport-<jobID>.out
or open the file in a text editor to take a look. - Report-
.out should look like this:
---------------------------------------
Begin Slurm Prolog: Dec-01-2022 00:41:40
Job ID: 130804
User ID: svangala3
Account: phx-pace-staff
Job name: eigenTest
Partition: cpu-small
QOS: inferno
---------------------------------------
Eigen version : 4 . 0
---------------------------------------
Begin Slurm Epilog: Dec-01-2022 00:42:01
Job ID: 130804
Array Job ID: _4294967294
User ID: svangala3
Account: phx-pace-staff
Job name: eigenTest
Resources: cpu=2,mem=4G,node=1
Rsrc Used: cput=00:00:42,vmem=13132K,walltime=00:00:21,mem=0,energy_used=0
Partition: cpu-small
QOS: inferno
Nodes: atl1-1-02-004-15-1
---------------------------------------
- After the result files are produced, you can move the files off the cluster, refer to the file transfer guide for help.
- Congratulations! You successfully ran a C++ Program using Eigen on the cluster.