diff --git a/02-MSA-hello-world-gpu/Makefile b/02-MSA-hello-world-gpu/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..c51d61d957d0decf1cb391bed05c7a34ddaac7e3 --- /dev/null +++ b/02-MSA-hello-world-gpu/Makefile @@ -0,0 +1,28 @@ +CUCOMP = nvcc +CUFLAGS = -arch=sm_80 + +ifdef EBROOTOPENMPI +MPI_HOME+=$(EBROOTOPENMPI) +endif +ifdef EBROOTPSMPI +MPI_HOME+=$(EBROOTPSMPI) +endif + +INCLUDES = -I$(MPI_HOME)/include +LIBRARIES = -L$(MPI_HOME)/lib -lmpi + +all: hello.cpu.out hello.gpu.out + +hello.cpu.out: hello-world.c + mpicc $< -o $@ + +hello.gpu.out: hello.gpu.o + $(CUCOMP) $(CUFLAGS) $(LIBRARIES) $< -o $@ + +hello.gpu.o: hello-world.cu + $(CUCOMP) $(CUFLAGS) $(INCLUDES) -c $< -o $@ + +.PHONY: clean + +clean: + rm -f hello.cpu.out hello.gpu.out *.o \ No newline at end of file diff --git a/02-MSA-hello-world-gpu/hello-world.c b/02-MSA-hello-world-gpu/hello-world.c new file mode 100644 index 0000000000000000000000000000000000000000..9d501bc9ff1e73e01ef888629f768d6d778af464 --- /dev/null +++ b/02-MSA-hello-world-gpu/hello-world.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include <mpi.h> + +int main(int argc, char** argv){ + MPI_Init(&argc, &argv); + + int size; + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Status stat; + + if(size != 2){ + if(rank == 0){ + printf("This program requires exactly 2 MPI ranks, but you are attempting to use %d! Exiting...\n", size); + } + MPI_Finalize(); + exit(0); + } + int tag = 10; + + const char *payload = "world!"; + + if (rank == 0) { + MPI_Send(payload, 6, MPI_CHAR, 1, tag, MPI_COMM_WORLD); + } + + printf("\n"); + + return 0; +} diff --git a/02-MSA-hello-world-gpu/hello-world.cu b/02-MSA-hello-world-gpu/hello-world.cu new file mode 100644 index 0000000000000000000000000000000000000000..da1b592e0c32c8165dc99c8d102bc4b3767aa902 --- /dev/null +++ b/02-MSA-hello-world-gpu/hello-world.cu @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <stdlib.h> +#include <mpi.h> + +#define CUDA_RT_CALL(call) \ + { \ + cudaError_t cudaStatus = call; \ + if (cudaSuccess != cudaStatus) \ + fprintf(stderr, \ + "ERROR: CUDA RT call \"%s\" in line %d of file %s failed " \ + "with " \ + "%s (%d).\n", \ + #call, __LINE__, __FILE__, cudaGetErrorString(cudaStatus), cudaStatus); \ + } +__global__ void hello(const char * payload){ + int i = blockDim.x * blockIdx.x + threadIdx.x; + + if (i == 0) { + printf("%s", payload); + } +} + +int main(int argc, char** argv){ + MPI_Init(&argc, &argv); + + int size; + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Status stat; + + if(size != 2){ + if(rank == 0){ + printf("This program requires exactly 2 MPI ranks, but you are attempting to use %d! Exiting...\n", size); + } + MPI_Finalize(); + exit(0); + } + int tag = 10; + + const char *payload = "hello "; + + char * d_payload; + CUDA_RT_CALL( cudaMalloc((void**)&d_payload, 6) ); + CUDA_RT_CALL( cudaMemcpy(d_payload, payload, 6, cudaMemcpyHostToDevice) ); + + hello<<<1, 1>>>(d_payload); + + CUDA_RT_CALL( cudaPeekAtLastError() ); + CUDA_RT_CALL( cudaDeviceSynchronize() ); + + if (rank == 1) { + MPI_Recv(d_payload, 6, MPI_CHAR, 0, tag, MPI_COMM_WORLD, &stat); + } + + hello<<<1, 1>>>(d_payload); + + CUDA_RT_CALL( cudaPeekAtLastError() ); + CUDA_RT_CALL( cudaDeviceSynchronize() ); + + printf("\n"); + + return 0; +} diff --git a/02-MSA-hello-world-gpu/job_msa_juwels.sh b/02-MSA-hello-world-gpu/job_msa_juwels.sh new file mode 100644 index 0000000000000000000000000000000000000000..32bd3696ee2e173aaa8207ee2d0c3466e2ffafc6 --- /dev/null +++ b/02-MSA-hello-world-gpu/job_msa_juwels.sh @@ -0,0 +1,14 @@ +#!/bin/bash -x +#SBATCH --account=training2317 +#SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 +#SBATCH --output=slurm-out.%j +#SBATCH --error=slurm-err.%j +#SBATCH --time=00:15:00 +#SBATCH --partition=devel +#SBATCH hetjob +#SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 +#SBATCH --partition=develbooster + +srun xenv -P -L GCC -L ParaStationMPI ./hello.cpu.out : xenv -P -L GCC -L ParaStationMPI -L MPI-settings/CUDA ./hello.gpu.out diff --git a/02-MSA-ping-pong/Makefile b/03-MSA-ping-pong/Makefile similarity index 100% rename from 02-MSA-ping-pong/Makefile rename to 03-MSA-ping-pong/Makefile diff --git a/02-MSA-ping-pong/README.md b/03-MSA-ping-pong/README.md similarity index 100% rename from 02-MSA-ping-pong/README.md rename to 03-MSA-ping-pong/README.md diff --git a/02-MSA-ping-pong/compile.sh b/03-MSA-ping-pong/compile.sh similarity index 100% rename from 02-MSA-ping-pong/compile.sh rename to 03-MSA-ping-pong/compile.sh diff --git a/02-MSA-ping-pong/job_msa_jureca.sh b/03-MSA-ping-pong/job_msa_jureca.sh similarity index 100% rename from 02-MSA-ping-pong/job_msa_jureca.sh rename to 03-MSA-ping-pong/job_msa_jureca.sh diff --git a/02-MSA-ping-pong/job_msa_juwels.sh b/03-MSA-ping-pong/job_msa_juwels.sh similarity index 100% rename from 02-MSA-ping-pong/job_msa_juwels.sh rename to 03-MSA-ping-pong/job_msa_juwels.sh diff --git a/02-MSA-ping-pong/ping-pong.c b/03-MSA-ping-pong/ping-pong.c similarity index 100% rename from 02-MSA-ping-pong/ping-pong.c rename to 03-MSA-ping-pong/ping-pong.c diff --git a/02-MSA-ping-pong/ping-pong.cu b/03-MSA-ping-pong/ping-pong.cu similarity index 100% rename from 02-MSA-ping-pong/ping-pong.cu rename to 03-MSA-ping-pong/ping-pong.cu