Shared-Memory Model and Threads Intel Software College Introduction to Parallel Programming – Part 2.

Slides:



Advertisements
Similar presentations
Implementing Task Decompositions Intel Software College Introduction to Parallel Programming – Part 5.
Advertisements

Analyzing Parallel Performance Intel Software College Introduction to Parallel Programming – Part 6.
Confronting Race Conditions Intel Software College Introduction to Parallel Programming – Part 4.
Improving Parallel Performance Intel Software College Introduction to Parallel Programming – Part 7.
Implementing Domain Decompositions Intel Software College Introduction to Parallel Programming – Part 3.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 16 Unemployment: Search and Efficiency Wages.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2010, Elsevier Inc. All rights Reserved Chapter 1 Why Parallel Computing? An Introduction to Parallel Programming Peter Pacheco.
Processes and Operating Systems
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 5: Repetition and Loop Statements Problem Solving & Program.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 10 second questions
Chapter 6 File Systems 6.1 Files 6.2 Directories
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
Solve Multi-step Equations
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Figure 12–1 Basic computer block diagram.
Intel Software College Tuning Threading Code with Intel® Thread Profiler for Explicit Threads.
PP Test Review Sections 6-1 to 6-6
Chapter 10: Virtual Memory
INTEL CONFIDENTIAL Implementing a Task Decomposition Introduction to Parallel Programming – Part 9.
CS 6143 COMPUTER ARCHITECTURE II SPRING 2014 ACM Principles and Practice of Parallel Programming, PPoPP, 2006 Panel Presentations Parallel Processing is.
2 |SharePoint Saturday New York City
VOORBLAD.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Copyright © 2013, 2009, 2006 Pearson Education, Inc.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
1 © 2004, Cisco Systems, Inc. All rights reserved. CCNA 1 v3.1 Module 2 Networking Fundamentals.
Copyright © 2013, 2009, 2006 Pearson Education, Inc. 1 Section 5.4 Polynomials in Several Variables Copyright © 2013, 2009, 2006 Pearson Education, Inc.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Analyzing Genes and Genomes
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Energy Generation in Mitochondria and Chlorplasts
INTEL CONFIDENTIAL Deadlock Introduction to Parallel Programming – Part 7.
INTEL CONFIDENTIAL OpenMP for Domain Decomposition Introduction to Parallel Programming – Part 5.
INTEL CONFIDENTIAL Confronting Race Conditions Introduction to Parallel Programming – Part 6.
INTEL CONFIDENTIAL Why Parallel? Why Now? Introduction to Parallel Programming – Part 1.
INTEL CONFIDENTIAL Parallel Decomposition Methods Introduction to Parallel Programming – Part 2.
INTEL CONFIDENTIAL Finding Parallelism Introduction to Parallel Programming – Part 3.
Recognizing Potential Parallelism Intel Software College Introduction to Parallel Programming – Part 1.
INTEL CONFIDENTIAL Predicting Parallel Performance Introduction to Parallel Programming – Part 10.
INTEL CONFIDENTIAL Shared Memory Considerations Introduction to Parallel Programming – Part 4.
Presentation transcript:

