You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This program finds all primes in the first 40,000,000 integers,
6
-
the number of 4n+1 primes, and the number of 4n-1 primes in the same range.
5
+
This program finds all primes in the first 40,000,000 integers,
6
+
the number of 4n+1 primes, and the number of 4n-1 primes in the same range.
7
7
It illustrates two OpenMP* directives to help speed up the code.
8
8
9
-
9
+
10
10
| Optimized for | Description
11
11
|:--- |:---
12
-
| OS | macOS* with Xcode* installed
12
+
| OS | macOS* with Xcode* installed
13
13
| Software | Intel® Fortran Compiler
14
14
| What you will learn | How to build and run a Fortran OpenMP application using Intel Fortran Compiler
15
15
| Time to complete | 10 minutes
16
16
17
17
## Purpose
18
18
19
-
This program finds all primes in the first 40,000,000 integers, the number of 4n+1 primes,
20
-
and the number of 4n-1 primes in the same range. It illustrates two OpenMP* directives
19
+
This program finds all primes in the first 40,000,000 integers, the number of 4n+1 primes,
20
+
and the number of 4n-1 primes in the same range. It illustrates two OpenMP* directives
21
21
to help speed up the code.
22
22
23
-
First, a dynamic schedule clause is used with the OpenMP* for a directive.
24
-
Because the DO loop's workload increases as its index get bigger,
25
-
the default static scheduling does not work well. Instead, dynamic scheduling
26
-
is used to account for the increased workload.
27
-
But dynamic scheduling itself has more overhead than static scheduling,
23
+
First, a dynamic schedule clause is used with the OpenMP* for a directive.
24
+
Because the DO loop's workload increases as its index get bigger,
25
+
the default static scheduling does not work well. Instead, dynamic scheduling
26
+
is used to account for the increased workload.
27
+
But dynamic scheduling itself has more overhead than static scheduling,
28
28
so a chunk size of 10 is used to reduce the overhead for dynamic scheduling.
29
29
30
-
Second, a reduction clause is used instead of an OpenMP* critical directive
31
-
to eliminate lock overhead. A critical directive would cause excessive lock overhead
32
-
due to the one-thread-at-time update of the shared variables each time through the DO loop.
30
+
Second, a reduction clause is used instead of an OpenMP* critical directive
31
+
to eliminate lock overhead. A critical directive would cause excessive lock overhead
32
+
due to the one-thread-at-time update of the shared variables each time through the DO loop.
33
33
Instead, the reduction clause causes only one update of the shared variables once at the end of the loop.
34
34
35
-
The sample can be compiled unoptimized (-O0 ), or at any level of
35
+
The sample can be compiled unoptimized (-O0 ), or at any level of
36
36
optimization (-O1 through -O3 ). Also, the following compiler options are needed.
37
37
38
-
The option -qopenmp enables compiler recognition of OpenMP* directives.
38
+
The option -qopenmp enables compiler recognition of OpenMP* directives.
39
39
This option can also be omitted, in which case the generated executable will be a serial program.
40
40
41
41
The option -fpp enables the Fortran preprocessor.
42
42
Read the Intel® Fortran Compiler Documentation for more information about these options.
43
43
44
44
## Key Implementation Details
45
-
The Intel® oneAPI Intel Fortran Compiler includes all libraries and headers necessary to compile and run OpenMP* enabled Fortran applications. Users simply use the -qopenmp compiler option to compile and link their OpenMP enabled applications.
45
+
The Intel® oneAPI Intel Fortran Compiler includes all libraries and headers necessary to compile and run OpenMP* enabled Fortran applications. Users simply use the -qopenmp compiler option to compile and link their OpenMP enabled applications.
46
46
47
-
## License
47
+
## License
48
48
Code samples are licensed under the MIT license. See
49
49
[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.
50
50
51
51
Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt)
52
52
53
-
## Building the `Fortran OpenMP*` sample
53
+
## Using Visual Studio Code* (Optional)
54
+
55
+
You can use Visual Studio Code (VS Code) extensions to set your environment, create launch configurations,
56
+
and browse and download samples.
57
+
58
+
The basic steps to build and run a sample using VS Code include:
59
+
- Download a sample using the extension **Code Sample Browser for Intel oneAPI Toolkits**.
60
+
- Configure the oneAPI environment with the extension **Environment Configurator for Intel oneAPI Toolkits**.
61
+
- Open a Terminal in VS Code (**Terminal>New Terminal**).
62
+
- Run the sample in the VS Code terminal using the instructions below.
63
+
- (Linux only) Debug your GPU application with GDB for Intel® oneAPI toolkits using the **Generate Launch Configurations** extension.
64
+
65
+
To learn more about the extensions, see
66
+
[Using Visual Studio Code with Intel® oneAPI Toolkits](https://www.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html).
67
+
68
+
After learning how to use the extensions for Intel oneAPI Toolkits, return to this readme for instructions on how to build and run a sample.
69
+
70
+
## Building the `Fortran OpenMP*` sample
71
+
72
+
> **Note**: If you have not already done so, set up your CLI
73
+
> environment by sourcing the `setvars` script located in
>For more information on environment variables, see Use the setvars Script for [Linux or macOS](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html), or [Windows](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-windows.html).
54
83
55
84
### Experiment 1: Unoptimized build and run
56
85
* Build openmp_samples
57
86
58
-
cd openmp_samples
59
-
make clean
87
+
cd openmp_samples
88
+
make clean
60
89
make debug
61
90
62
91
* Run the program
@@ -65,16 +94,16 @@ Third party program Licenses can be found here: [third-party-programs.txt](https
65
94
66
95
* What did you see?
67
96
68
-
Did the debug, unoptimized code run slower?
69
-
70
-
### Experiment 2: Default Optimized build and run
97
+
Did the debug, unoptimized code run slower?
98
+
99
+
### Experiment 2: Default Optimized build and run
71
100
72
101
* Build openmp_samples
73
102
74
-
make
103
+
make
75
104
* Run the program
76
105
77
-
make run
106
+
make run
78
107
79
108
### Experiment 3: Controlling the number of threads
80
109
By default, an OpenMP application creates and uses as many threads as the number of "processors" in a system. A "processor" is defined as the number of logical processors, which are twice the number of physical cores on hyperthreaded cores.
@@ -89,13 +118,18 @@ note the number of threads reported by the application. Now try two threads:
89
118
make run
90
119
Did the make the application run faster? Experiment with the number of threads and see how it affects performance.
91
120
92
-
### Clean up
93
-
* Clean the program
121
+
### Clean up
122
+
* Clean the program
94
123
make clean
95
124
125
+
### Troubleshooting
126
+
If an error occurs, troubleshoot the problem using the Diagnostics Utility for Intel® oneAPI Toolkits.
Interested in learning more? We have a wealth of information
98
-
on using OpenMP with the Intel Fortran Compiler in our
131
+
Interested in learning more? We have a wealth of information
132
+
on using OpenMP with the Intel Fortran Compiler in our
99
133
[OpenMP section of Developer Guide and Reference][1]
100
134
101
135
[1]: https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-developer-guide-and-reference/top/optimization-and-programming-guide/openmp-support.html"Developer Guide and Reference"
0 commit comments