Information AboutOpenmp |
| CATEGORIES ABOUT OPENMP | |
| fortran programming language family | |
| c programming language family | |
| parallel computing | |
| application programming interfaces | |
|
The OpenMP (Open Multi-Processing) is an Application Programming Interface (API) that supports multi-platform Shared Memory Multiprocessing programming in C / C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms. It consists of a set of Compiler Directive s, library routines, and Environment Variable s that influence run-time behavior. Jointly defined by a group of major computer hardware and software vendors, OpenMP is a portable, scalable model that gives Programmer s a simple and flexible interface for developing parallel applications for platforms ranging from the desktop to the Supercomputer . Often a so-called hybrid-model for Parallel Programming , programming in Computer Cluster s can be done using both OpenMP and MPI ( Message Passing Interface ) simultaneously. INTRODUCTION where the master thead forks off a number of threads which execute blocks of code in parallel]] OpenMP is an implementation of Multithreading , a method of parallelization whereby the master "thread" (a series of instructions executed consecutively) "forks" a specified number of slave "threads" and a task is divided among them. The threads then run concurrently, with the Runtime Environment allocating threads to different processors. The section of code that is meant to run in parallel is marked accordingly, with a Preprocessor Directive that will cause the threads to form before the section is executed. Each thread has an "id" attached to it which can be obtained using a Function (called omp_get_thread_num() in C / C++ and OMP_GET_THREAD_NUM() in FORTRAN ). The thread id is an integer, and the master thread has an id of "0". After the execution of the parallelized code, the threads "join" back into the master thread, which continues onward to the end of the program.By default, each thread executes the parallelized section of code independently. "Work-sharing constructs" can be used to divide a task among the threads so that each thread executes its allocated part of the code. Both Task Parallelism and Data Parallelism can be achieved using OpenMP in this way. The runtime environment allocates threads to processors depending on usage, machine load and other factors. The number of threads can be assigned by the runtime environment based on Environment Variables or in code using functions. The OpenMP functions are included in a Header File labelled "omp.h" in C / C++ . HISTORY The OpenMP Architecture Review Board (ARB) published its first standard, OpenMP for FORTRAN 1.0, in October of 1997. October the following year they released the C/C++ standard. 2000 saw version 2.0 of the FORTRAN standard with version 2.0 of the C/C++ standard being released in 2002. The current version is 2.5. It is a combined C/C++/FORTRAN standard, which was released in 2005. THE CORE ELEMENTS The core elements of OpenMP are the constructs for thread creation, work load distribution (work sharing), data environment management, thread synchronization, user level runtime routines and environment variables. A compiler directive in C/C++ is called a ''pragma'' (pragmatic information). It is a Preprocessor Directive so is declared with a hash (#). Compiler directives specific to OpenMP in C/C++ are written in codes as follows: #pragma omp The OpenMP specific pragmas are listed below: Thread creation ''omp parallel''. It is used to fork additional threads to carry out the work enclosed in the construct in parallel. The original process will be denoted as master thread with thread ID 0. Example: Display "Hello, world" using multiple threads.
{ #pragma omp parallel printf("Hello, world. "); return 0; } Work-sharing constructs used to specify how to assign independent work to one or all of the threads.
Example: initialize the value of a large array in parallel, using each thread to do a portion of the work #define N 100000
{ int i, a {Link without Title} ; #pragma omp parallel for for (i=0;i
return 0; } OpenMP Clauses Since OpenMP is a shared memory programming model, most variables in OpenMP code are visible to all threads by default. But sometimes private variables are necessary to avoid Race Condition and there is a need to pass values between the sequential part and the parallel region (the code block executed in parallel), so data environment management is introduced as ''data clauses'' by appending them to the OpenMP directive. The different types of clauses are Data Scoping Clauses
Synchronization clauses
Scheduling clauses
#''static'': Here,all the threads are allocated iterations before they execute the loop iterations. The iterations are divided among threads equally by default.However, specifying an integer for the parameter "chunk" will allocate "chunk" number of contiguous iterations to a particular thread. #''dynamic'':Here,some of the iterations are allocated to a smaller number of threads.Once a particular thread finishes its allocated iteration, it returns to get another one from the iterations that are left. The parameter "chunk" defines the number of contiguous iterations that are allocated to a thread at a time. #''guided'':A large chunk of contiguous iterations are allocated to each thread dynamically (as above). The chunk size decreases exponentially with each successive allocation to a minimum size specified in the parameter "chunk" IF control
Initialization
Data copying
Reduction |
|
|