OpenMP: Difference between revisions

Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Description ==
== Description ==
[http://openmp.org/wp/ OpenMP] (Open Multi-Processing) is an application programming interface for shared memory parallel computing. This API is supported on numerous platforms, including Linux and Windows, and is available for the C/C++ and Fortran programming languages. The API consists of a set of directives, a software library, and environment variables.
[http://openmp.org/wp/ OpenMP] (Open Multi-Processing) is an application programming interface (API) for shared memory parallel computing. It is supported on numerous platforms, including Linux and Windows, and is available for the C/C++ and Fortran programming languages. The API consists of a set of directives, a software library, and environment variables.


OpenMP allows for the rapid development of fine-grained parallel applications on a multicore machine while staying close to the serial code. Although there is only one program instance running, it can execute multiple subtasks in parallel. Directives inserted into the program control the parallel execution and allow for the management of the computations' distribution between the subtasks. The beauty of these directives is that they are usually non-intrusive and the compiler that does not support them can still compile the program and the user can run it, serially of course, as usual.
OpenMP allows one to develop fine-grained parallel applications on a multicore machine while making it possible to preserve the structure of the serial code. Although there is only one program instance running, it can execute multiple subtasks in parallel. Directives inserted into the program control the parallel execution and allow the management of the distribution of work between the subtasks. The beauty of these directives is that they are usually non-intrusive. A compiler that does not support them can still compile the program and the user can run it serially.


The OpenMP interface relies on the notion of threads, a well-known concept in the Operating Systems realm. A thread is a bit like a light weight process or a "virtual processor, operating serially", and can formally be defined as the smallest unit of work/processing that can be scheduled by an Operating System. From a programmer's point of view, if there are five threads, then that corresponds virtually to five cores that can do a computation in parallel. It is important to understand that the number of threads is independent of the number of physical cores within the computer. Two cores can, for example, run a program with ten threads. The operating system decides how to share the cores' time between threads.  
OpenMP relies on the notion of [https://en.wikipedia.org/wiki/Thread_(computing) threads]. A thread is a bit like a light weight process or a "virtual processor, operating serially", and can formally be defined as the smallest unit of work/processing that can be scheduled by an operating system. From a programmer's point of view, if there are five threads, then that corresponds virtually to five cores that can do a computation in parallel. It is important to understand that the number of threads is independent of the number of physical cores within the computer. Two cores can, for example, run a program with ten threads. The operating system decides how to share the cores' time between threads.  


Having said that, it is clear that if you have four available cores, you should use at least four threads to be able to profit from all the available computing power, as a thread can not be executed by two processors at the same time. It could be advantageous, in certain cases, to use more threads than the number of available cores. Using too many threads is not recommended, however.
Conversely, one thread can ''not'' be executed by two processors at the same time, so if you have (e.g.) four cores available you must create at least four threads in order to take advantage of them all. In some cases it ''may'' be advantageous to use more threads than the number of available cores, but the usual practice is to match the number of threads to the number of cores.


Another important point concerning threads is synchronization. When multiple threads within the same program do computations at the same time, absolutely nothing can be assumed about the order in which things happen. If the order matters for the correctness of the code, then the necessary openMP synchronization directives need to used to achieve that. The exact thread distribution method, between cores, remains completely unknown to the programmer (openMP and thread affinity offer capabilities to help the programmer control that as well).  
Another important point concerning threads is synchronization. When multiple threads in a program do computations at the same time, one must assume nothing about the order in which things happen. If the order matters for the correctness of the code, then the programmer must use OpenMP synchronization directives to achieve that. Also, the precise distribution of threads over cores is unknown to the programmer (although thread [https://en.wikipedia.org/wiki/Processor_affinity affinity] capabilities are available to control that).


The following link points to a [http://www.admin-magazine.com/HPC/Articles/Programming-with-OpenMP tutorial for getting started with OpenMP under Linux].
The following link points to a [http://www.admin-magazine.com/HPC/Articles/Programming-with-OpenMP tutorial for getting started with OpenMP under Linux].
Bureaucrats, cc_docs_admin, cc_staff
2,879

edits

Navigation menu