From 3b1335b3f98aed606ace06b0a7535d848ba23e49 Mon Sep 17 00:00:00 2001
From: Andreas Herten <a.herten@fz-juelich.de>
Date: Sat, 10 Jun 2023 20:23:25 +0200
Subject: [PATCH] Some reshuffling and documentation

Revamp how things are compiled and move systemname to name of executable; make JUWELS the default and also add instructions for JUWELS
---
 01-MSA-hello-world/Makefile          | 10 +++++++---
 01-MSA-hello-world/README.md         | 18 ++++++++++++++++++
 01-MSA-hello-world/compile.sh        | 13 +++++++++++++
 01-MSA-hello-world/compile_all.sh    |  7 -------
 01-MSA-hello-world/job_msa_jureca.sh |  2 +-
 01-MSA-hello-world/job_msa_juwels.sh |  2 +-
 01-MSA-hello-world/mpi_hello_world.c |  2 +-
 7 files changed, 41 insertions(+), 13 deletions(-)
 create mode 100644 01-MSA-hello-world/README.md
 create mode 100755 01-MSA-hello-world/compile.sh
 delete mode 100755 01-MSA-hello-world/compile_all.sh

diff --git a/01-MSA-hello-world/Makefile b/01-MSA-hello-world/Makefile
index bd8251c..9921395 100644
--- a/01-MSA-hello-world/Makefile
+++ b/01-MSA-hello-world/Makefile
@@ -1,10 +1,14 @@
-EXECS=mpi_hello_world.out
+SYS:=none
+_SYS=$(addprefix .,$(SYS))
 MPICC=mpicc
 
+EXECS=mpi_hello_world$(_SYS).out
+
+.PHONY: all clean
 all: ${EXECS}
 
-mpi_hello_world.out: mpi_hello_world.c
-	${MPICC} -o mpi_hello_world.out mpi_hello_world.c
+mpi_hello_world$(_SYS).out: mpi_hello_world.c
+	${MPICC} -o $@ $<
 
 clean:
 	rm ${EXECS} *.out || true
diff --git a/01-MSA-hello-world/README.md b/01-MSA-hello-world/README.md
new file mode 100644
index 0000000..5c92a0b
--- /dev/null
+++ b/01-MSA-hello-world/README.md
@@ -0,0 +1,18 @@
+# MSA Hello World
+
+In this simple example, the Slurm heterogeneous job functionality is used to launch a job between JUWELS Cluster and Booster.
+
+Execute the following on JUWELS Booster
+
+```bash
+bash compile.sh
+```
+
+Execute the following on JUWELS Cluster
+
+```bash
+bash compile.sh
+sbatch job_msa_juwels.sh
+```
+
+Monitor your job with `squeue --me`. When it ran through successfully, have a look at the output in `slurm-out.N`, with `N` being your job number.
\ No newline at end of file
diff --git a/01-MSA-hello-world/compile.sh b/01-MSA-hello-world/compile.sh
new file mode 100755
index 0000000..78e3228
--- /dev/null
+++ b/01-MSA-hello-world/compile.sh
@@ -0,0 +1,13 @@
+if [[ "$SYSTEMNAME" == "juwelsbooster" ]]; then
+	echo "Building for $SYSTEMNAME"
+	ml GCC ParaStationMPI
+	make SYS=$SYSTEMNAME
+elif [[ "$SYSTEMNAME" == "juwels" ]]; then
+	echo "Building for $SYSTEMNAME"
+	ml GCC ParaStationMPI
+	make SYS=$SYSTEMNAME
+else
+	echo "The system $SYSTEMNAME is not supported!"
+	echo "Please load a capable MPI and compile the executables on each system with"
+	echo "make SYS=PARTIONNAME"
+fi
\ No newline at end of file
diff --git a/01-MSA-hello-world/compile_all.sh b/01-MSA-hello-world/compile_all.sh
deleted file mode 100755
index 5fb05fb..0000000
--- a/01-MSA-hello-world/compile_all.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-ml GCC ParaStationMPI
-make
-mv mpi_hello_world.out mpi_hello_world_cluster.out
-
-ml GCC ParaStationMPI
-make
-mv mpi_hello_world.out mpi_hello_world_booster.out
diff --git a/01-MSA-hello-world/job_msa_jureca.sh b/01-MSA-hello-world/job_msa_jureca.sh
index 641e74b..7e1323e 100644
--- a/01-MSA-hello-world/job_msa_jureca.sh
+++ b/01-MSA-hello-world/job_msa_jureca.sh
@@ -11,4 +11,4 @@
 #SBATCH --ntasks-per-node=1
 #SBATCH --partition=dc-gpu-devel
 
-srun xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world_cluster.out : xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world_booster.out
+srun xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world.jureca.out : xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world.jureca.out
diff --git a/01-MSA-hello-world/job_msa_juwels.sh b/01-MSA-hello-world/job_msa_juwels.sh
index d362ad1..5840bd7 100644
--- a/01-MSA-hello-world/job_msa_juwels.sh
+++ b/01-MSA-hello-world/job_msa_juwels.sh
@@ -11,4 +11,4 @@
 #SBATCH --ntasks-per-node=1
 #SBATCH --partition=develbooster
 
-srun xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world_cluster.out : xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world_booster.out
+srun xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world.juwels.out : xenv -P -L GCC -L ParaStationMPI ./mpi_hello_world.juwelsbooster.out
diff --git a/01-MSA-hello-world/mpi_hello_world.c b/01-MSA-hello-world/mpi_hello_world.c
index 35db8ad..2c2a1bd 100644
--- a/01-MSA-hello-world/mpi_hello_world.c
+++ b/01-MSA-hello-world/mpi_hello_world.c
@@ -13,7 +13,7 @@ int main(int argc, char** argv) {
     int world_rank;
     MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
 
-    // Get the name of the processor
+    // Get the name of the processor, which is the hostname
     char processor_name[MPI_MAX_PROCESSOR_NAME];
     int name_len;
     MPI_Get_processor_name(processor_name, &name_len);
-- 
GitLab