Shared-Memory Model and Threads Intel Software College Introduction to Parallel Programming – Part 2

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 2 Shared-Memory Model and Threads Objectives At the end of this module you should be able to: Describe the shared-memory model of parallel programming Describe the differences between the fork/join model and the general threads model Demonstrate how to implement domain and functional decompositions using threads Decide whether a variable in a multithreaded program should be shared or private

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 3 Shared-Memory Model and Threads Cooperating Parallel Processes Parallel computing multiple processes working together to speed the solution of a task Working together process cooperation Kinds of cooperation Sharing information (communication) Keeping out of each others way (synchronization)

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 4 Shared-Memory Model and Threads The Shared-Memory Model Shared Memory CPU Private Memory CPU Private Memory CPU Private Memory

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 5 Shared-Memory Model and Threads Evaluating Parallel Models How do processes share information? How do processes synchronize? In shared-memory model, both accomplished through shared variables Communication: buffer Synchronization: semaphore

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 6 Shared-Memory Model and Threads Methodology Study problem, sequential program, or code segment Look for opportunities for parallelism Use threads to express parallelism

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 7 Shared-Memory Model and Threads What Is a Process? A program in some state of execution Code Data Logical address space Information about a process includes Process state Program counter Values of CPU registers Memory management information

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 8 Shared-Memory Model and Threads What Is a Thread? A unit of control within a process Carver and Tai Main thread executes programs main function Main thread may create other threads to execute other functions Threads have own program counter, copy of CPU registers, and stack of activation records Threads share processs data, code, address space, and other resources Threads have lower overhead than processes

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 9 Shared-Memory Model and Threads Another Way of Looking at It So why does this view matter? Thread 0 (Program Counter, Registers, etc.) Address Space File Descriptors Other Data Process

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 10 Shared-Memory Model and Threads Why This View Matters Thread 0 (Program Counter, Registers, etc.) Address Space File Descriptors Other Data Process Thread 1 (Program Counter, Registers, etc.)

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 11 Shared-Memory Model and Threads What Are Threads Good For? Making programs easier to understand Overlapping computation and I/O Improving responsiveness of GUIs Improving performance through parallel execution

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 12 Shared-Memory Model and Threads Fork/Join Programming Model When program begins execution, only master thread active Master thread executes sequential portions of program For parallel portions of program, master thread forks (creates or awakens) additional threads At join (end of parallel section of code), extra threads are suspended or die

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 13 Shared-Memory Model and Threads Master Thread ForkJoin Fork Other Threads

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 14 Shared-Memory Model and Threads Relating Fork/Join to Code for { } } Sequential code Parallel code Sequential code Parallel code Sequential code

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 15 Shared-Memory Model and Threads More General Threads Model When program begins execution, only one user thread, called the main thread, is active The main thread can create other threads, which execute other functions Created threads can also create additional threads How this is done varies according to programming language or API

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 16 Shared-Memory Model and Threads Fork/Join versus General Model You can implement fork/join in the general model Hence fork/join a special case of general model More structured More easily optimized General model More flexible Better support for functional decompositions

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 17 Shared-Memory Model and Threads Incremental Parallelization Sequential program a special case of threaded program Programmers can add parallelism incrementally Profile program execution Repeat Choose best opportunity for parallelization Transform sequential code into parallel code Until further improvements not worth the effort

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 18 Shared-Memory Model and Threads Utility of Threads Threads are flexible enough to implement Domain decomposition Functional decomposition Pipelining

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 19 Shared-Memory Model and Threads Domain Decomposition Using Threads Shared Memory Thread 0Thread 2 Thread 1 f ( )

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 20 Shared-Memory Model and Threads Shared Memory Functional Decomposition Using Threads Thread 0Thread 1 e ( ) g ( )h ( ) f ( )

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 21 Shared-Memory Model and Threads Pipelining Using Threads Thread 0Thread 2Thread 1 Shared Memory InputOutput e ( )f ( )g ( ) Data set 2 Data sets 5, 6,... Data set 4 Data set 3 Data set 1

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 22 Shared-Memory Model and Threads Shared versus Private Variables Shared Variables Private Variables Private Variables Thread

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 23 Shared-Memory Model and Threads Domain Decomposition Sequential Code: int a[1000], i; for (i = 0; i < 1000; i++) a[i] = foo(i);

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 24 Shared-Memory Model and Threads Domain Decomposition Sequential Code: int a[1000], i; for (i = 0; i < 1000; i++) a[i] = foo(i); Thread 0: for (i = 0; i < 500; i++) a[i] = foo(i); Thread 1: for (i = 500; i < 1000; i++) a[i] = foo(i);

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 25 Shared-Memory Model and Threads Domain Decomposition Sequential Code: int a[1000], i; for (i = 0; i < 1000; i++) a[i] = foo(i); Thread 0: for (i = 0; i < 500; i++) a[i] = foo(i); Thread 1: for (i = 500; i < 1000; i++) a[i] = foo(i); Shared Private

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 26 Shared-Memory Model and Threads Functional Decomposition int e; main () { int x[10], j, k, m; j = f(x, k); m = g(x, k);... } int f(int *x, int k) { int a; a = e * x[k] * x[k]; return a; } int g(int *x, int k) { int a; k = k-1; a = e / x[k]; return a; }

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 27 Shared-Memory Model and Threads Functional Decomposition int e; main () { int x[10], j, k, m; j = f(x, k); m = g(x, k); } int f(int *x, int k) { int a; a = e * x[k] * x[k]; return a; } int g(int *x, int k) { int a; k = k-1; a = e / x[k]; return a; } Thread 0 Thread 1

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 28 Shared-Memory Model and Threads Functional Decomposition volatile int e; main () { int x[10], j, k, m; j = f(x, k); m = g(x, k); } int f(int *x, int k) { int a; a = e * x[k] * x[k]; return a; } int g(int *x, int k) { int a; k = k-1; a = e / x[k]; return a; } Thread 0 Thread 1 Static variable: Shared

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 29 Shared-Memory Model and Threads Functional Decomposition volatile int e; main () { int x[10], j, k, m; j = f(x, k); m = g(x, k); } int f(int *x, int k) { int a; a = e * x[k] * x[k]; return a; } int g(int *x, int k) { int a; k = k-1; a = e / x[k]; return a; } Thread 0 Thread 1 Heap variable: Shared

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 30 Shared-Memory Model and Threads Functional Decomposition volatile int e; main () { int x[10], j, k, m; j = f(x, k); m = g(x. k); } int f(int *x, int k) { int a; a = e * x[k] * x[k]; return a; } int g(int *x, int k) { int a; k = k-1; a = e / x[k]; return a; } Thread 0 Thread 1 Functions local variables: Private

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 31 Shared-Memory Model and Threads Shared and Private Variables Shared variables Static variables Heap variables Contents of run-time stack at time of call Private variables Loop index variables Run-time stack of functions invoked by thread

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 32 Shared-Memory Model and Threads The Shared-Memory Model (Reprise) Shared Memory CPU Private Memory CPU Private Memory CPU Private Memory

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 33 Shared-Memory Model and Threads The Threads Model Shared Variables Thread Private Variables Thread Private Variables Thread Private Variables

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 34 Shared-Memory Model and Threads References Jim Beveridge and Robert Wiener, Multithreading Applications in Win32®, Addison-Wesley (1997). David R. Butenhof, Programming with POSIX® Threads, Addison-Wesley, (1997). Richard H. Carver and Kuo-Chung Tai, Modern Multithreading: Implementing, Testing, and Debugging Java and C++/Pthreads/ Win32 Programs, Wiley-Interscience (2006). Doug Lea, A Java Fork/Join Framework, Proceedings of the ACM 2000 Conference on Java Grande, pp Michael J. Quinn, Parallel Programming in C with MPI and OpenMP, McGraw-Hill (2004).

Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States or other countries. *Other brands and names are the property of their respective owners. Intel ® Software College 35 Shared-Memory Model and Threads