Run OpenFOAM codes on Curnagl
Script to run OpenFOAM code
You are using OpenFOAM on your computer and you need more ressources. Let’s go on Curnagl!
OpenFOAM is usually using MPI. Here is a bash script to run your parallelized OpenFOAM code. NTASKS should be replaced by the number of processors you want to use into your OpenFOAM code. It is good practice to put your OpenFOAM code in a bash file instead of calling OpenFOAM commands right into the sbatch file.
For instance, create openfoam.sh
in which you call your OpenFOAM code (replace commands with yours):
!/bin/bash
# First command
decomposepar ...
# Second command, if you are using a parallel command, CALL IT WITH SRUN COMMAND
srun snappyHexMesh -parallel ...
Then, create a sbatch file to run your OpenFOAM bash file on Curnagl:
#!/bin/bash -l
#SBATCH --job-name openfoam
#SBATCH --output openfoam.out
#SBATCH --partition cpu
#SBATCH --nodes 1
#SBATCH --ntasks NTASKS
#SBATCH --cpus-per-task 1
#SBATCH --mem 8G
#SBATCH --time 00:30:00
#SBATCH --export NONE
module purge
module load gcc/10.4.0 mvapich2/2.3.7 openfoam/2206
export SLURM_EXPORT_ENV=ALL
# RUN YOUR BASH OPENFOAM CODE HERE
bash ./openfoam.sh
Please note that running your parallelized OpenFOAM code should not be performed via mpirun
but srun
. For a complete MPI overview on Curnagl, please refer to compiling and running MPI codes wiki.
How do I transfer my OpenFOAM code to Curnagl ?
You can upload your OpenFOAM code thanks to FileZilla or copy and paste data to the cluster thanks to the scp
command.
Example: I want to copy test.py to Curnagl. I run the following command:
scp test.py <username>@curnagl.dcsr.unil.ch:/YOUR_PATH_ON_CURNAGL
Where YOUR_PATH_ON_CURNAGL
is something like /users/username/work/my_folder
.
In these commands, do not forget to change <username>
with yours.
This transfer can be done for any file type: .py, .csv, .h, images...
To copy a folder, use the command scp -r
.
For more details, refer to transfer files to/from Curnagl wiki.