Shared-memory Programming

Size: px
Start display at page:

Download "Shared-memory Programming"

Transcription

1 Shared-memory Programming Introduction to High Performance Computing Systems (CS1645) Esteban Meneses

2 Programming a Supercomputer Languages: Fortran, C/C++, Python. Nodes Cores Accelerators Supercomputer Libraries: linear algebra, scientific methods, data mining. 3-tier parallelism, hybrid architecture. 2

3 Node Parallelism One process per node. Private memory. Communication Message Passing Interface (MPI) send(m) between nodes: Message-passing. Basic operations: send, receive. Collective operations. M receive(m) 3

4 Core Parallelism One thread per core. Shared-memory. Synchronization between cores: OpenMP #pragma omp parallel for! for(i=0;i<n;i++)! x[i] += y[i] Basic operations: fork, join. Bulk-synchronous parallel (BSP). 4

5 Accelerator Parallelism Massively parallel thread architecture. Shared memory. Offload mechanism OpenACC #pragma acc kernels! for(i=0;i<n;i++)! x[i] = foo(i) to spawn kernel on accelerator. Manage memory copy operations. 5

6 Multithreading Source: David Whittaker 6

7 Shared-memory Systems Instruction Streams single multiple MISD MIMD SISD SIMD single multiple Data Streams CPU CPU CPU CPU Interconnect Memory There is a single shared address space for all processors. All processors share the same view of memory. 7

8 Types of Shared-memory Systems Uniform Memory Access (UMA): memory is equally accessible to all processors with the same performance (bandwidth and latency). Cache-coherent Non Uniform Memory Access (ccnuma): memory is physically distributed but appears as a single address space. Performance (bandwidth and latency) is different for local and remote memory access. Copies of the same cache line may reside in different caches. Cache coherence protocols guarantees consistency all time (for UMA and ccnuma). Cache coherence protocols do not alleviate parallel programming for shared-memory architectures. Source: Prof. Dr. G. Wellein 8

9 OpenMP Open Multi-Processing. An implementation of multithreading. Standard API for shared-memory programming. OpenMP Architecture Review Board (ARB) published OpenMP standard 1.0 in Adopted by most important operating systems and supercomputer vendors. Based on pragmas, programmer annotations for the compiler. Embraces incremental parallelization philosophy. Serial counterpart is always available. 9

10 Bulk Synchronous Parallelism (BSP) Bridging model developed by Leslie Valiant in Model components: Processors. Network. Synchronization hardware. Computation proceeds by executing supersteps: Concurrent computation. Communication. Barrier synchronization. Concurrency level expands and shrinks. Source: 10

11 Two Types of Parallelism Data parallelism (SIMD): parallel execution of the same code stream on a supercomputer. Each node may process a different data portion. Task parallelism (MIMD): distribution of different code streams on a supercomputer. Each node may process a different data portion. Both are possible in OpenMP. 11

12 Example Grading a set of exams: 40 exams, 4 questions, 4 graders. Data parallelism: 10 exams per grader Task parallelism: 1 question per grader. #1 #2 #3 #

13 OpenMP Standard Defines an Application Program Interface (API) which provides a portable and scalable model for developers of shared memory parallel applications (instead of PThreads). A library with some simple functions. A few program directives (pragmas = hints to the compiler). A few environment variables. A compiler translates OpenMP functions and directives to PThread calls. Program begins with a master thread. Threads are forked when specified by directives. 13

14 Parallel Regions Defined with #pragma omp parallel: #include <omp.h>! int main(){!! print( The output:\n );!! #pragma omp parallel // multi-threaded section!! {!!! printf( Hello World\n );!! }!! // resumes serial section! } The number of spawned threads can be specified through: An environment variable: setenv OMP_NUM_THREADS 8 An API function: void omp_set_num_threads(int number);! Get number of threads: int get_num_threads(); 14

15 Private Variables The format of a pragma in C/C++is: #pragma omp name_of_directive [optional_clauses]! private is a clause that declares variables that are local to the spawned threads. A similar clause, shared, is used to declare variables that are not local (the default). #include <omp.h>! int main(){!! int id, np;!! #pragma omp parallel private(id, np)!! {!!! np = omp_get_num_threads();!!! id = omp_get_thread_num();!!! printf( Hello from thread %d, out of %d threads\n, id, np);!! }! } 15

16 Running jobs on Supercomputers Source: 16

17 Running OpenMP Programs Compiler flag: icpc -openmp pgm.cpp Include file: #include <omp.h> Environment variable for number of threads: OMP_NUM_THREADS Useful functions: omp_set_num_threads(int t) sets number of active threads. omp_get_wtime() gets current wall clock time in seconds. omp_in_parallel() returns true if program is running in parallel; false otherwise omp_get_num_threads() returns the number of active threads. omp_get_thread_num() returns the thread ID. 17

18 Number of Threads The num_threads clause can be added to a parallel directive: # pragma omp parallel num_threads (thread_count) It allows the programmer to specify the number of threads that should execute the following block. There may be system-defined limitations on the number of threads that a program can start. The OpenMP standard does not guarantee that this will actually start thread_count threads. Most current systems can start hundreds or even thousands of threads. Unless we are trying to start a lot of threads, we will almost always get the desired number of threads. 18

19 Critical Sections and Barriers A critical section is executed by one thread at a time; (name) is optional. Critical sections with different names can be executed simultaneously. #pragma omp parallel shared(sum) {!!! value = foo();!! #pragma omp critical(name)! {!! sum = sum + value;! }! } All the threads in the active team must reach the barrier point before any can continue: # pragma omp barrier 19

20 Example Using the trapezoidal rule to compute the integral of a function. h = (b-a)/n! approx = (f(a)+f(b))/2;! for(i=1; i<=n-1; i++){!! xi = a + i*h;!! approx += f(xi);! }! approx = h*approx; Source: 20

21 Example (cont.) We identify two types of tasks: Computation of the areas of individual trapezoids. Adding the areas of trapezoids. There is no communication among the tasks in the first collection, but each task in the first collection communicates with task in the second. We assume that there would be many more trapezoids than cores. So we aggregate tasks by assigning a contiguous block of trapezoids to each thread. Source: An Introduction to Parallel Programming by Peter Pacheco 21

