Rocky R Prime

From NIMBioS

Insert example here

Prime Number example code

R serial script

library(foreach)
registerDoSeq()

library(doParallel)

registerDoParallel(40)

R parallel script

Naive version

library(foreach)
library(doParallel)

registerDoParallel(40)

Only check numbers ending in 1, 3, 7 and 9

library(foreach)
library(doParallel)

registerDoParallel(40)

Slurm submission script

#!/bin/bash
#SBATCH --job-name=R_PRIME        ### Job Name
#SBATCH --output=R_prime_%j.out   ### File in which to store job output
#SBATCH --time=00:10:00           ### Wall clock time limit in Days-HH:MM:SS
#SBATCH --nodes=1                 ### Node count required for the job
#SBATCH --ntasks-per-node=1       ### Number of tasks to be launched per Node
#SBATCH --mem-per-cpu=2G

#SBATCH --cpus-per-task=40

module load R/4.2.1-foss-2022a 
date
R --version

time Rscript R_prime_serial.R
date
time Rscript R_prime_parallel.R
date
time Rscript R_prime_parallel_fast.R
date

Running the Prime Number example

Uploading the code

The simple way to see this code is to clone the github repository:

[[ -e ~/git ]]  || mkdir ~/git  # Auto-create git subdirectory
cd ~/git                        # switch to git subdirectory
[[ -e r_prime_cluster ]] || git clone #GITHUB REPO URL
cd r_prime_cluster

Sanity check:

cat BLAH

Submitting the script

sbatch R-prime.srun

Looking at the results

Check the job queue, wait for job completion

squeue

Check log file:

ls -l R_prime_*.out

# just look at the latest output log
cat $( ls -t R_prime_*.out | head -n 1)

Check results file:

# Quick hash check verifying prime number sets are identical
md5sum $( ls -t R_prime_*.txt | head -n 3)