Skip to content

Commit

Permalink
minor formatting changes, removed Summit from GNUParallel and added A…
Browse files Browse the repository at this point in the history
…lpine
  • Loading branch information
LRFreeborn committed Dec 18, 2022
1 parent 1d827a6 commit e8999bf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
35 changes: 27 additions & 8 deletions docs/software/GNUParallel.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
## GNU Parallel

GNU Parallel is an effective tool for optimally using multiple cores and nodes on RMACC Summit to run lots of independent tasks without the need to learn OpenMP or MPI. This tutorial assumes user knowledge of Slurm jobs, shell scripting, and some Python.
GNU Parallel is an effective tool for optimally using multiple cores and
nodes on CURC clusters to run lots of independent tasks without the need
to learn
OpenMP or MPI. This tutorial assumes user knowledge of Slurm jobs, shell scripting, and some Python.

### Why Use GNU Parallel?

Suppose you have a very simple serial program that crops a photo, and you need to apply it to crop several million photos. You could rewrite the serial program into a parallel program that would use multiple processors to more quickly run the program over the entire set of photos (compared to doing one-at-a-time), but this would require some knowledge of parallel programming. If your code is in a language that has limited parallelization capabilities, this may not even be an option. The easiest solution for this problem is to use GNU Parallel.
Suppose you have a very simple serial program that crops a photo, and you
need to apply it to crop several million photos. You could rewrite the
serial program into a parallel program that would use multiple processors
to more quickly run the program over the entire set of photos (compared to
doing one-at-a-time), but this would require knowledge of parallel
programming. If your code is in a language that has limited
parallelization capabilities then this may not even be an option. The
easiest solution to this problem is to use GNU Parallel.

### Using GNU Parallel

GNU Parallel is provided as a software module on RMACC Summit. It allows shell commands (for example, calls to serial programs) to be distributed amongst nodes and cores on RMACC Summit. This means code doesn’t need to be explicitly parallelized for MPI or OpenMP. Additionally, code can be written in any language that can be run from a Linux shell.
GNU Parallel is provided as a software module on Alpine. It allows shell
commands (for example, calls to serial programs) to be distributed amongst nodes and cores. This means code doesn’t need to be explicitly parallelized for MPI or OpenMP. Additionally, code can be written in any language that can be run from a Linux shell.

Let’s create a simple ‘Hello World’ serial python script to demonstrate the GNU Parallel tool. We will call the script `hello_World.py` and it will print “Hello World from task: ” followed by a command line argument:

Expand All @@ -18,30 +29,38 @@ import sys
print “Hello World from task: ”, sys.argv[1]
```

Now create a job script called `run_hello.sh` that will use GNU Parallel to run as many instances of your python script as you want. Before running GNU Parallel in our script, we need to load the Python and GNU Parallel modules. Your job script should look something like this:
Now create a job script called `run_hello.sh` that will use GNU Parallel
to run as many instances of your python script as you want. Before running GNU Parallel in our script, we need to load the python and GNU Parallel modules. Your job script should look something like this:

> _Note: This example uses a custom python environment built with conda, more infomation on using python or R with conda can be found [here](/software/python.html)_
> _Note: This example uses a custom python environment built with conda,
more infomation on using python or R with conda can be found
[here](./python.html)_

```bash
#!/bin/bash

#SBATCH --time 00:02:00
#SBATCH --partition shas-testing
#SBATCH --partition atesting
#SBATCH --qos testing
#SBATCH --ntasks=4
#SBATCH --job-name gpPythonDemo
#SBATCH --output gnuparallel.out

module purge
module load anaconda
conda activate custom_python_environment
conda activate your_custom_env
module load gnu_parallel

my_parallel="parallel --delay .2 -j $SLURM_NTASKS"
my_srun="srun --export=all --exclusive -n1 --cpus-per-task=1 --cpu-bind=cores"
$my_parallel "$my_srun python hello_World.py" ::: {1..20}
```

Note the last three lines of the script. We customize the GNU Parallel `parallel` command by creating a variable called `$my_parallel` that delays the execution of each task by 0.2 seconds (`--delay 0.2`) which mitigates bottlenecks for tasks that have heavy I/O when they start, and which specifies the number of tasks to run simultaneously (`-j $SLURM_NTASKS`). The environment variable `$SLURM_NTASKS` is set by Slurm at runtime and contains the number of `—ntasks` (cores) requested in the `#SBATCH` directives near the top of the job script (in this case the value is 4). We then customize the `srun` command so that it properly allocates the GNU parallel tasks to the allocated cores (`--export=all --exclusive -N1 -n1 --cpus-per-task=1 --cpu-bind=cores`). Note that the use of `srun` will also ensure that GNU parallel runs properly for cases where we request cores across multiple nodes (e.g., if we request `--ntasks=100`). Finally, we invoke GNU Parallel to run our python script 20 times using the customized `parallel` and `srun` commands we just created, `$my_parallel` and `$my_srun` respectively. Running this script via `sbatch` will run the commands. A successful job will result in output that looks something like this:
Note the last three lines of the script. We customize the GNU Parallel
`parallel` command by creating a variable called `$my_parallel` that
delays the execution of each task by 0.2 seconds (`--delay 0.2`) to
mitigates bottlenecks for tasks that have heavy I/O, and which specifies
the number of tasks to run simultaneously (`-j $SLURM_NTASKS`). The environment variable `$SLURM_NTASKS` is set by Slurm at runtime and contains the number of `—ntasks` (cores) requested in the `#SBATCH` directives. We then customize the `srun` command so that it properly allocates the GNU parallel tasks to the allocated cores (`--export=all --exclusive -N1 -n1 --cpus-per-task=1 --cpu-bind=cores`). Note that the use of `srun` will also ensure that GNU parallel runs properly for cases where we request cores across multiple nodes (e.g., if we request `--ntasks=100`). Finally, we invoke GNU Parallel to run our python script 20 times using the customized `parallel` and `srun` commands we just created, `$my_parallel` and `$my_srun` respectively. Running this script via `sbatch` will run the commands. A successful job will result in output that looks something like this:

```
Hello World from task: 1
Expand Down
1 change: 1 addition & 0 deletions docs/software/gaussian.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ __Linda Parallel__
#SBATCH --cpus-per-task=64
#SBATCH --time=00:50:00
#SBATCH --output=g16-test.%j.out
#SBATCH --constraint=ib

module load gaussian/16_avx2
source $g16root/g16/bsd/g16.profile
Expand Down
2 changes: 1 addition & 1 deletion docs/software/matlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ to use the GUI (in this instance, the Matlab Desktop). However, there
might be other reasons you would like to work interactively with
Matlab.

The second way to run Matlab on RC resources through a
The second way to run Matlab on RC resources is through a
batch job. This allows the job to run in the background when resources
become available. You may choose to use this method if you have a
large job that may wait in the queue for awhile, or if you are not
Expand Down
3 changes: 2 additions & 1 deletion docs/software/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ should see `(pyomp_2022)` replace the `(base)` in front of your prompt.

To see the python packages available in the environment, you can type `conda list`.

Similarly to use the CURC R distribution (R v3.6.0), run the following command with Anaconda initialized:
Similarly, to use the CURC R distribution (R v3.6.0), run the following
command with Anaconda initialized:

```
(base) [johndoe@c3cpu-a7-u19-1 ~]$ conda activate
Expand Down

0 comments on commit e8999bf

Please sign in to comment.