CS470/570 Lecture 5 Introduction to OpenMP Compute Pi example OpenMP directives and options.

Slides:



Advertisements
Similar presentations
OpenMP.
Advertisements

Introductions to Parallel Programming Using OpenMP
NewsFlash!! Earth Simulator no longer #1. In slightly less earthshaking news… Homework #1 due date postponed to 10/11.
1 Programming Explicit Thread-level Parallelism  As noted previously, the programmer must specify how to parallelize  But, want path of least effort.
Open[M]ulti[P]rocessing Pthreads: Programmer explicitly define thread behavior openMP: Compiler and system defines thread behavior Pthreads: Library independent.
1 Tuesday, November 07, 2006 “If anything can go wrong, it will.” -Murphy’s Law.
Computer Architecture II 1 Computer architecture II Programming: POSIX Threads OpenMP.
1 ITCS4145/5145, Parallel Programming B. Wilkinson Feb 21, 2012 Programming with Shared Memory Introduction to OpenMP.
CSCI-6964: High Performance Parallel & Distributed Computing (HPDC) AE 216, Mon/Thurs 2-3:20 p.m. Pthreads (reading Chp 7.10) Prof. Chris Carothers Computer.
OpenMPI Majdi Baddourah
A Very Short Introduction to OpenMP Basile Schaeli EPFL – I&C – LSP Vincent Keller EPFL – STI – LIN.
INTEL CONFIDENTIAL OpenMP for Domain Decomposition Introduction to Parallel Programming – Part 5.
CS 470/570 Lecture 7 Dot Product Examples Odd-even transposition sort More OpenMP Directives.
Introduction to OpenMP Introduction OpenMP basics OpenMP directives, clauses, and library routines.
Programming with Shared Memory Introduction to OpenMP
1 Copyright © 2010, Elsevier Inc. All rights Reserved Chapter 5 Shared Memory Programming with OpenMP An Introduction to Parallel Programming Peter Pacheco.
Shared Memory Parallelism - OpenMP Sathish Vadhiyar Credits/Sources: OpenMP C/C++ standard (openmp.org) OpenMP tutorial (
Parallel Programming in Java with Shared Memory Directives.
OMPi: A portable C compiler for OpenMP V2.0 Elias Leontiadis George Tzoumas Vassilios V. Dimakopoulos University of Ioannina.
COM503 Parallel Computer Architecture & Programming
Lecture 5: Shared-memory Computing with Open MP. Shared Memory Computing.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Thread Libraries  Pthreads  Windows.
OpenMP: Open specifications for Multi-Processing What is OpenMP? Join\Fork model Join\Fork model Variables Variables Explicit parallelism Explicit parallelism.
Lecture 8: OpenMP. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism / Implicit parallelism.
O PEN MP (O PEN M ULTI -P ROCESSING ) David Valentine Computer Science Slippery Rock University.
OpenMP – Introduction* *UHEM yaz çalıştayı notlarından derlenmiştir. (uhem.itu.edu.tr)
CS 838: Pervasive Parallelism Introduction to OpenMP Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references.
Hybrid MPI and OpenMP Parallel Programming
Work Replication with Parallel Region #pragma omp parallel { for ( j=0; j
High-Performance Parallel Scientific Computing 2008 Purdue University OpenMP Tutorial Seung-Jai Min School of Electrical and Computer.
Introduction to OpenMP
Lecture 7: POSIX Threads - Pthreads. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Shared Memory Parallelism - OpenMP Sathish Vadhiyar Credits/Sources: OpenMP C/C++ standard (openmp.org) OpenMP tutorial (
Introduction to Pragnesh Patel 1 NICS CSURE th June 2015.
CS/EE 217 GPU Architecture and Parallel Programming Lecture 23: Introduction to OpenACC.
Special Topics in Computer Engineering OpenMP* Essentials * Open Multi-Processing.
Heterogeneous Computing using openMP lecture 2 F21DP Distributed and Parallel Technology Sven-Bodo Scholz.
CPE779: Shared Memory and OpenMP Based on slides by Laxmikant V. Kale and David Padua of the University of Illinois.
COMP7330/7336 Advanced Parallel and Distributed Computing OpenMP: Programming Model Dr. Xiao Qin Auburn University
Heterogeneous Computing using openMP lecture 1 F21DP Distributed and Parallel Technology Sven-Bodo Scholz.
OpenMP – Part 2 * *UHEM yaz çalıştayı notlarından derlenmiştir. (uhem.itu.edu.tr)
1 Programming with Shared Memory - 2 Issues with sharing data ITCS 4145 Parallel Programming B. Wilkinson Jan 22, _Prog_Shared_Memory_II.ppt.
1 ITCS4145 Parallel Programming B. Wilkinson March 23, hybrid-abw.ppt Hybrid Parallel Programming Introduction.
Introduction to OpenMP
Shared Memory Parallelism - OpenMP
Lecture 5: Shared-memory Computing with Open MP
CS427 Multicore Architecture and Parallel Computing
Loop Parallelism and OpenMP CS433 Spring 2001
Open[M]ulti[P]rocessing
Introduction to MPI.
Introduction to OpenMP
September 4, 1997 Parallel Processing (CS 667) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson Parallel Processing.
SHARED MEMORY PROGRAMMING WITH OpenMP
Computer Science Department
Chapter 4: Threads Overview Multithreading Models Thread Libraries
Multi-core CPU Computing Straightforward with OpenMP
Parallel Programming with OpenMP
September 4, 1997 Parallel Processing (CS 730) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson Wed. Jan. 31, 2001 *Parts.
Lab. 3 (May 11th) You may use either cygwin or visual studio for using OpenMP Compiling in cygwin “> gcc –fopenmp ex1.c” will generate a.exe Execute :
September 4, 1997 Parallel Processing (CS 730) Lecture 5: Shared Memory Parallel Programming with OpenMP* Jeremy R. Johnson *Parts of this lecture.
Introduction to High Performance Computing Lecture 20
Programming with Shared Memory Introduction to OpenMP
Introduction to parallelism and the Message Passing Interface
DNA microarrays. Infinite Mixture Model-Based Clustering of DNA Microarray Data Using openMP.
Programming with Shared Memory
Hybrid Parallel Programming
Introduction to OpenMP
Programming with Shared Memory
Hybrid MPI and OpenMP Parallel Programming
Shared-Memory Paradigm & OpenMP
Presentation transcript:

CS470/570 Lecture 5 Introduction to OpenMP Compute Pi example OpenMP directives and options

Introduction to OpenMP A set of compiler directives and library routines to support parallel programming in a share memory architecture Can be used with C, C++ and ForTran A program created with OpenMP starts with a master thread Various directives cause the program to created and execute multiple threads

Introduction to OpenMP Master Thread Additional Threads Execute New Threads created with #pragma omp parallel Threads joined Only master thread remains

Introduction to OpenMp Directives have the following form – #pragma omp construct [clauses] Directives are applied to a structured block of code – A structured block has one entry point (at the top) and one exit point (at the bottom)

Introduction to OpenMp Supports explicit parallelism Programmer needs to specify where parallel threads should be used Programmer needs to think about synchronization issues

Simple Example Sequential algorithm to calculate pi – Find the area under the curve 4/(1+x 2 ) between 0 and 1. – Example of numerical integration Parallelization of the algorithm using OpenMP

Compute Pi

Sequential Algorithm to Computer Pi int main(int argc, char *argv[]) { double midpoint, width, pi, sum; int numIntervals, I; numIntervals = atoi(argv[1]); width = 1.0 / numIntervals; pi = 0.0; for(i = 0; i < numIntervals; i++) { midpoint = (i + 0.5) * width; sum = sum +4.0 / (1.0 + midpoint * midpoint); } pi = width*sum; printf("%1.20f \n", pi); }

Parallelized Algorithm to Computer Pi int main(int argc, char *argv[]) { double midpoint, width, pi, sum; int numIntervals, I; numIntervals = atoi(argv[1]); width = 1.0 / numIntervals; pi = 0.0; #pragma omp parallel for default(shared) private(i, midpoint)reduction(+:sum) for(i = 0; i < numIntervals; i++) { midpoint = (i + 0.5) * width; sum = sum +4.0 / (1.0 + midpoint * midpoint); } pi = width*sum; printf("%1.20f \n", pi); }

OpenMP Directives #pragma omp parallel #pragma omp for #pragma omp sections

#pragma omp parallel Example void printId(int myId) { printf("%d\n", myId); } int main(int argc, char *argv[]) { #pragma omp parallel { printId(omp_get_thread_num()); }

#pragma omp for int main(int argc, char *argv[]) { int i; #pragma omp parallel for num_threads(4) for (i = 0; i < 10; i++) { printf("%d %d\n",omp_get_thread_num(),i); }

#pragma omp sections int main(int argc, char *argv[]) { #pragma omp parallel num_threads(4) { #pragma omp sections { #pragma omp section {printf("%d\n",omp_get_thread_num());} #pragma omp section {printf("%d\n",omp_get_thread_num());} #pragma omp section {printf("%d\n",omp_get_thread_num());} #pragma omp section {printf("%d\n",omp_get_thread_num());} }