#!/bin/bash

#SBATCH --job-name=Jacobi-OpenACC
#SBATCH --account=IscrC_SCGPCT
#SBATCH --partition=boost_usr_prod
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1
#SBATCH --gres=gpu:1
#SBATCH --output=Jacobi-OpenACC-%j.out
#SBATCH --error=Jacobi-OpenACC-%j.err
#SBATCH --time=0:10:00

# module purge
# module load scorep/8.1--openmpi--4.1.4--nvhpc--23.1-cuda-11.8
# module load openmpi/4.1.6--nvhpc--23.11 nvhpc/23.11
module load nvhpc/23.11

SCOREP= #"scorep --user"
CC = "nvcc"
OPT = 
#OPT="-g -mp=gpu -gpu=ccnative,debug,lineinfo -target=gpu -Minfo=all -v"
#LIB="-L/leonardo/prod/opt/libraries/openmpi/4.1.6/nvhpc--24.3/lib/ -lmpi -lm"
LIB = "-lm"

COMPUTE_SANITIZER="compute-sanitizer --generate-coredump "

### script path
SCRIPT_PATH=/leonardo/home/userexternal/dgoz0000/test/openmp-gpu/script

################## source list (C CPP)
# on Leonardo compile the CPP code
SOURCE_CODE=( CPP )

#################################################################################
#################################################################################
if [ ! -d ${SCRIPT_PATH} ]
then
    printf "\n\t SCRIPT_PATH invalid... aborting..."
    exit 0
fi

printf "\n\t SLURM:"
printf "\n\t\t NODES       : ${SLURM_NNODES} (${SLURM_NODELIST})"
printf "\n\t\t NTASKS      : ${SLURM_NTASKS}"
printf "\n\t\t CPU-PER-TASK: ${SLURM_CPUS_PER_TASK}"
printf "\n\t\t GPUs        : ${SLURM_JOB_GPUS}"
printf "\n\n"

# working directory
WORKDIR=${PWD}

# compile the sources
source ${SCRIPT_PATH}/compile_OpenMP-GPU.sh

# run the executable getting the profile using score-p
source ${SCRIPT_PATH}/run_OpenMP-GPU.sh

printf "\n\t End of game!!! \n"
