compiling_an_openmp_application.md 1.11 KB
Newer Older
Adam Caprez's avatar
Adam Caprez committed
1
2
3
+++
title = "Compiling an OpenMP Application"
description = "How to compile an OpenMP-based application on HCC resources."
Carrie A Brown's avatar
Carrie A Brown committed
4
weight=20
Adam Caprez's avatar
Adam Caprez committed
5
+++
6

Adam Caprez's avatar
Adam Caprez committed
7
8
9
Compiling an [OpenMP](https://computing.llnl.gov/tutorials/openMP)
application is done with the `-fopenmp` option to GCC and the `-openmp` or
`-qopenmp` option for Intel.  For example, the command could be:
10

Adam Caprez's avatar
Adam Caprez committed
11
{{< highlight bash >}}
12
$ gcc -o openmp-app.exe -fopenmp openmp-app.c
Adam Caprez's avatar
Adam Caprez committed
13
{{< /highlight >}}
14
15
16
17
18

GCC will perform all of the OpenMP pragmas.

OpenMP applications have OpenMP pragmas like `#pragma omp <options>`

Adam Caprez's avatar
Adam Caprez committed
19
{{< highlight C >}}
20
21
22
23
24
#pragma omp parallel for reduction(+: sum) 
  for (i = 0; i<NUM_STEPS; i++) {
    x = 2.0 * (double)i / (double)(NUM_STEPS); /* value of x */
    sum += x * x;
  }
Adam Caprez's avatar
Adam Caprez committed
25
{{< /highlight >}}
26

Adam Caprez's avatar
Adam Caprez committed
27
28
An example application code is [integrate_mp.c](/attachments/integrate_mp.c).
Compiling `integrate_mp.c` is done with the `gcc` command:
29

Adam Caprez's avatar
Adam Caprez committed
30
{{< highlight bash >}}
31
$ gcc -o integrate_mp.exe -fopenmp integrate_mp.c
Adam Caprez's avatar
Adam Caprez committed
32
{{< /highlight >}}
33

Adam Caprez's avatar
Adam Caprez committed
34
See [Submitting an OpenMP Job]({{< relref "submitting_an_openmp_job" >}}) for
35
instructions on how to submit `integrate_mp.exe` to the cluster.