CS 4230: Parallel Programming Lecture 4: OpenMP Open Multi-Processing
January 23, 2017
01/23/2017 1 CS4230
CS 4230: Parallel Programming Lecture 4: OpenMP Open - - PowerPoint PPT Presentation
CS 4230: Parallel Programming Lecture 4: OpenMP Open Multi-Processing January 23, 2017 01/23/2017 CS4230 1 Outline OpenMP another approach for thread parallel programming Fork-Join execution model OpenMP constructs syntax
01/23/2017 1 CS4230
2 01/23/2017 CS4230
See http://www.openmp.org
01/23/2017 CS4230 3
1/23/2017 CS 4230
#include <omp.h> #include <stdio.h> int main (int argc, char *argv[]) { #pragma omp parallel { printf("Hello World from Thread %d!\n”,
} return 0; }
01/23/2017 CS4230 5
01/23/2017 CS4230 6
01/23/2017 CS4230 7
01/23/2017 CS4230 8
01/23/2017 CS4230 9
01/23/2017 CS4230 10
01/23/2017 CS4230 11
01/23/2017 CS4230 12
#include <omp.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { int i,n=1000; float a[1000], b[1000], sum; for (i=0; i<n; i++) a[i] = b[i] = i * 1.0; sum = 0.0; #pragma omp parallel for reduction(+:sum) for (i=0; i<n; i++) sum = sum + (a[i] * b[i]); printf("Sum = %f\n",sum); }
01/23/2017 CS4230 13
Source: http://computing.llnl.gov/tutorials/openMP/samples/C/omp_reduction.c
– int pthread_barrier_wait(pthread_barrier_t *barrier);
01/23/2017 CS4230 14
01/23/2017 CS4230 15
Threads Time (s) Speedup
01/23/2017 CS4230 16
01/23/2017 CS4230 17