22 Example (cont.) double f(double x); /* Function we're integrating */! void Trap(double a, double b, int n, double* global_result_p);!! int main(int argc, char* argv[]) {! double global_result = 0.0; /* Store result in global_result */! double a, b; /* Left and right endpoints */! int n; /* Total number of trapezoids */! int thread_count;!!!! if (argc!= 2) Usage(argv[0]);! thread_count = strtol(argv[1], NULL, 10);! printf("enter a, b, and n\n");! scanf("%lf %lf %d", &a, &b, &n);! if (n % thread_count!= 0) Usage(argv[0]);! #pragma omp parallel num_threads(thread_count)! Trap(a, b, n, &global_result);! printf("with n = %d trapezoids, our estimate\n", n);! printf("of the integral from %f to %f = %.14e\n",! a, b, global_result);! return 0;! } /* main */ Source: An Introduction to Parallel Programming by Peter Pacheco 22

23 Example (cont.) void Trap(double a, double b, int n, double* global_result_p) {! double h, x, my_result;! double local_a, local_b;! int i, local_n;! int my_rank = omp_get_thread_num();! int thread_count = omp_get_num_threads();!! h = (b-a)/n;! local_n = n/thread_count;! local_a = a + my_rank*local_n*h;! local_b = local_a + local_n*h;! my_result = (f(local_a) + f(local_b))/2.0;! for (i = 1; i <= local_n-1; i++) {! x = local_a + i*h;! my_result += f(x);! }! my_result = my_result*h;!! #pragma omp critical! *global_result_p += my_result;! Source: An Introduction to } /* Trap */ Parallel Programming by Peter Pacheco 23

24 Exercise Implement in OpenMP an efficient parallel version of matrix-matrix multiplication. for (i=0; i<n; i++)! for (j=0; j<n; j++)! for (k=0; k<n; k++)! C[i][j] += A[i][k]*B[k][j];! 24

25 Solution for (i=0; i<n; i++)! for (j=0; j<n; j++)! for (k=0; k<n; k++)! C[i][j] += A[i][k]*B[k][j];! #pragma omp parallel private(np,id)! {! np = omp_get_num_threads();! id = omp_get_thread_num();! for (i=id*n/np; i<(id+1)*n/np; i++)! for (j=0; j<n; j++)! for (k=0; k<n; k++)! C[i][j] += A[i][k]*B[k][j];! } 25

26 Embarrassingly Parallel A problem that has a trivial parallel solution: Simple distribution of work is enough to parallelize. No significant communication complexity. No significant synchronization complexity. Should we feel embarrassed to come up with an easy parallel solution? Of course not. Embarrassingly parallel Delightfully parallel. 26

27 For-loop pragma Automatically distributes iterations in the for-loop to active threads. Syntax: #pragma omp for! for(i=0; i<n; i++){!...! } Usually used inside a parallel region. 27

28 Example: Adding arrays a and b #define N 1024! #define N_THREADS 16! main(){!! int chunk, a[n], b[n], c[n];!! omp_set_num_threads(n_threads);!! chunk = N / N_THREADS;!! #pragma omp parallel shared(a,b,c) private(i, id)!! {!!! id = omp_get_thread_num();!!! for (i=id*chunk; i<(id+1)*chunk; i++)!!!! c[i] = a[i] + b[i];!! }! } #pragma omp parallel shared(a,b,c) private(i, id)! {!! #pragma omp for!! for (i=0; i<n; i++)!!! c[i] = a[i] + b[i];! } 28

29 Combining parallel and for pragmas Programmer needs to consider data dependencies between iterations. #pragma omp parallel shared(a,b,c) private(i)! {! #pragma omp for! for(i=0; i<n; i++)! c[i] = a[i] + b[i];! } #pragma omp parallel for shared(a,b,c) private(i)! for(i=0; i<n; i++)! c[i] = a[i] + b[i];! 29

30 Data Dependencies Example: fibo[0] = fibo[1] = 1; for (i=2; i<10; i++)! fibo[i] = fibo[i 1] + fibo[i 2]; fibo[0] = fibo[1] = 1; # pragma omp parallel for num_threads(2)! for (i=2; i<10; i++)! fibo[i] = fibo[i 1] + fibo[i 2]; Source: An Introduction to Parallel Programming by Peter Pacheco 30

31 Format of parallel for loops Initialization Condition Iteration index = start index < end! index <= end! index >= end! index > end index++ ++index index--! index += inc! index -= inc! index = index + incr! index = incr + index! index = index - incr Variable index has to be either integer or pointer type. Expressions for start, end, and inc have to be compatible with index and should not be changed during the loop. Variable index is made private by default. 31

32 Odd-Even Sort Parallel equivalent to Bubble Sort. If n processors sort n numbers, the worst time is O(n/2). Alternates between n/2 odd and even phases. Each processor holds one number. Odd phase: odd-numbered processors compare and swap their number with neighbor. Even phase: even-numbered processors compare and swap their number with neighbor

33 Odd-Even Sort Program void OddEvenSort(int A[], int n){!! for(int i = 0; i < n; ++i){!!! if(i & 1){!!!! for(int j = 2; j < n; j+=2)!!!!! if (a[j] < a[j-1])!!!!!! swap(a[j-1], a[j]);!!! } else {!!!! for(int j = 1; j < n; j+=2)!!!!! if (a[j] < a[j-1])!!!!!! swap(a[j-1], a[j]);!!! }!! }! } 33

34 Exercise Transform the following loops into valid OpenMP parallel for loops. for(i=0; i<n; i++){!! x = a[i] + b[i];!! for(j=i; j<n; j++){!!! k++;!!! c[i][j] = x + d[k][j];!! }! } for(i=0; i<n; i++){!! x = a[i] + b[i];!! #pragma omp parallel for!! for(j=i; j<n; j++){!!! c[i][j] = x + d[k-i+j+1][j];!! }!! k += n-i;! } 34

35 Exercise (cont.) for(i=0; i<n; i++){!! a[i] = b[i] + c[i][j];!! t = a[i] + 2;!! b[i] = t * 2;!! c[i][j] = t * 3;!! s += t;! } #pragma omp parallel for private(t)! for(i=0; i<n; i++){!! a[i] = b[i] + c[i][j];!! t = a[i] + 2;!! b[i] = t * 2;!! c[i][j] = t * 3;!! #pragma omp critical!! s += t;! } 35

36 Exercise (cont.) for(i=0; i<n; i++){!! for(j=0; j<m; j++){!!! a[j] = a[j] + b[k];!!! k++;!! }!! k++;!! for(j=0; j<m; j++)!!! c[i][j] = a[j] + 1;! } for(i=0; i<n; i++){!! #pragma omp parallel for!! for(j=0; j<m; j++){!!! a[j] = a[j] + b[k+j];!! }!! k += m + 1;!! #pragma omp parallel for!! for(j=0; j<m; j++)!!! c[i][j] = a[j] + 1;! } #pragma omp parallel for! for(i=0; i<n; i++){!! for(j=0; j<m; j++){!!! a[j] = a[j] + b[k+n*(m+1)+j];!! }!! for(j=0; j<m; j++)!!! c[i][j] = a[j] + 1;! }! k += n*(m + 1); 36

37 Scheduling iterations of for loops Used to specify distribution of iterations to threads. Syntax: #pragma omp parallel for schedule(type,chunksize) The type can be: Static: iterations are distributed among threads before the loop is executed. Dynamic or guided: iterations are assigned to threads during the execution of the loop. Auto: the compiler or runtime system determines the proper schedule. Runtime: the environment variable OMP_SCHEDULE is used to determine schedule at runtime. chunksize is a positive integer. 37

38 Static scheduling The iteration space is divided into chunks and distributed to threads in a round-robin fashion. T1 T2 T3 T4 T1 T2 T3 T4 Example, 24 iterations: Chunksize T1 T2 T3 T4 1 0,4,8,12,16,20 1,5,9,13,17,21 2,6,10,14,18,22 3,7,11,15,19,23 2 0,1,8,9,16,17 2,3,9,10,18,19 4,5,11,12,20,21 6,7,13,14,22,23 3 0,1,2,12,13,14 3,4,5,15,16,17 6,7,8,18,19,20 9,10,11,21,22,23 4 0,1,2,3,16,17,18,19 4,5,6,7,20,21,22,23 8,9,10,11 12,13,14,15 38

39 Dynamic Scheduling Iterations are divided into chunks and assigned to threads dynamically. Each thread executes a chunk, and when done, requests another chunk from the runtime system. Although each chunk contains the same number of iterations, chunks may have different execution times. Example: sum = 0.0;! for(i=0; i<=n; i++)! sum += f(i) double f(int i){!! int j, start = i*(i+1), finish = start+i;!! double return_val = 0.0;!! for(j=start; j<=finish; j++){!!! return_val += sin(j);!! }!! return return_val;! } 39

40 Guided Scheduling T1 T2 T3 T4 T4 T3 T3 T2 T1 Similar to dynamic scheduling, except that chunk size decreases as the execution progresses. At the dynamic scheduling decision, the chunk size is equal to 1/p of the remaining iterations, where p is the number of threads. Can specify the smallest chunksize (except possibly the last). The default smallest chunksize is 1. 40

41 Exercise What would be the assignment of iterations to threads for a guided schedule in a parallel for loop with 1000 iterations and 2 threads. The sequence in which threads 0 and 1 request more work is given by: 0,1,1,1,0,1,0,1,1,1,1. Chunk Thread [1-500] 0 [ ] 1 [ ] 1 [ ] 1 [ ] 0 [ ] 1 [ ] 0 [ ] 1 [ ]

42 Data Scoping Types of variables: Shared. Private. Firstprivate: private but initialized to its value before entering the region. Lastprivate: private but on exit, value in master is last value in thread. Default: default type for all variables in the thread. Reduction: variables declared in enclosing context, are private in the parallel sections, but reduced upon exit using the specified operator (e.g. +, *, -, &,, ˆ, &&, ). 42

43 Example Internal product of two vectors a and b. main(){!! int i, n;!! float a[100], b[100], result;!! n = 100;!! result = 0.0;!! for(i=0; i<n; i++){!!! a[i] =... ; b[i] =... ;!! }!! #pragma omp parallel for default(shared) private(i) reduction(+:result)!! for (i=0; i < n; i++)!!! result = result + (a[i] * b[i]);!! printf("final result= %f\n",result);! } 43

44 Exercise Use a loop pragma to implement the matrix multiplication algorithm in OpenMP. for (i=0; i<n; i++)! for (j=0; j<n; j++)! for (k=0; k<n; k++)! C[i][j] += A[i][k]*B[k][j];! #pragma omp parallel for! for (i=0; i<n; i++)! for (j=0; j<n; j++)! for (k=0; k<n; k++)! C[i][j] += A[i][k]*B[k][j];! for (i=0; i<n; i++)! #pragma omp parallel for! for (j=0; j<n; j++)! for (k=0; k<n; k++)! C[i][j] += A[i][k]*B[k][j];! 44

45 Exercise Implement in OpenMP the parallel sum algorithm. shared float v[n];! int value;!! for(i=1; i<=log(n); i++)! if(id mod 2 i == 2 i -1)! value = v[id] + v[id-2 i-1 ] barrier! v[id] = value! barrier 45

46 Exercise (cont.) #pragma omp parallel private(i, nthreads, tid, value, stages)! {!!!! // sum local entries into value!! // getting thread id and number of threads! tid = omp_get_thread_num();! nthreads = omp_get_num_threads();!! stages = (int) log2(nthreads);! for(i=1; i<=stages; i++){! if(tid % (int)pow(2,i) == (int)pow(2,i)-1){! value = vector[tid] + vector[tid-(int)pow(2,i-1)];! }! #pragma omp barrier! vector[tid] = value;! #pragma omp barrier! }! } 46

47 Exercise (cont.) #pragma omp parallel for reduction(+:sum)! for(int i=0; i<n; i++){!! sum += vector[i];! } 47

48 Sections Define independent pieces of code. May combine the parallel and sections pragmas (as with for). If there are more threads than sections, then some are idle. If there are fewer threads than sections, then some sections are serialized. #define N 1000! main(){!! int i;!! float a[n], b[n], c[n];!! for (i=0; i < N; i++)!!! a[i] = b[i] =... ;!! #pragma omp parallel shared(a,b,c) private(i)!! {...!!! #pragma omp sections!!! {!!!! #pragma omp section!!!! {!!!!! for (i=0; i < N/2; i++)!!!!!! c[i] = a[i] + b[i];!!!! }!!!! #pragma omp section!!!! {!!!!! for (i=n/2; i < N; i++)!!!!!! c[i] = a[i] + b[i];!!!! }!!! } /* end of sections */!!...!! } /* end of parallel section */! } 48

49 Single and Master The single directive serializes a section of code within a parallel region. More convenient and efficient than terminating a parallel region and starting it later. Typically used to serialize a small section of the code that s not thread safe. Threads in the team that do not execute the single directive, wait at the end of the enclosed code block, unless a nowait clause is specified. The master directive is the same as the single directive except that: The serial code is executed by the master thread. The other threads skip the master section, but do not wait for the master thread to finish executing it. 49

50 Atomic A critical section composed of one statement (expression) of the form: x++, x--, ++x, x, or x <op> = <expression>; <op> can be +,*,-,/,&,^,,<<, or >>! Compiler will use hardware atomic instructions. Is more efficient than using the critical section directive. Example: #pragma omp parallel for shared(sum)! for(i = 0; i < n; i++){!! value = f(a[i]);!! #pragma omp atomic!! sum = sum + value;! } 50

51 Task Parallelism Pragma task spawns a task (non-blocking). Pragma taskwait wait for all spawned tasks. Pragmas for task parallelism must be used inside a parallel section. int fibo(int n){! int fn1, fn2;! if (n<2)! return n;! else {! #pragma omp task! fn1 = fibo(n-1);! #pragma omp task! fn2 = fibo(n-2);! #pragma omp taskwait! return fn1 + fn2;! }! }!! int main() {! #pragma omp parallel shared(n)! {! #pragma omp single!! fibo(n);! }! } 51

52 Summary OpenMP is the de facto standard for sharedmemory programming in HPC. It is a wrapper for multithreading libraries (such as PThreads). OpenMP combines directives to the compiler and parallelization by the programmer. OpenMP embraces incremental parallelization: The sequential version of an OpenMP program is always available. 52

53 Acknowledgements Lecture notes by Rami Melhem. An Introduction to Parallel Programming by Peter S. Pacheco. Morgan-Kaufmann,

Introduc)on to OpenMP

Introduc)on to OpenMP Introduc)on to OpenMP Chapter 5.1-5. Bryan Mills, PhD Spring 2017 OpenMP An API for shared-memory parallel programming. MP = multiprocessing Designed for systems in which each thread or process can potentially

More information

Multithreading in C with OpenMP

Multithreading in C with OpenMP Multithreading in C with OpenMP ICS432 - Spring 2017 Concurrent and High-Performance Programming Henri Casanova (henric@hawaii.edu) Pthreads are good and bad! Multi-threaded programming in C with Pthreads

More information

CS691/SC791: Parallel & Distributed Computing

CS691/SC791: Parallel & Distributed Computing CS691/SC791: Parallel & Distributed Computing Introduction to OpenMP 1 Contents Introduction OpenMP Programming Model and Examples OpenMP programming examples Task parallelism. Explicit thread synchronization.

More information

OpenMP Introduction. CS 590: High Performance Computing. OpenMP. A standard for shared-memory parallel programming. MP = multiprocessing

OpenMP Introduction. CS 590: High Performance Computing. OpenMP. A standard for shared-memory parallel programming. MP = multiprocessing CS 590: High Performance Computing OpenMP Introduction Fengguang Song Department of Computer Science IUPUI OpenMP A standard for shared-memory parallel programming. MP = multiprocessing Designed for systems

More information

OpenMP Algoritmi e Calcolo Parallelo. Daniele Loiacono

OpenMP Algoritmi e Calcolo Parallelo. Daniele Loiacono OpenMP Algoritmi e Calcolo Parallelo References Useful references Using OpenMP: Portable Shared Memory Parallel Programming, Barbara Chapman, Gabriele Jost and Ruud van der Pas OpenMP.org http://openmp.org/

More information

Lecture 4: OpenMP Open Multi-Processing

Lecture 4: OpenMP Open Multi-Processing 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

More information

Introduction to OpenMP. OpenMP basics OpenMP directives, clauses, and library routines

Introduction to OpenMP. OpenMP basics OpenMP directives, clauses, and library routines Introduction to OpenMP Introduction OpenMP basics OpenMP directives, clauses, and library routines What is OpenMP? What does OpenMP stands for? What does OpenMP stands for? Open specifications for Multi

More information

Topics. Introduction. Shared Memory Parallelization. Example. Lecture 11. OpenMP Execution Model Fork-Join model 5/15/2012. Introduction OpenMP

Topics. Introduction. Shared Memory Parallelization. Example. Lecture 11. OpenMP Execution Model Fork-Join model 5/15/2012. Introduction OpenMP Topics Lecture 11 Introduction OpenMP Some Examples Library functions Environment variables 1 2 Introduction Shared Memory Parallelization OpenMP is: a standard for parallel programming in C, C++, and

More information

CS 470 Spring Mike Lam, Professor. OpenMP

CS 470 Spring Mike Lam, Professor. OpenMP CS 470 Spring 2018 Mike Lam, Professor OpenMP OpenMP Programming language extension Compiler support required "Open Multi-Processing" (open standard; latest version is 4.5) Automatic thread-level parallelism

More information

CS 470 Spring Mike Lam, Professor. OpenMP

CS 470 Spring Mike Lam, Professor. OpenMP CS 470 Spring 2017 Mike Lam, Professor OpenMP OpenMP Programming language extension Compiler support required "Open Multi-Processing" (open standard; latest version is 4.5) Automatic thread-level parallelism

More information

EPL372 Lab Exercise 5: Introduction to OpenMP

EPL372 Lab Exercise 5: Introduction to OpenMP EPL372 Lab Exercise 5: Introduction to OpenMP References: https://computing.llnl.gov/tutorials/openmp/ http://openmp.org/wp/openmp-specifications/ http://openmp.org/mp-documents/openmp-4.0-c.pdf http://openmp.org/mp-documents/openmp4.0.0.examples.pdf

More information

Introduction to OpenMP.

Introduction to OpenMP. Introduction to OpenMP www.openmp.org Motivation Parallelize the following code using threads: for (i=0; i

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Ricardo Fonseca https://sites.google.com/view/rafonseca2017/ Outline Shared Memory Programming OpenMP Fork-Join Model Compiler Directives / Run time library routines Compiling and

More information

Parallel Programming

Parallel Programming Parallel Programming OpenMP Nils Moschüring PhD Student (LMU) Nils Moschüring PhD Student (LMU), OpenMP 1 1 Overview What is parallel software development Why do we need parallel computation? Problems

More information

ECE 574 Cluster Computing Lecture 10

ECE 574 Cluster Computing Lecture 10 ECE 574 Cluster Computing Lecture 10 Vince Weaver http://www.eece.maine.edu/~vweaver vincent.weaver@maine.edu 1 October 2015 Announcements Homework #4 will be posted eventually 1 HW#4 Notes How granular

More information

MPI and OpenMP (Lecture 25, cs262a) Ion Stoica, UC Berkeley November 19, 2016

MPI and OpenMP (Lecture 25, cs262a) Ion Stoica, UC Berkeley November 19, 2016 MPI and OpenMP (Lecture 25, cs262a) Ion Stoica, UC Berkeley November 19, 2016 Message passing vs. Shared memory Client Client Client Client send(msg) recv(msg) send(msg) recv(msg) MSG MSG MSG IPC Shared

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Ekpe Okorafor School of Parallel Programming & Parallel Architecture for HPC ICTP October, 2014 A little about me! PhD Computer Engineering Texas A&M University Computer Science

More information

Parallel Programming with OpenMP. CS240A, T. Yang

Parallel Programming with OpenMP. CS240A, T. Yang Parallel Programming with OpenMP CS240A, T. Yang 1 A Programmer s View of OpenMP What is OpenMP? Open specification for Multi-Processing Standard API for defining multi-threaded shared-memory programs

More information

Parallel and Distributed Computing

Parallel and Distributed Computing Concurrent Programming with OpenMP Rodrigo Miragaia Rodrigues MSc in Information Systems and Computer Engineering DEA in Computational Engineering CS Department (DEI) Instituto Superior Técnico October

More information

Concurrent Programming with OpenMP

Concurrent Programming with OpenMP Concurrent Programming with OpenMP Parallel and Distributed Computing Department of Computer Science and Engineering (DEI) Instituto Superior Técnico October 11, 2012 CPD (DEI / IST) Parallel and Distributed

More information

Multi-core Architecture and Programming

Multi-core Architecture and Programming Multi-core Architecture and Programming Yang Quansheng( 杨全胜 ) http://www.njyangqs.com School of Computer Science & Engineering 1 http://www.njyangqs.com Programming with OpenMP Content What is PpenMP Parallel

More information

Parallel Computing Notes Topic: Notes on Hybrid MPI + OpenMP Programming

Parallel Computing Notes Topic: Notes on Hybrid MPI + OpenMP Programming Parallel Computing Notes Topic: Notes on Hybrid MPI + OpenMP Programming Mary Thomas Department of Computer Science Computational Science Research Center (CSRC) San Diego State University (SDSU) Last Update:

More information

Distributed Systems + Middleware Concurrent Programming with OpenMP

Distributed Systems + Middleware Concurrent Programming with OpenMP Distributed Systems + Middleware Concurrent Programming with OpenMP Gianpaolo Cugola Dipartimento di Elettronica e Informazione Politecnico, Italy cugola@elet.polimi.it http://home.dei.polimi.it/cugola

More information

Shared Memory Programming Model

Shared Memory Programming Model Shared Memory Programming Model Ahmed El-Mahdy and Waleed Lotfy What is a shared memory system? Activity! Consider the board as a shared memory Consider a sheet of paper in front of you as a local cache

More information

Shared Memory Parallelism - OpenMP

Shared Memory Parallelism - OpenMP Shared Memory Parallelism - OpenMP Sathish Vadhiyar Credits/Sources: OpenMP C/C++ standard (openmp.org) OpenMP tutorial (http://www.llnl.gov/computing/tutorials/openmp/#introduction) OpenMP sc99 tutorial

More information

OpenMP 2. CSCI 4850/5850 High-Performance Computing Spring 2018

OpenMP 2. CSCI 4850/5850 High-Performance Computing Spring 2018 OpenMP 2 CSCI 4850/5850 High-Performance Computing Spring 2018 Tae-Hyuk (Ted) Ahn Department of Computer Science Program of Bioinformatics and Computational Biology Saint Louis University Learning Objectives

More information

Introduction to OpenMP

Introduction to OpenMP Christian Terboven, Dirk Schmidl IT Center, RWTH Aachen University Member of the HPC Group terboven,schmidl@itc.rwth-aachen.de IT Center der RWTH Aachen University History De-facto standard for Shared-Memory

More information

Alfio Lazzaro: Introduction to OpenMP

Alfio Lazzaro: Introduction to OpenMP First INFN International School on Architectures, tools and methodologies for developing efficient large scale scientific computing applications Ce.U.B. Bertinoro Italy, 12 17 October 2009 Alfio Lazzaro:

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Le Yan Scientific computing consultant User services group High Performance Computing @ LSU Goals Acquaint users with the concept of shared memory parallelism Acquaint users with

More information

OpenMP examples. Sergeev Efim. Singularis Lab, Ltd. Senior software engineer

OpenMP examples. Sergeev Efim. Singularis Lab, Ltd. Senior software engineer OpenMP examples Sergeev Efim Senior software engineer Singularis Lab, Ltd. OpenMP Is: An Application Program Interface (API) that may be used to explicitly direct multi-threaded, shared memory parallelism.

More information

Shared Memory programming paradigm: openmp

Shared Memory programming paradigm: openmp IPM School of Physics Workshop on High Performance Computing - HPC08 Shared Memory programming paradigm: openmp Luca Heltai Stefano Cozzini SISSA - Democritos/INFM

More information

EE/CSCI 451 Introduction to Parallel and Distributed Computation. Discussion #4 2/3/2017 University of Southern California

EE/CSCI 451 Introduction to Parallel and Distributed Computation. Discussion #4 2/3/2017 University of Southern California EE/CSCI 451 Introduction to Parallel and Distributed Computation Discussion #4 2/3/2017 University of Southern California 1 USC HPCC Access Compile Submit job OpenMP Today s topic What is OpenMP OpenMP

More information

COSC 6374 Parallel Computation. Introduction to OpenMP. Some slides based on material by Barbara Chapman (UH) and Tim Mattson (Intel)

COSC 6374 Parallel Computation. Introduction to OpenMP. Some slides based on material by Barbara Chapman (UH) and Tim Mattson (Intel) COSC 6374 Parallel Computation Introduction to OpenMP Some slides based on material by Barbara Chapman (UH) and Tim Mattson (Intel) Edgar Gabriel Fall 2015 OpenMP Provides thread programming model at a

More information

Shared Memory Parallelism using OpenMP

Shared Memory Parallelism using OpenMP Indian Institute of Science Bangalore, India भ रत य व ज ञ न स स थ न ब गल र, भ रत SE 292: High Performance Computing [3:0][Aug:2014] Shared Memory Parallelism using OpenMP Yogesh Simmhan Adapted from: o

More information

A brief introduction to OpenMP

A brief introduction to OpenMP A brief introduction to OpenMP Alejandro Duran Barcelona Supercomputing Center Outline 1 Introduction 2 Writing OpenMP programs 3 Data-sharing attributes 4 Synchronization 5 Worksharings 6 Task parallelism

More information

Parallel programming using OpenMP

Parallel programming using OpenMP Parallel programming using OpenMP Computer Architecture J. Daniel García Sánchez (coordinator) David Expósito Singh Francisco Javier García Blas ARCOS Group Computer Science and Engineering Department

More information

Module 10: Open Multi-Processing Lecture 19: What is Parallelization? The Lecture Contains: What is Parallelization? Perfectly Load-Balanced Program

Module 10: Open Multi-Processing Lecture 19: What is Parallelization? The Lecture Contains: What is Parallelization? Perfectly Load-Balanced Program The Lecture Contains: What is Parallelization? Perfectly Load-Balanced Program Amdahl's Law About Data What is Data Race? Overview to OpenMP Components of OpenMP OpenMP Programming Model OpenMP Directives

More information

OpenMP Overview. in 30 Minutes. Christian Terboven / Aachen, Germany Stand: Version 2.

OpenMP Overview. in 30 Minutes. Christian Terboven / Aachen, Germany Stand: Version 2. OpenMP Overview in 30 Minutes Christian Terboven 06.12.2010 / Aachen, Germany Stand: 03.12.2010 Version 2.3 Rechen- und Kommunikationszentrum (RZ) Agenda OpenMP: Parallel Regions,

More information

OpenMP I. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS16/17. HPAC, RWTH Aachen

OpenMP I. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS16/17. HPAC, RWTH Aachen OpenMP I Diego Fabregat-Traver and Prof. Paolo Bientinesi HPAC, RWTH Aachen fabregat@aices.rwth-aachen.de WS16/17 OpenMP References Using OpenMP: Portable Shared Memory Parallel Programming. The MIT Press,

More information

OpenMP. OpenMP. Portable programming of shared memory systems. It is a quasi-standard. OpenMP-Forum API for Fortran and C/C++

OpenMP. OpenMP. Portable programming of shared memory systems. It is a quasi-standard. OpenMP-Forum API for Fortran and C/C++ OpenMP OpenMP Portable programming of shared memory systems. It is a quasi-standard. OpenMP-Forum 1997-2002 API for Fortran and C/C++ directives runtime routines environment variables www.openmp.org 1

More information

Parallelising Scientific Codes Using OpenMP. Wadud Miah Research Computing Group

Parallelising Scientific Codes Using OpenMP. Wadud Miah Research Computing Group Parallelising Scientific Codes Using OpenMP Wadud Miah Research Computing Group Software Performance Lifecycle Scientific Programming Early scientific codes were mainly sequential and were executed on

More information

EE/CSCI 451: Parallel and Distributed Computation

EE/CSCI 451: Parallel and Distributed Computation EE/CSCI 451: Parallel and Distributed Computation Lecture #7 2/5/2017 Xuehai Qian Xuehai.qian@usc.edu http://alchem.usc.edu/portal/xuehaiq.html University of Southern California 1 Outline From last class

More information

Parallel Computing Parallel Programming Languages Hwansoo Han

Parallel Computing Parallel Programming Languages Hwansoo Han Parallel Computing Parallel Programming Languages Hwansoo Han Parallel Programming Practice Current Start with a parallel algorithm Implement, keeping in mind Data races Synchronization Threading syntax

More information

HPC Practical Course Part 3.1 Open Multi-Processing (OpenMP)

HPC Practical Course Part 3.1 Open Multi-Processing (OpenMP) HPC Practical Course Part 3.1 Open Multi-Processing (OpenMP) V. Akishina, I. Kisel, G. Kozlov, I. Kulakov, M. Pugach, M. Zyzak Goethe University of Frankfurt am Main 2015 Task Parallelism Parallelization

More information

Shared Memory Programming with OpenMP

Shared Memory Programming with OpenMP Shared Memory Programming with OpenMP Moreno Marzolla Dip. di Informatica Scienza e Ingegneria (DISI) Università di Bologna moreno.marzolla@unibo.it Copyright 2013, 2014, 2017 2019 Moreno Marzolla, Università

More information

COMP4510 Introduction to Parallel Computation. Shared Memory and OpenMP. Outline (cont d) Shared Memory and OpenMP

COMP4510 Introduction to Parallel Computation. Shared Memory and OpenMP. Outline (cont d) Shared Memory and OpenMP COMP4510 Introduction to Parallel Computation Shared Memory and OpenMP Thanks to Jon Aronsson (UofM HPC consultant) for some of the material in these notes. Outline (cont d) Shared Memory and OpenMP Including

More information

CSL 860: Modern Parallel

CSL 860: Modern Parallel CSL 860: Modern Parallel Computation Hello OpenMP #pragma omp parallel { // I am now thread iof n switch(omp_get_thread_num()) { case 0 : blah1.. case 1: blah2.. // Back to normal Parallel Construct Extremely

More information

Computer Architecture

Computer Architecture Jens Teubner Computer Architecture Summer 2016 1 Computer Architecture Jens Teubner, TU Dortmund jens.teubner@cs.tu-dortmund.de Summer 2016 Jens Teubner Computer Architecture Summer 2016 2 Part I Programming

More information

Introduction to Standard OpenMP 3.1

Introduction to Standard OpenMP 3.1 Introduction to Standard OpenMP 3.1 Massimiliano Culpo - m.culpo@cineca.it Gian Franco Marras - g.marras@cineca.it CINECA - SuperComputing Applications and Innovation Department 1 / 59 Outline 1 Introduction

More information

OpenMP Programming. Prof. Thomas Sterling. High Performance Computing: Concepts, Methods & Means

OpenMP Programming. Prof. Thomas Sterling. High Performance Computing: Concepts, Methods & Means High Performance Computing: Concepts, Methods & Means OpenMP Programming Prof. Thomas Sterling Department of Computer Science Louisiana State University February 8 th, 2007 Topics Introduction Overview

More information

OpenMP. Dr. William McDoniel and Prof. Paolo Bientinesi WS17/18. HPAC, RWTH Aachen

OpenMP. Dr. William McDoniel and Prof. Paolo Bientinesi WS17/18. HPAC, RWTH Aachen OpenMP Dr. William McDoniel and Prof. Paolo Bientinesi HPAC, RWTH Aachen mcdoniel@aices.rwth-aachen.de WS17/18 Loop construct - Clauses #pragma omp for [clause [, clause]...] The following clauses apply:

More information

OpenMP. António Abreu. Instituto Politécnico de Setúbal. 1 de Março de 2013

OpenMP. António Abreu. Instituto Politécnico de Setúbal. 1 de Março de 2013 OpenMP António Abreu Instituto Politécnico de Setúbal 1 de Março de 2013 António Abreu (Instituto Politécnico de Setúbal) OpenMP 1 de Março de 2013 1 / 37 openmp what? It s an Application Program Interface

More information

OpenMP. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS16/17. HPAC, RWTH Aachen

OpenMP. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS16/17. HPAC, RWTH Aachen OpenMP Diego Fabregat-Traver and Prof. Paolo Bientinesi HPAC, RWTH Aachen fabregat@aices.rwth-aachen.de WS16/17 Worksharing constructs To date: #pragma omp parallel created a team of threads We distributed

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Christian Terboven 10.04.2013 / Darmstadt, Germany Stand: 06.03.2013 Version 2.3 Rechen- und Kommunikationszentrum (RZ) History De-facto standard for

More information

OpenMP. Today s lecture. Scott B. Baden / CSE 160 / Wi '16

OpenMP. Today s lecture. Scott B. Baden / CSE 160 / Wi '16 Lecture 8 OpenMP Today s lecture 7 OpenMP A higher level interface for threads programming http://www.openmp.org Parallelization via source code annotations All major compilers support it, including gnu

More information

Programming Shared Memory Systems with OpenMP Part I. Book

Programming Shared Memory Systems with OpenMP Part I. Book Programming Shared Memory Systems with OpenMP Part I Instructor Dr. Taufer Book Parallel Programming in OpenMP by Rohit Chandra, Leo Dagum, Dave Kohr, Dror Maydan, Jeff McDonald, Ramesh Menon 2 1 Machine

More information

Data Environment: Default storage attributes

Data Environment: Default storage attributes COSC 6374 Parallel Computation Introduction to OpenMP(II) Some slides based on material by Barbara Chapman (UH) and Tim Mattson (Intel) Edgar Gabriel Fall 2014 Data Environment: Default storage attributes

More information

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Thread-Level Parallelism (TLP) and OpenMP

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Thread-Level Parallelism (TLP) and OpenMP CS 61C: Great Ideas in Computer Architecture (Machine Structures) Thread-Level Parallelism (TLP) and OpenMP Instructors: John Wawrzynek & Vladimir Stojanovic http://inst.eecs.berkeley.edu/~cs61c/ Review

More information

Introduction to OpenMP. Martin Čuma Center for High Performance Computing University of Utah

Introduction to OpenMP. Martin Čuma Center for High Performance Computing University of Utah Introduction to OpenMP Martin Čuma Center for High Performance Computing University of Utah mcuma@chpc.utah.edu Overview Quick introduction. Parallel loops. Parallel loop directives. Parallel sections.

More information

Mango DSP Top manufacturer of multiprocessing video & imaging solutions.

Mango DSP Top manufacturer of multiprocessing video & imaging solutions. 1 of 11 3/3/2005 10:50 AM Linux Magazine February 2004 C++ Parallel Increase application performance without changing your source code. Mango DSP Top manufacturer of multiprocessing video & imaging solutions.

More information

CMSC 714 Lecture 4 OpenMP and UPC. Chau-Wen Tseng (from A. Sussman)

CMSC 714 Lecture 4 OpenMP and UPC. Chau-Wen Tseng (from A. Sussman) CMSC 714 Lecture 4 OpenMP and UPC Chau-Wen Tseng (from A. Sussman) Programming Model Overview Message passing (MPI, PVM) Separate address spaces Explicit messages to access shared data Send / receive (MPI

More information

Programming with OpenMP*

Programming with OpenMP* Objectives At the completion of this module you will be able to Thread serial code with basic OpenMP pragmas Use OpenMP synchronization pragmas to coordinate thread execution and memory access 2 Agenda

More information

Announcements. Scott B. Baden / CSE 160 / Wi '16 2

Announcements. Scott B. Baden / CSE 160 / Wi '16 2 Lecture 8 Announcements Scott B. Baden / CSE 160 / Wi '16 2 Recapping from last time: Minimal barrier synchronization in odd/even sort Global bool AllDone; for (s = 0; s < MaxIter; s++) { barr.sync();

More information

High Performance Computing: Tools and Applications

High Performance Computing: Tools and Applications High Performance Computing: Tools and Applications Edmond Chow School of Computational Science and Engineering Georgia Institute of Technology Lecture 2 OpenMP Shared address space programming High-level

More information

Introduction to parallel computing. Seminar Organization

Introduction to parallel computing. Seminar Organization Introduction to parallel computing Rami Melhem Department of Computer Science 1 Seminar Organization 1) Introductory lectures (probably 4) 2) aper presentations by students (2/3 per short/long class) -

More information

Parallel Programming in C with MPI and OpenMP

Parallel Programming in C with MPI and OpenMP Parallel Programming in C with MPI and OpenMP Michael J. Quinn Chapter 17 Shared-memory Programming 1 Outline n OpenMP n Shared-memory model n Parallel for loops n Declaring private variables n Critical

More information

OpenMP - II. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS15/16. HPAC, RWTH Aachen

OpenMP - II. Diego Fabregat-Traver and Prof. Paolo Bientinesi WS15/16. HPAC, RWTH Aachen OpenMP - II Diego Fabregat-Traver and Prof. Paolo Bientinesi HPAC, RWTH Aachen fabregat@aices.rwth-aachen.de WS15/16 OpenMP References Using OpenMP: Portable Shared Memory Parallel Programming. The MIT

More information

Session 4: Parallel Programming with OpenMP

Session 4: Parallel Programming with OpenMP Session 4: Parallel Programming with OpenMP Xavier Martorell Barcelona Supercomputing Center Agenda Agenda 10:00-11:00 OpenMP fundamentals, parallel regions 11:00-11:30 Worksharing constructs 11:30-12:00

More information

Parallel Programming using OpenMP

Parallel Programming using OpenMP 1 Parallel Programming using OpenMP Mike Bailey mjb@cs.oregonstate.edu openmp.pptx OpenMP Multithreaded Programming 2 OpenMP stands for Open Multi-Processing OpenMP is a multi-vendor (see next page) standard

More information

Parallel Programming using OpenMP

Parallel Programming using OpenMP 1 OpenMP Multithreaded Programming 2 Parallel Programming using OpenMP OpenMP stands for Open Multi-Processing OpenMP is a multi-vendor (see next page) standard to perform shared-memory multithreading

More information

OpenMP, Part 2. EAS 520 High Performance Scientific Computing. University of Massachusetts Dartmouth. Spring 2015

OpenMP, Part 2. EAS 520 High Performance Scientific Computing. University of Massachusetts Dartmouth. Spring 2015 OpenMP, Part 2 EAS 520 High Performance Scientific Computing University of Massachusetts Dartmouth Spring 2015 References This presentation is almost an exact copy of Dartmouth College's openmp tutorial.

More information

Parallel Computing. Lecture 13: OpenMP - I

Parallel Computing. Lecture 13: OpenMP - I CSCI-UA.0480-003 Parallel Computing Lecture 13: OpenMP - I Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Small and Easy Motivation #include #include int main() {

More information

by system default usually a thread per CPU or core using the environment variable OMP_NUM_THREADS from within the program by using function call

by system default usually a thread per CPU or core using the environment variable OMP_NUM_THREADS from within the program by using function call OpenMP Syntax The OpenMP Programming Model Number of threads are determined by system default usually a thread per CPU or core using the environment variable OMP_NUM_THREADS from within the program by

More information

OpenMP 4. CSCI 4850/5850 High-Performance Computing Spring 2018

OpenMP 4. CSCI 4850/5850 High-Performance Computing Spring 2018 OpenMP 4 CSCI 4850/5850 High-Performance Computing Spring 2018 Tae-Hyuk (Ted) Ahn Department of Computer Science Program of Bioinformatics and Computational Biology Saint Louis University Learning Objectives

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Le Yan HPC Consultant User Services Goals Acquaint users with the concept of shared memory parallelism Acquaint users with the basics of programming with OpenMP Discuss briefly the

More information

Parallel Sort and More Open MP

Parallel Sort and More Open MP Parallel Sort and More Open MP Chapter 5.6 Bryan Mills, PhD "Bubbling Up" the Largest Element Traverse a collec+on of elements Move from the front to the end Bubble the largest value to the end using pair-

More information

Allows program to be incrementally parallelized

Allows program to be incrementally parallelized Basic OpenMP What is OpenMP An open standard for shared memory programming in C/C+ + and Fortran supported by Intel, Gnu, Microsoft, Apple, IBM, HP and others Compiler directives and library support OpenMP

More information

Advanced C Programming Winter Term 2008/09. Guest Lecture by Markus Thiele

Advanced C Programming Winter Term 2008/09. Guest Lecture by Markus Thiele Advanced C Programming Winter Term 2008/09 Guest Lecture by Markus Thiele Lecture 14: Parallel Programming with OpenMP Motivation: Why parallelize? The free lunch is over. Herb

More information

Shared Memory Programming with OpenMP

Shared Memory Programming with OpenMP Shared Memory Programming with OpenMP Moreno Marzolla Dip. di Informatica Scienza e Ingegneria (DISI) Università di Bologna moreno.marzolla@unibo.it OpenMP Programming 2 Credits Peter Pacheco, Dept. of

More information

Shared Memory Programming with OpenMP

Shared Memory Programming with OpenMP Shared Memory Programming with OpenMP (An UHeM Training) Süha Tuna Informatics Institute, Istanbul Technical University February 12th, 2016 2 Outline - I Shared Memory Systems Threaded Programming Model

More information

Parallel Programming with OpenMP. CS240A, T. Yang, 2013 Modified from Demmel/Yelick s and Mary Hall s Slides

Parallel Programming with OpenMP. CS240A, T. Yang, 2013 Modified from Demmel/Yelick s and Mary Hall s Slides Parallel Programming with OpenMP CS240A, T. Yang, 203 Modified from Demmel/Yelick s and Mary Hall s Slides Introduction to OpenMP What is OpenMP? Open specification for Multi-Processing Standard API for

More information

[Potentially] Your first parallel application

[Potentially] Your first parallel application [Potentially] Your first parallel application Compute the smallest element in an array as fast as possible small = array[0]; for( i = 0; i < N; i++) if( array[i] < small ) ) small = array[i] 64-bit Intel

More information

Little Motivation Outline Introduction OpenMP Architecture Working with OpenMP Future of OpenMP End. OpenMP. Amasis Brauch German University in Cairo

Little Motivation Outline Introduction OpenMP Architecture Working with OpenMP Future of OpenMP End. OpenMP. Amasis Brauch German University in Cairo OpenMP Amasis Brauch German University in Cairo May 4, 2010 Simple Algorithm 1 void i n c r e m e n t e r ( short a r r a y ) 2 { 3 long i ; 4 5 for ( i = 0 ; i < 1000000; i ++) 6 { 7 a r r a y [ i ]++;

More information

OpenMP Tutorial. Seung-Jai Min. School of Electrical and Computer Engineering Purdue University, West Lafayette, IN

OpenMP Tutorial. Seung-Jai Min. School of Electrical and Computer Engineering Purdue University, West Lafayette, IN OpenMP Tutorial Seung-Jai Min (smin@purdue.edu) School of Electrical and Computer Engineering Purdue University, West Lafayette, IN 1 Parallel Programming Standards Thread Libraries - Win32 API / Posix

More information

Programming with Shared Memory PART II. HPC Fall 2007 Prof. Robert van Engelen

Programming with Shared Memory PART II. HPC Fall 2007 Prof. Robert van Engelen Programming with Shared Memory PART II HPC Fall 2007 Prof. Robert van Engelen Overview Parallel programming constructs Dependence analysis OpenMP Autoparallelization Further reading HPC Fall 2007 2 Parallel

More information

Introduction to OpenMP. Rogelio Long CS 5334/4390 Spring 2014 February 25 Class

Introduction to OpenMP. Rogelio Long CS 5334/4390 Spring 2014 February 25 Class Introduction to OpenMP Rogelio Long CS 5334/4390 Spring 2014 February 25 Class Acknowledgment These slides are adapted from the Lawrence Livermore OpenMP Tutorial by Blaise Barney at https://computing.llnl.gov/tutorials/openmp/

More information

Programming with Shared Memory PART II. HPC Fall 2012 Prof. Robert van Engelen

Programming with Shared Memory PART II. HPC Fall 2012 Prof. Robert van Engelen Programming with Shared Memory PART II HPC Fall 2012 Prof. Robert van Engelen Overview Sequential consistency Parallel programming constructs Dependence analysis OpenMP Autoparallelization Further reading

More information

OpenMP. Application Program Interface. CINECA, 14 May 2012 OpenMP Marco Comparato

OpenMP. Application Program Interface. CINECA, 14 May 2012 OpenMP Marco Comparato OpenMP Application Program Interface Introduction Shared-memory parallelism in C, C++ and Fortran compiler directives library routines environment variables Directives single program multiple data (SPMD)

More information

Parallel Numerical Algorithms

Parallel Numerical Algorithms Parallel Numerical Algorithms http://sudalab.is.s.u-tokyo.ac.jp/~reiji/pna16/ [ 8 ] OpenMP Parallel Numerical Algorithms / IST / UTokyo 1 PNA16 Lecture Plan General Topics 1. Architecture and Performance

More information

Computational Mathematics

Computational Mathematics Computational Mathematics Hamid Sarbazi-Azad Department of Computer Engineering Sharif University of Technology e-mail: azad@sharif.edu OpenMP Work-sharing Instructor PanteA Zardoshti Department of Computer

More information

Introduction to OpenMP. Martin Čuma Center for High Performance Computing University of Utah

Introduction to OpenMP. Martin Čuma Center for High Performance Computing University of Utah Introduction to OpenMP Martin Čuma Center for High Performance Computing University of Utah mcuma@chpc.utah.edu Overview Quick introduction. Parallel loops. Parallel loop directives. Parallel sections.

More information

/Users/engelen/Sites/HPC folder/hpc/openmpexamples.c

/Users/engelen/Sites/HPC folder/hpc/openmpexamples.c /* Subset of these examples adapted from: 1. http://www.llnl.gov/computing/tutorials/openmp/exercise.html 2. NAS benchmarks */ #include #include #ifdef _OPENMP #include #endif

More information

DPHPC: Introduction to OpenMP Recitation session

DPHPC: Introduction to OpenMP Recitation session SALVATORE DI GIROLAMO DPHPC: Introduction to OpenMP Recitation session Based on http://openmp.org/mp-documents/intro_to_openmp_mattson.pdf OpenMP An Introduction What is it? A set of compiler directives

More information

Assignment 1 OpenMP Tutorial Assignment

Assignment 1 OpenMP Tutorial Assignment Assignment 1 OpenMP Tutorial Assignment B. Wilkinson and C Ferner: Modification date Aug 5, 2014 Overview In this assignment, you will write and execute run some simple OpenMP programs as a tutorial. First

More information

Parallel Programming in C with MPI and OpenMP

Parallel Programming in C with MPI and OpenMP Parallel Programming in C with MPI and OpenMP Michael J. Quinn Chapter 17 Shared-memory Programming 1 Outline n OpenMP n Shared-memory model n Parallel for loops n Declaring private variables n Critical

More information

Introduction to OpenMP

Introduction to OpenMP Introduction to OpenMP Le Yan Objectives of Training Acquaint users with the concept of shared memory parallelism Acquaint users with the basics of programming with OpenMP Memory System: Shared Memory

More information

15-418, Spring 2008 OpenMP: A Short Introduction

15-418, Spring 2008 OpenMP: A Short Introduction 15-418, Spring 2008 OpenMP: A Short Introduction This is a short introduction to OpenMP, an API (Application Program Interface) that supports multithreaded, shared address space (aka shared memory) parallelism.

More information

19.1. Unit 19. OpenMP Library for Parallelism

19.1. Unit 19. OpenMP Library for Parallelism 19.1 Unit 19 OpenMP Library for Parallelism 19.2 Overview of OpenMP A library or API (Application Programming Interface) for parallelism Requires compiler support (make sure the compiler you use supports

More information

Overview: The OpenMP Programming Model

Overview: The OpenMP Programming Model Overview: The OpenMP Programming Model motivation and overview the parallel directive: clauses, equivalent pthread code, examples the for directive and scheduling of loop iterations Pi example in OpenMP

More information

CS4961 Parallel Programming. Lecture 9: Task Parallelism in OpenMP 9/22/09. Administrative. Mary Hall September 22, 2009.

CS4961 Parallel Programming. Lecture 9: Task Parallelism in OpenMP 9/22/09. Administrative. Mary Hall September 22, 2009. Parallel Programming Lecture 9: Task Parallelism in OpenMP Administrative Programming assignment 1 is posted (after class) Due, Tuesday, September 22 before class - Use the handin program on the CADE machines

More information