Skip to content

Commit

Permalink
feat: parallel execution chapter (#173)
Browse files Browse the repository at this point in the history
* feat: first two dummy slides to start the chapter

* fix: updated date

* feat: added option to create Handout background. Would be nice to enable it automatically when rendering a handout version

* fix: boundary fix for the n-th time - peril of mergers

* feat: introducing threading

* feat: update to copy script

* feat: immediate install of conda, without reliance on micromamba or miniconda due to libmamba in conda

* feat: added mpi example code

* feat: added 2nd version of copy script

* feat: added example Snakefile for MPI runs

* fix: removed mpi example copy

* fix: mpi example under solutions

* feat: finished MPI example setup - need generalization for different clusters

* feat: added MPI intro

* fix: syntax
  • Loading branch information
cmeesters authored Jan 28, 2025
1 parent 073eb60 commit 7d4fccc
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/config_Mainz_NHR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ layout:
course:
# sets the slides aspectratio (if outcommented, the default is 43=4:3)
aspectratio: 1609 # - 169 = 16:9
date: "23.-27. September 2024" # maybe: "\today"
date: "29.-30. January 2025" # maybe: "\today"
#title: "" # specifiy your title here, else a default is used.
#subtitle: "" # specifiy your subtitle here, else a default is used.
question: "yes" # if set (to any value) the question slide will be shown
Expand Down
Binary file added images/humor/DALLE_runners.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion render
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def find_and_replace_sections(boundaries, section_estimate, fname):
# first render minitoc
if minitocline:
lower = max((section_estimate - 2), 1) # lower boundary not lower than 1
upper = min(
upper = max(
(section_estimate + 3), boundaries["upper"]
) # upper boundary not higher then upper boundary ;-)
sections = f"{lower}-{upper}"
Expand Down
17 changes: 17 additions & 0 deletions setup_creators/copy_script_mogonNHR.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# This script is used to teach on the cluster "Mogon II"

CLUSTER_ALIAS="mogon_NHR_nox" # nox stands for "no X11 forwarding"
BASEPATH="/lustre/project/nhr-workflow/tutorial" # repeated used

# creating remote directory:
ssh ${CLUSTER_ALIAS} "mkdir -p ${BASEPATH}"

scp condarc_mogon "${CLUSTER_ALIAS}:${BASEPATH}/condarc"
scp get_tutorial.sh "${CLUSTER_ALIAS}:${BASEPATH}/get_tutorial.sh"
scp install_micromamba.sh "${CLUSTER_ALIAS}:${BASEPATH}/install_conda.sh"
scp environment.yaml "${CLUSTER_ALIAS}:${BASEPATH}/environment.yaml"

rsync -rtlv --chmod=D755 "tutorial" "${CLUSTER_ALIAS}:${BASEPATH}"
rsync -rtlv --chmod=D755 "solutions" "${CLUSTER_ALIAS}:/lustre/project/nhr-worfklow"
7 changes: 7 additions & 0 deletions setup_creators/install_conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh

bash Miniforge3-Linux-x86_64.sh

rm Miniforge3-Linux-x86_64.sh
24 changes: 24 additions & 0 deletions setup_creators/solutions/mpi_example/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
localrules: all, clean

rule all:
input: "pi.calc"

rule clean:
shell: "rm -f pi.calc pi_MPI *log"

rule compile:
input: "pi_MPI.c"
output: temp("pi_MPI")
log: "compile.log"
envmodules: "mpi/OpenMPI/4.1.5-GCC-12.3.0"
shell:
"mpicc -o {output} {input} 2> {log}"

rule calc_pi:
input: "pi_MPI"
output: "pi.calc"
log: "calc_pi.log"
resources:
mpi: "srun"
envmodules: "mpi/OpenMPI/4.1.5-GCC-12.3.0"
shell: "{resources.mpi} ./{input} > {output} 2> {log}"
61 changes: 61 additions & 0 deletions setup_creators/solutions/mpi_example/pi_MPI.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <stdio.h>
#include <math.h>
#include "stdlib.h"
#include "mpi.h"


double f(double x){
return ( 4.0/(1.0 + x*x) );
}


int main(int argc,char *argv[])
{

int myrank, size;

MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

long long int i, n;
double PI25DT = 3.141592653589793238462643;
double mypi, pi, h, mysum, x;



/* Argument handling from command line */
if( 2 == argc ){
n = atoll(argv[1]);
}else{
if( 0 == myrank ){
n = 10000000;
printf("Too many or no argument given; using n = %d instead.\n", n);
}
}


MPI_Bcast(&n, 1, MPI_LONG_LONG_INT, 0, MPI_COMM_WORLD);

h = 1.0/( (double)n );
mysum = 0.0;

for(i = myrank+1 ; i <= n ; i += size){
x = h*((double)i - 0.5);
mysum = mysum + f(x);
}

mypi = h*mysum;

MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

/* Output result if myrank==0 */
if( 0 == myrank ){
printf("\nUsing %d processes and the value n = %d.\n",size,n);
printf("Calculated pi: %.16f, with error %.16f\n\n", pi, fabs(pi - PI25DT));
}

MPI_Finalize();
return 0;
}

11 changes: 11 additions & 0 deletions slides/Snakemake_HPC_User_Creator_Combi.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@

\subtitle{<+++ if course.subtitle is defined +++><++course.subtitle++><+++else+++>Programming and Deployment<+++endif+++> - <++course.edition++>}


%\usepackage{background}
%\backgroundsetup{
% placement=center,
% angle=30,
% scale=1,
% contents={\footnodesize Handout from Snakemake Teaching Alliance by <++instructor.name++>},
% opacity=1
%}
%\setbeamertemplate{background}{\BgMaterial}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
Expand Down
Loading

1 comment on commit 7d4fccc

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts

Please sign in to comment.