INTEL CONFIDENTIAL Shared Memory Considerations Introduction to Parallel Programming – Part 4.

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.
Shared-Memory Model and Threads Intel Software College Introduction to Parallel Programming – Part 2.
Improving Parallel Performance Intel Software College Introduction to Parallel Programming – Part 7.
Implementing Domain Decompositions Intel Software College Introduction to Parallel Programming – Part 3.
Intel Software College Tuning Threading Code with Intel® Thread Profiler for Explicit Threads.
INTEL CONFIDENTIAL Implementing a Task Decomposition Introduction to Parallel Programming – Part 9.
INTEL CONFIDENTIAL Threading for Performance with Intel® Threading Building Blocks Session:
The Intel® Software Community Real-world resources you can use.
INTEL CONFIDENTIAL Improving Parallel Performance Introduction to Parallel Programming – Part 11.
INTEL CONFIDENTIAL Deadlock Introduction to Parallel Programming – Part 7.
Thinking in Parallel – Task Decomposition New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
Stacks and HeapsCS-3013 A-term A Short Digression on Stacks and Heaps CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
1 Tuesday, November 07, 2006 “If anything can go wrong, it will.” -Murphy’s Law.
Digression on Stack and Heaps CS-502 (EMC) Fall A Short Digression on Stacks and Heaps CS-502, Operating Systems Fall 2009 (EMC) (Slides include.
Concurrency CS 510: Programming Languages David Walker.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
3.5 Interprocess Communication
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
Stacks and HeapsCS-502 Fall A Short Digression Stacks and Heaps CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
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 OpenMP for Task Decomposition Introduction to Parallel Programming – Part 8.
Threaded Programming Methodology Intel Software College.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
INTEL CONFIDENTIAL Why Parallel? Why Now? Introduction to Parallel Programming – Part 1.
1 MPI-2 and Threads. 2 What are Threads? l Executing program (process) is defined by »Address space »Program Counter l Threads are multiple program counters.
Thinking in Parallel – Pipelining New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
INTEL CONFIDENTIAL Reducing Parallel Overhead Introduction to Parallel Programming – Part 12.
INTEL CONFIDENTIAL Parallel Decomposition Methods Introduction to Parallel Programming – Part 2.
User-Level Process towards Exascale Systems Akio Shimada [1], Atsushi Hori [1], Yutaka Ishikawa [1], Pavan Balaji [2] [1] RIKEN AICS, [2] Argonne National.
Introduction to Symmetric Multiprocessors Süha TUNA Bilişim Enstitüsü UHeM Yaz Çalıştayı
INTEL CONFIDENTIAL Finding Parallelism Introduction to Parallel Programming – Part 3.
Programming Models using Windows* Threads Intel Software College.
Recognizing Potential Parallelism Intel Software College Introduction to Parallel Programming – Part 1.
Evaluation of a DAG with Intel® CnC Mark Hampton Software and Services Group CnC MIT July 27, 2010.
Multi-core Programming: Basic Concepts. Copyright © 2006, Intel Corporation. All rights reserved. Intel and the Intel logo are trademarks or registered.
INTEL CONFIDENTIAL Predicting Parallel Performance Introduction to Parallel Programming – Part 10.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Threads and Processes.
Runtime Environments Compiler Construction Chapter 7.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Concurrent Programming. Concurrency  Concurrency means for a program to have multiple paths of execution running at (almost) the same time. Examples:
Recognizing Potential Parallelism Introduction to Parallel Programming Part 1.
Programming with POSIX* Threads Intel Software College.
Programs of the Intel® Education Initiative are funded by the Intel Foundation and Intel Corporation. Copyright © 2007, Intel Corporation. All rights reserved.
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
Correcting Threading Errors with Intel® Parallel Inspector.
Thinking in Parallel – Implementing In Code New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
CS 838: Pervasive Parallelism Introduction to pthreads Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from online references.
CSC 8505 Compiler Construction Runtime Environments.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Threaded Programming Lecture 1: Concepts. 2 Overview Shared memory systems Basic Concepts in Threaded Programming.
Thinking in Parallel – Domain Decomposition New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
A Pattern Language for Parallel Programming Beverly Sanders University of Florida.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Parallel Computing Presented by Justin Reschke
Thinking in Parallel - Introduction New Mexico Supercomputing Challenge in partnership with Intel Corp. and NM EPSCoR.
Tuning Threaded Code with Intel® Parallel Amplifier.
1 Parallel Processing Fundamental Concepts. 2 Selection of an Application for Parallelization Can use parallel computation for 2 things: –Speed up an.
Processes and threads.
Threads and Cooperation
More examples How many processes does this piece of code create?
Lecture 10: Threads Implementation
ე ვ ი ო Ш Е Т И О А С Д Ф К Ж З В Н М W Y U I O S D Z X C V B N M
Lecture 10: Threads Implementation
CS Introduction to Operating Systems
Presentation transcript:

INTEL CONFIDENTIAL Shared Memory Considerations Introduction to Parallel Programming – Part 4

Copyright © 2009, 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. Review & Objectives Previously: Described method to identify opportunities for parallelism in code segments and applications At the end of this part you should be able to: Describe the shared-memory model of parallel programming Demonstrate how to implement domain and task decompositions using threads Decide whether a variable in a multithreaded program should be shared or private 2

Copyright © 2009, 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. 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 other’s way (synchronization) 3

Copyright © 2009, 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. The Shared-Memory Model 4 Shared Memory Core Private Memory Core Private Memory Core Private Memory

Copyright © 2009, 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. 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 5

Copyright © 2009, 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. Methodology Study problem, sequential program, or code segment Look for opportunities for parallelism Use threads to express parallelism 6

Copyright © 2009, 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. 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 core’s registers Memory management information 7

Copyright © 2009, 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. What Is a Thread? “A unit of control within a process” — Carver and Tai Main thread executes program’s “main” function Main thread may create other threads to execute other functions Threads have own program counter, copy of core registers, and stack of activation records Threads share process’s data, code, address space, and other resources Threads have lower overhead than processes 8

Copyright © 2009, 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. Utility of Threads Threads are flexible enough to implement Domain decomposition Task decomposition Pipelining 9

Copyright © 2009, 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. Domain Decomposition Using Threads 10 Shared Memory Thread 0Thread 2 Thread 1 f ( )

Copyright © 2009, 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. Task Decomposition Using Threads 11 Shared Memory Thread 0Thread 1 e ( ) g ( )h ( ) f ( )

Copyright © 2009, 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. Pipelining Using Threads 12 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 © 2009, 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. Shared versus Private Variables 13 Shared Variables Private Variables Private Variables Thread

Copyright © 2009, 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. Domain Decomposition Sequential Code: int a[1000], i; for (i = 0; i < 1000; i++) a[i] = foo(i); 14

Copyright © 2009, 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. 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); 15

Copyright © 2009, 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. 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); 16 Shared Private

Copyright © 2009, 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. Task 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; } 17

Copyright © 2009, 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. Task 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; } 18 Thread 0 Thread 1

Copyright © 2009, 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. Task 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; } 19 Thread 0 Thread 1 Static variable: Shared

Copyright © 2009, 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. Task 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; } 20 Thread 0 Thread 1 Heap variable: Shared

Copyright © 2009, 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. Task 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; } 21 Thread 0 Thread 1 Function’s local variables: Private

Copyright © 2009, 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. 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 22

Copyright © 2009, 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. The Shared-Memory Model (Reprise) 23 Shared Memory Core Private Memory Core Private Memory Core Private Memory

Copyright © 2009, 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. The Threads Model 24 Shared Variables Thread Private Variables Thread Private Variables Thread Private Variables

Copyright © 2009, 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. 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). Michael J. Quinn, Parallel Programming in C with MPI and OpenMP, McGraw-Hill (2004). 25