openmp shared memory architektur processor bus memory processor

67
OpenMP

Upload: daryl-dancer

Post on 28-Mar-2015

228 views

Category:

Documents


1 download

TRANSCRIPT

  • Slide 1

Slide 2 OpenMP Slide 3 Shared Memory Architektur Processor BUS Memory Processor Slide 4 OpenMP Portable programming of shared memory systems. It is a quasi-standard. OpenMP-Forum 1997 - 2009 API for Fortran and C/C++ directives runtime routines environment variables www.openmp.org Slide 5 > export OMP_NUM_THREADS=3 > a.out Hello World > export OMP_NUM_THREADS=2 > a.out Hello world > icc O3 openmp openmp.c #include main(){ #pragma omp parallel { printf(Hello world); } Example Program Compilation Execution Slide 6 #pragma omp parallel { printf(Hello world %d\n, omp_get_thread_num()) ; } PARALLEL { Execution Model print } T0 T1T2 T0 Thread Team Creates Team is destroyed Slide 7 Fork/Join Execution Model 1.An OpenMP-program starts as a single thread (master thread). 2.Additional threads (Team) are created when the master hits a parallel region. 3.When all threads finished the parallel region, the new threads are given back to the runtime or operating system. A team consists of a fixed set of threads executing the parallel region redundantly. All threads in the team are synchronized at the end of a parallel region via a barrier. The master continues after the parallel region. Slide 8 Work Sharing in a Parallel Region main (){ int a[100]; #pragma omp parallel { #pragma omp for for (int i= 1; i Example: Tree Traversal struct node { struct node *left; struct node *right; }; void traverse( struct node *p ) { if (p->left) #pragma omp task // p is firstprivate by default traverse(p->left); if (p->right) #pragma omp task // p is firstprivate by default traverse(p->right); process(p); } Slide 55 #pragma omp taskwait {... } Task Wait Waits for completion of child tasks Child tasks: Tasks generated since the beginning of the current task. Slide 56 Slide 57 Slide 58 Slide 59 Slide 60 Slide 61 Slide 62 Slide 63 Collapsing of loops Handles multi-dimensional perfectly nested loops Larger iteration space ordered according to sequential execution. Schedule clause applies to new iteration space #pragma omp parallel for collapse(2) for (i=0; i