forked from carpentries-incubator/hpc-intro
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removed uneeded second R Script * Rename test script to 'sum_matrix' to avoid confusion with job arrays. Also made script work with MPI. * make naming consistant.
- Loading branch information
1 parent
63a2fe8
commit cba1c13
Showing
20 changed files
with
137 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash -e | ||
|
||
#SBATCH --job-name dmp_job | ||
#SBATCH --output %x.out | ||
#SBATCH --mem-per-cpu 500 | ||
#SBATCH --ntasks 4 | ||
|
||
module purge | ||
module load R/4.3.1-gimkl-2022a | ||
srun Rscript sum_matrix.r | ||
echo "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash -e | ||
|
||
module purge | ||
module load R/4.3.1-gimkl-2022a | ||
Rscript sum_matrix.r | ||
echo "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash -e | ||
|
||
#SBATCH --job-name example_job | ||
#SBATCH --account nesi99991 | ||
#SBATCH --mem 300M | ||
#SBATCH --time 00:15:00 | ||
|
||
module purge | ||
module load R/4.3.1-gimkl-2022a | ||
Rscript sum_matrix.r | ||
echo "Done!" |
4 changes: 2 additions & 2 deletions
4
_includes/example_scripts/example-job.sl.2 → _includes/example_scripts/example_job.sl.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
#!/bin/bash -e | ||
|
||
#SBATCH --job-name my_job | ||
#SBATCH --job-name example_job | ||
#SBATCH --account nesi99991 | ||
#SBATCH --mem 300M | ||
#SBATCH --time 00:15:00 | ||
#SBATCH --cpus-per-task 4 | ||
|
||
module purge | ||
module load R/4.3.1-gimkl-2022a | ||
{{ site.example.shell }} {{ site.example.script }} | ||
Rscript sum_matrix.r | ||
echo "Done!" |
4 changes: 2 additions & 2 deletions
4
_includes/example_scripts/example-job.sl.3 → _includes/example_scripts/example_job.sl.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
#!/bin/bash -e | ||
|
||
#SBATCH --job-name my_job | ||
#SBATCH --job-name example_job | ||
#SBATCH --account nesi99991 | ||
#SBATCH --mem 600M | ||
#SBATCH --time 00:10:00 | ||
#SBATCH --cpus-per-task 4 | ||
|
||
module purge | ||
module load R/4.3.1-gimkl-2022a | ||
{{ site.example.shell }} {{ site.example.script }} | ||
Rscript sum_matrix.r | ||
echo "Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
#!/bin/bash -e | ||
|
||
#SBATCH --job-name smp_job | ||
#SBATCH --job-name smp | ||
#SBATCH --account nesi99991 | ||
#SBATCH --output %x.out | ||
#SBATCH --mem-per-cpu 500 | ||
#SBATCH --cpus-per-task 8 | ||
|
||
echo "I am task #${SLURM_PROCID} running on node '$(hostname)' with $(nproc) CPUs" | ||
module purge | ||
module load R/4.3.1-gimkl-2022a | ||
Rscript sum_matrix.r | ||
echo "Done!" |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
|
||
# Function for shared memory execution | ||
doTask <- function(size_x, size_y, seed, print_progress){ | ||
suppressPackageStartupMessages(library(doParallel)) | ||
|
||
message(sprintf("Summing [ %e x %e ] matrix, seed = '%i'",size_x,size_y, seed)) | ||
message(sprintf("Running on '%s' with %i CPU(s).", Sys.info()["nodename"], num_cpus)) | ||
|
||
set.seed(seed) | ||
|
||
registerDoParallel((num_cpus/2)) | ||
|
||
results_all <- foreach(z=0:size_x) %dopar% { | ||
percent_complete= z*100/size_x | ||
if (print_progress && percent_complete%%1==0){ | ||
message(sprintf(" %i%% done...\r", percent_complete)) | ||
} | ||
sum(rnorm(size_y)) | ||
} | ||
Reduce("+",results_all) | ||
} | ||
|
||
# 50 calculations, store the result in 'x' | ||
|
||
ntasks <- strtoi(Sys.getenv('SLURM_NTASKS', unset = "1")) | ||
seed <- strtoi(Sys.getenv('SLURM_ARRAY_TASK_ID', unset = "0")) | ||
num_cpus <- as.integer(strtoi(Sys.getenv('SLURM_CPUS_PER_TASK', unset = "1"))) | ||
|
||
size_x <-60000 # This on makes memorier | ||
size_y <-40000 # This one to make longer | ||
|
||
# Time = (size_x/n) * size_y + c | ||
# Mem = (size_x * n) * c1 + size_y * c2 | ||
|
||
print_progress <- TRUE | ||
# print_progress <- interactive() # Whether to print progress or not. | ||
|
||
#If more than 1 task, use doMPI | ||
if (ntasks > 1){ | ||
suppressPackageStartupMessages(library(doSNOW)) | ||
cl <- makeMPIcluster(outfile="") | ||
|
||
results_all <- foreach(z=1:ntasks) %dopar% { | ||
doTask(size_x, ceiling(size_y/ntasks), z+seed, print_progress) | ||
} | ||
|
||
results = Reduce("+",results_all) | ||
stopCluster(cl) | ||
message(sprintf("Sums to %f", results)) | ||
}else{ | ||
results = doTask(size_x, size_y, seed, print_progress) | ||
message(sprintf("Sums to %f", results)) | ||
} |