diff --git a/exercises/ex1/Makefile b/exercises/ex1/Makefile new file mode 100644 index 0000000..c6c1368 --- /dev/null +++ b/exercises/ex1/Makefile @@ -0,0 +1,17 @@ +F90=nvfortran +F90FLAGS=-cuda + +.PHONY: clean distclean + +all: hello_world.x + +hello_world.x: hello_world.f90 + +%.x: %.f90 + $(F90) $(F90FLAGS) $< -o $@ + +distclean: clean + rm *.x + +clean: + rm -f *.o *.mod diff --git a/exercises/ex1/hello_world.f90 b/exercises/ex1/hello_world.f90 new file mode 100644 index 0000000..17cd66a --- /dev/null +++ b/exercises/ex1/hello_world.f90 @@ -0,0 +1,30 @@ +module helloWorld + implicit none + +contains + + subroutine hello_world_cpu + write(*,*) 'hello world from CPU code' + end subroutine hello_world_cpu + + attributes(global) subroutine hello_world_cuda + write(*,*) 'hello world from CUDA code' + end subroutine hello_world_cuda + + attributes(global) subroutine hello_world_cuda_threads + write(*,*) 'hello world from thread', threadIdx%x + end subroutine hello_world_cuda_threads +end module helloWorld + +program testHelloWorld + use cudafor + use helloWorld + + implicit none + + integer :: istat + + call hello_world_cpu + call hello_world_cuda<<<1, 1>>> + istat = cudaDeviceSynchronize() +end program testHelloWorld diff --git a/exercises/ex1/script.sh b/exercises/ex1/script.sh new file mode 100644 index 0000000..a42041e --- /dev/null +++ b/exercises/ex1/script.sh @@ -0,0 +1,14 @@ +#!/bin/bash -l +#SBATCH --nodes=1 +#SBATCH --ntasks-per-node=1 +#SBATCH --ntasks-per-core=1 +#SBATCH --cpus-per-task=1 +#SBATCH --gres=gpu:1 +#SBATCH --reservation=spc-cuda-training-12.04 +#SBATCH --account=spc-cuda-training +#SBATCH --time=0:05:00 + +module load nvhpc + +srun -n 1 ./hello_world.x > output_hello_world +