cs8803sc_lecture4 - CS8803SC Software and Hardware...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS8803SC Software and Hardware Cooperative Computing Introduction to OpenMP Prof. Hyesoon Kim School of Computer Science Georgia Institute of Technology Today’s Goal Review OpenMP – OpenMP? – Directives and clauses – Work-sharing – Data sharing – Synchronization – Orphaned work-sharing – More directives and clauses – API
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 OpenMP Open standard for scientific parallel programming on symmetric multiprocessor (SMP) system Extensions for Fortran, C and c++ for portable SMP programming Bases on threads, but Higher-level than POSIX threads (Pthreads) Implemented by Compiler Directives Runtime Library (an API) Environment Variables Embedded directives specify – Parallelism Data sharing semantics Work sharing semantics Compiler option required to detect code directives Increasingly popular OpenMP History Primary OpenMP participates – Compaq, HP, IBM, Intel, KAI, SGI, SUN U.S. Dept. of Energy ASCI Program OpenMP Fortran API, Version 1.0, published Oct. 1997 OpenMP C API, Version 1.0, published Oct. 1998 OpenMP 2.0 API for Fortran, published in 2000 OpenMP 2.0 API for C/C++, published in 2002 OpenMP 2.5 API for C/C++ & F90 published in 2005 OpenMP 3.0 draft version
Image of page 2
3 Motivation: Why Should I Use OpenMP? www.sdsc.edu/~allans/cs260/ Prof. Allan Snavely’s lecture slide Where Should I Use OpenMP? www.sdsc.edu/~allans/cs260/ Prof. Allan Snavely’s lecture slide
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Programming Model Compiler directives via pragmas (C, C++) or comments (Fortran) Compiler replaces directives with calls to runtime library (libgomp (gcc)) Runtime controls available via library API and environment variables Environment variables control parallelism – OMP_NUM_THREADS - OMP_SCHEDULE – OMP_DYNAMIC - OMP_NESTED http://people.redhat.com/dnovillo/Papers/rhs2006.pdf Programming Model Explicit sharing and synchronization Threads interact via shared variables – Several ways for specifying shared data – Sharing always at the variable level Programmer responsible for synchronization – Unintended sharing leads to “data races” – Use synchronization directives and library API – Synchronization is expensive http://people.redhat.com/dnovillo/Papers/rhs2006.pdf
Image of page 4
5 OpenMP Architecture application user compiler directives environment variables runtime library Threads in operating system OpenMP Parallel Directive C/C++ directives begin with: # pragma omp #include<stdio.h> #include “omp.h” int main() { #pragma omp parallel { int ii; ii = omp_get_thread_num(); printf (“Atlanta is a great city! %d \n”, ii); } } Atlanta is a great city! 0 Atlanta is a great city! 3 Atlanta is a great city! 2 Atlanta is a great city! 6 Atlanta is a great city! 1 Atlanta is a great city! 4 Atlanta is a great city! 7 Atlanta is a great city! 8 The master thread
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Directives and Clauses Directives are the main OpenMP construct Clauses provide modifiers and attributes to the directives General syntax is – C/C++ #pragma omp directive [ clause [ clause ] … ] http://people.redhat.com/dnovillo/Papers/rhs2006.pdf
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern