-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parallel execution chapter (#173)
* 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
Showing
9 changed files
with
444 additions
and
2 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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" |
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,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 |
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,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}" |
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,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; | ||
} | ||
|
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
Oops, something went wrong.
7d4fccc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Artifacts