Professional Documents
Culture Documents
Experiment No. 6 Aim: To Learn Basics of Openmp Api (Open Multi-Processor Api) Theory What Is Openmp?
Experiment No. 6 Aim: To Learn Basics of Openmp Api (Open Multi-Processor Api) Theory What Is Openmp?
6
AIM: To learn basics of OpenMP API (Open Multi-Processor API)
THEORY
What is OpenMP?
1. An Application Program Interface (API) that may be used to explicitly direct multi-
threaded, shared memory parallelism.
2. Comprised of three primary API components:
1) Compiler Directives
2) Runtime Library Routines
3) Environment Variables
3. An abbreviation for: Open Multi-Processing
Goals of OpenMP:
1) Standardization: Provide a standard among a variety of shared memory
architectures/platforms
Jointly defined and endorsed by a group of major computer hardware and software
vendors
2) Lean and Mean: Establish a simple and limited set of directives for programming shared
memory machines.
Significant parallelism can be implemented by using just 3 or 4 directives. This goal is
becoming less meaningful with each new release, apparently.
3) Ease of Use: Provide capability to incrementally parallelize a serial program, unlike
message-passing libraries which typically require an all or nothing approach.
Provide the capability to implement both coarse-grain and fine-grain parallelism.
4) Portability: The API is specified for C/C++ and FORTRAN. Most major platforms have
been implemented including Unix/Linux platforms and Windows.
This study source was downloaded by 100000823978223 from CourseHero.com on 01-26-2022 12:22:24 GMT -06:00
https://www.coursehero.com/file/58867299/EXP-6pdf/
OpenMP Programming Model:
This study source was downloaded by 100000823978223 from CourseHero.com on 01-26-2022 12:22:24 GMT -06:00
https://www.coursehero.com/file/58867299/EXP-6pdf/
JOIN: When the team threads complete the statements in the parallel region construct,
they synchronize and terminate, leaving only the master thread.
The number of parallel regions and the threads that comprise them are arbitrary.
Compiler Directives:
Compiler directives appear as comments in your source code and are ignored by compilers
unless you tell them otherwise - usually by specifying the appropriate compiler flag, as
discussed in the Compiling section later.
This study source was downloaded by 100000823978223 from CourseHero.com on 01-26-2022 12:22:24 GMT -06:00
https://www.coursehero.com/file/58867299/EXP-6pdf/
Run-time Library Routines:
The OpenMP API includes an ever-growing number of runtime library routines.
These routines are used for a variety of purposes:
Function Description
void omp_set_num_threads(int num_threads) Dynamically set the number of threads to
use for this region.
This study source was downloaded by 100000823978223 from CourseHero.com on 01-26-2022 12:22:24 GMT -06:00
https://www.coursehero.com/file/58867299/EXP-6pdf/
int omp_get_num_procs(void) Determines the number of processors on
the current machine.
int omp_in_parallel(void) Returns non-zero if it is called within the
dynamic extent of a parallel region
executing in parallel, otherwise it returns
zero.
void omp_set_dynamic(int dynamic_threads) Enable or disable dynamic adjustment of
the number of threads used to execute a
parallel region.
int omp_get_dynamic(void) Returns non-zero if dynamic thread
adjustment is enabled and returns zero
otherwise.
void omp_set_nested(int nested) Enable or disable nested parallelism. If
parameter is non-zero, enable. Default is
disabled.
int omp_get_nested(void) Always returns zero in the current version
of compiler.
Environment Variables:
OpenMP provides several environment variables for controlling the execution of parallel code
at run-time.
These environment variables can be used to control such things as:
This study source was downloaded by 100000823978223 from CourseHero.com on 01-26-2022 12:22:24 GMT -06:00
https://www.coursehero.com/file/58867299/EXP-6pdf/
CODE:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
OUTPUT:
CONCLUSION:
Thus,
1. Basics of OpenMP are now clear.
2. Various concepts such as parallelism, run-time libraries and environment variables were
studied in detail.
This study source was downloaded by 100000823978223 from CourseHero.com on 01-26-2022 12:22:24 GMT -06:00
https://www.coursehero.com/file/58867299/EXP-6pdf/