Skip to content

Commit

Permalink
programming and parallelization updates 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevhall52 committed Dec 16, 2022
1 parent 39afaa1 commit 53b2247
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
13 changes: 7 additions & 6 deletions docs/programming/OpenMP-C.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Using OpenMP with C

Because Summit is a cluster of CPUs, the most effective way to utilize
Because a cluster consists of many CPUs, the most effective way to utilize
these resources involves parallel programming. Probably the simplest
way to begin parallel programming involves the utilization of
OpenMP. OpenMP is a Compiler-side solution for creating code that runs
Expand Down Expand Up @@ -91,15 +91,16 @@ __Intel__:
icc parallel_hello_world.cpp -o parallel_hello_world.exe -qopenmp
```

This will give us an executable we can run as a job to
Summit. Simply run the job specifying slurm to run the
This will give us an executable we can submit as a job to our cluster.
Simply submit the job to Slurm, running the
executable. Your job script should look something like this:

```bash
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --time=0:01:00
#SBATCH --partition=shas-testing
#SBATCH --partition=atesting
#SBATCH --constraint=ib
#SBATCH --ntasks=4
#SBATCH --job-name=CPP_Hello_World
#SBATCH --output=CPP_Hello_World.out
Expand Down Expand Up @@ -179,7 +180,7 @@ Hello from process: 2
Hello from process: 1
```
Don’t worry about order of processes that printed, the threads will
Note: Don’t worry about the order of processes that printed, the threads will
print out at varying times.
Expand Down Expand Up @@ -470,7 +471,7 @@ int main(int argc, char** argv){
Let’s now set up our work sharing directive. We will use the `#pragma
omp for` to declare the loop as to be work sharing, followed by the
actual C++ loop. Because we want to add all number from 1 to 1000, we
will initialize out loop at one and end at 1000.
will initialize our loop at one and end at 1000.
```c++
#include <stdio.h>
Expand Down
16 changes: 9 additions & 7 deletions docs/programming/OpenMP-Fortran.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Using OpenMP with Fortran

Because Summit is a cluster of CPUs, parallel programming is the most
Because clusters are comprised of many CPUs, parallel programming is the most
effective way to utilize these resources. Probably the simplest way to
begin parallel programming is utilization of OpenMP. OpenMP is a
Compiler-side solution for creating code that runs on multiple
Expand Down Expand Up @@ -86,15 +86,17 @@ ifort parallel_hello_world.f90 -o parallel_hello_world.exe -qopenmp
```

This will give us an executable we can run as a job on
Summit. Simply run the job specifying slurm to run the
a cluster. Simply run the job telling Slurm to run the
executable. Your job script should look something like this:

```bash
#!/bin/bash

#SBATCH --nodes=1
#SBATCH --time=0:01:00
#SBATCH --partition=shas-testing
#SBATCH --partition=atesting
#SBATCH --constraint=ib
#SBATCH --qos=testing
#SBATCH --ntasks=4
#SBATCH --job-name=Fortran_Hello_World
#SBATCH --output=Fortran_Hello_World.out
Expand Down Expand Up @@ -280,7 +282,7 @@ Hello from process: 1
### Barrier and Critical Directives

OpenMP has a variety of tools for managing processes. One of the more
prominent forms of control comes with the b__arrier__:
prominent forms of control comes with the __barrier__:

```fortran
!$OMP BARRIER
Expand Down Expand Up @@ -397,8 +399,8 @@ Hello from process: 3
OpenMP’s power comes from easily splitting a larger task into multiple
smaller tasks. Work-sharing directives allow for simple and effective
splitting of normally serial tasks into fast parallel sections of
code. In this section we will learn how to implement omp do directive.
The directive omp do divides a normally serial for loop into a
code. In this section we will learn how to implement the `!$OMP DO` directive.
The directive `!$OMP DO` divides a normally serial for loop into a
parallel task. We can implement this directive as such:

```fortran
Expand All @@ -410,7 +412,7 @@ parallel task. We can implement this directive as such:
#### Example

Let’s write a program to add all the numbers between 1 and 1000. Begin
with a program title and the omp_lib header:
with a program title and the `OMP_LIB` header:

```fortran
PROGRAM Parallel_Do
Expand Down

0 comments on commit 53b2247

Please sign in to comment.