Revision [6857]
This is an old revision of OpenMP made by ToBo on 2008-12-06 14:57:28.
OpenMP
● OpenMP ist nur für Parallelrechner mit gemeinsamem Speicher geeignet.
● Schnittstellen für Fortran und C/C++
● Industriestandard (V1.0 in 1998, V2.0 in 2002, V2.5 in 2005, V3.0 in 2008)
● Erhältlich auf vielen Plattformen (vergleichbar mit MPI)
● erlaubt eine schrittweise Parallelisierung
● kommerziell und als OpenSource (Sun Studio und GCC) verfügbar
● URL: http://www.openmp.org , Text des Standards auf der Webseite verfügbar.
http://de.wikipedia.org/wiki/OpenMP
#pragma omp <Direktive> <Klauseln>
{
<referenzierter Bereich, enthält C/C++ Anweisungen>
}
{
<referenzierter Bereich, enthält C/C++ Anweisungen>
}
#include <omp.h>
int main () {
int nthreads, tid;
omp_set_num_threads(3);
printf("maxthreads=%d\n", omp_get_max_threads());
/* Fork a team of threads giving them their
own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain and print thread id */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}
/* All threads join master thread and terminate */
return 0;
}
int main () {
int nthreads, tid;
omp_set_num_threads(3);
printf("maxthreads=%d\n", omp_get_max_threads());
/* Fork a team of threads giving them their
own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
/* Obtain and print thread id */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}
/* All threads join master thread and terminate */
return 0;
}
Siehe auch • • • •