From ecd80d442612633b72f24e2077dd048a2a4f4035 Mon Sep 17 00:00:00 2001
From: Andreas Herten <a.herten@fz-juelich.de>
Date: Sun, 11 Jun 2023 22:45:35 +0200
Subject: [PATCH] Minor tweaks and renamings

And also use the structure from Task 1
---
 02-MSA-ping-pong/Makefile          | 27 +++++++++++++++++----------
 02-MSA-ping-pong/README.md         | 18 ++++++++++++++++++
 02-MSA-ping-pong/compile.sh        | 11 +++++++++++
 02-MSA-ping-pong/compile_all.sh    |  2 --
 02-MSA-ping-pong/job_msa_juwels.sh |  4 ++--
 5 files changed, 48 insertions(+), 14 deletions(-)
 create mode 100644 02-MSA-ping-pong/README.md
 create mode 100755 02-MSA-ping-pong/compile.sh
 delete mode 100755 02-MSA-ping-pong/compile_all.sh

diff --git a/02-MSA-ping-pong/Makefile b/02-MSA-ping-pong/Makefile
index 0fbc367..f7233d2 100644
--- a/02-MSA-ping-pong/Makefile
+++ b/02-MSA-ping-pong/Makefile
@@ -1,22 +1,29 @@
 CUCOMP  = nvcc
 CUFLAGS = -arch=sm_80
 
-INCLUDES  = -I$(EBROOTOPENMPI)/include
-LIBRARIES = -L$(EBROOTOPENMPI)/lib -lmpi
+ifdef EBROOTOPENMPI
+MPI_HOME+=$(EBROOTOPENMPI)
+endif
+ifdef EBROOTPSMPI
+MPI_HOME+=$(EBROOTPSMPI)
+endif
 
-all: pp_cpu.out pp_cuda_aware.out
+INCLUDES  = -I$(MPI_HOME)/include
+LIBRARIES = -L$(MPI_HOME)/lib -lmpi
 
-pp_cpu.out: ping-pong.c
-	mpicc ping-pong.c -o pp_cpu.out
+all: ping-pong.cpu.out ping-pong.gpu.out
 
-pp_cuda_aware.out: ping-pong.o
-	$(CUCOMP) $(CUFLAGS) $(LIBRARIES) ping-pong.o -o pp_cuda_aware.out
+ping-pong.cpu.out: ping-pong.c
+	mpicc $< -o $@
 
-ping-pong.o: ping-pong.cu
-	$(CUCOMP) $(CUFLAGS) $(INCLUDES) -c ping-pong.cu
+ping-pong.gpu.out: ping-pong.gpu.o
+	$(CUCOMP) $(CUFLAGS) $(LIBRARIES) $< -o $@
+
+ping-pong.gpu.o: ping-pong.cu
+	$(CUCOMP) $(CUFLAGS) $(INCLUDES) -c $< -o $@
 
 .PHONY: clean
 
 clean:
-	rm -f pp_cpu.out pp_cuda_aware.out *.o
+	rm -f ping-pong.cpu.out ping-pong.gpu.out *.o
 
diff --git a/02-MSA-ping-pong/README.md b/02-MSA-ping-pong/README.md
new file mode 100644
index 0000000..2503027
--- /dev/null
+++ b/02-MSA-ping-pong/README.md
@@ -0,0 +1,18 @@
+# MSA CPU-GPU Ping Pong
+
+We extend the simple previous example to now use a heterogeneous job on a CPU and GPU with dedicated partitions. The two job components of the heterogeneous job send _ping pong_ messages to each other of increasing size.
+
+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/02-MSA-ping-pong/compile.sh b/02-MSA-ping-pong/compile.sh
new file mode 100755
index 0000000..302fa09
--- /dev/null
+++ b/02-MSA-ping-pong/compile.sh
@@ -0,0 +1,11 @@
+if [[ "$SYSTEMNAME" == "juwelsbooster" ]]; then
+	echo "Building GPU-aware version for $SYSTEMNAME"
+	ml GCC ParaStationMPI MPI-settings/CUDA
+	make ping-pong.gpu.out
+elif [[ "$SYSTEMNAME" == "juwels" ]]; then
+	echo "Building CPU version for $SYSTEMNAME"
+	ml GCC ParaStationMPI 
+	make ping-pong.cpu.out
+else
+	echo "The system $SYSTEMNAME is not supported!"
+fi
\ No newline at end of file
diff --git a/02-MSA-ping-pong/compile_all.sh b/02-MSA-ping-pong/compile_all.sh
deleted file mode 100755
index 1f677bb..0000000
--- a/02-MSA-ping-pong/compile_all.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-ml GCC OpenMPI MPI-settings/CUDA
-make all
diff --git a/02-MSA-ping-pong/job_msa_juwels.sh b/02-MSA-ping-pong/job_msa_juwels.sh
index 5e6f8bb..e6f2ba4 100644
--- a/02-MSA-ping-pong/job_msa_juwels.sh
+++ b/02-MSA-ping-pong/job_msa_juwels.sh
@@ -1,5 +1,5 @@
 #!/bin/bash -x
-#SBATCH --account=exalab
+#SBATCH --account=training2317
 #SBATCH --nodes=1
 #SBATCH --ntasks-per-node=1
 #SBATCH --output=slurm-out.%j
@@ -11,4 +11,4 @@
 #SBATCH --ntasks-per-node=1
 #SBATCH --partition=develbooster
 
-srun xenv -P -L GCC -L OpenMPI -L MPI-settings/CUDA ./pp_cpu.out : xenv -P -L GCC -L OpenMPI -L MPI-settings/CUDA ./pp_cuda_aware.out
+srun xenv -P -L GCC -L ParaStationMPI ./ping-pong.cpu.out : xenv -P -L GCC -L ParaStationMPI -L MPI-settings/CUDA ./ping-pong.gpu.out
-- 
GitLab