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.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Threads, SMP, and Microkernels
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Computer Systems/Operating Systems - Class 8
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Chapter 5 Processes and Threads Copyright © 2008.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
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
Operating Systems Lecture # 3. Recap Hardware Operating System Application System Call Trap Hardware Trap Processor.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
Process Concept An operating system executes a variety of programs
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
Process Description and Control. Process concepts n Definitions – replaces task, job – program in execution – entity that can be assigned to and executed.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Operating System 4 THREADS, SMP AND MICROKERNELS
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Threads G.Anuradha (Reference : William Stallings)
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
Introduction to OpenMP Eric Aubanel Advanced Computational Research Laboratory Faculty of Computer Science, UNB Fredericton, New Brunswick.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Department of Computer Science and Software Engineering
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Module 2.0: Threads.
CSC 322 Operating Systems Concepts Lecture - 7: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Java Thread Programming
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Introduction to Operating Systems Concepts
Chapter 4 – Thread Concepts
Processes and threads.
Day 12 Threads.
Chapter 4 – Thread Concepts
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4 Threads.
Chapter 4: Threads.
Operating System Concepts
Threads and Data Sharing
Mid Term review CSC345.
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
CS510 Operating System Foundations
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Presentation transcript:

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

3 Inside a Thread l

4 Kinds of Threads l Almost a process »Kernel (Operating System) schedules »each thread can make independent system calls l Co-routines »User schedules (sort of…) l Memory references »Hardware schedules

5 Kernel Threads l System calls (e.g., read, accept) block calling thread but not process l Alternative to “nonblocking” or “asynchronous” I/O: »create_thread thread calls blocking read l Can be expensive

6 User Threads l System calls (may) block all threads in process l Allows multiple processors to cooperate on data operations »loop: create # threads = # processors - 1 each thread does part of loop l Cheaper than kernel threads »Still must save registers (if in same processor) »Parallelism requires OS to schedule threads on different processors

7 Hardware Threads l Hardware controls threads l Allows single processor to interleave memory references and operations »Unsatisfied memory ref changes thread »Separate registers for each thread l Single cycle thread switch with appropriate hardware »basis of Tera MTA computer »like kernel threads, replaces nonblocking hardware operations - multiple pending loads »Even lighter weight—just change PC

8 Why Use Threads? l Manage multiple points of interaction »Low overhead steering/probing »Background checkpoint save l Alternate method for nonblocking operations »CORBA method invocation (no funky nonblocking calls) l Hiding memory latency l Fine-grain parallelism »Compiler parallelism Latency Hiding

9 Thread Interfaces l POSIX “pthreads” l Windows »Kernel threads »User threads called “fibers” l Java »First major language with threads »Provides memory synchronization model: methods (procedures) declared “synchronized” executed by one thread at a time »(don’t mention Ada, which had tasks) l OpenMP (Fortran only for now) »Mostly directive-based parallel loops »Some thread features (lock/unlock) » Library-based Invoke a routine in a separate thread

10 Thread Issues l Synchronization »Avoiding conflicting operations l Variable Name Space »Interaction between threads and the language l Scheduling »Will the OS do what you want?

11 Synchronization of Access Read/write model a = 1; b = 1; barrier(); barrier(); b = 2; while (a==1) ; a = 2; printf( “%d\n”, b ); What does thread 2 print? l Need lock/unlock to synchronize/order »OpenMP has FLUSH, possibly worse »volatile in C »Fortran has no corresponding concept l Java has “synchronized” methods (procedures) 1212

12 Variable Names l Each thread can access all of a processes memory (except for the thread’s stack) »Named variables refer to the address space—thus visible to all threads »Compiler doesn’t distinguish A in one thread from A in another »No modularity »Like using Fortran blank COMMON for all variables l NEC has a variant where all variables names refer to different variables unless specified »All variables are on thread stack by default (even globals) »More modular

13 Scheduling Threads l If threads used for latency hiding »Schedule on the same processor –Provides better data locality, cache usage l If threads used for parallel execution »Schedule on different processors using different memory pathways

14 The Changing Computing Model l More interaction »Threads allow low-overhead agents on any compution –OS schedules if necessary; no overhead if nothing happens (almost…) »Changes the interaction model from batch (give commands, wait for results) to constant interaction l Fine-grain parallelism »Simpler SMP programming model l Lowering the Memory Wall »CPU speeds increasing much faster than memory »hardware threads hide memory latency

15 Threads and MPI MPI_Init_thread(&argc,&argv,required,&provided) »Thread modes: –MPI_THREAD_SINGLE — One thread (MPI_Init) –MPI_THREAD_FUNNELED — One thread making MPI calls –MPI_THREAD_SERIALIZED — One thread at a time making MPI calls –MPI_THREAD_MULTIPLE — Free for all l Coexist with compiler (thread) parallelism for SMPs l MPI could have defined the same modes on a communicator basis (more natural, and MPICH will do this through attributes)

16 Using Threads with MPI l MPI defines what it means to support threads but does not require that support »Some vendors (such as IBM and Sun) support multi-threaded MPI processes »Others (such as SGI) do not –Interoperation with other thread systems (essentially MPI_THREAD_FUNNELED) may be supported l Active messages, interrupt receives, etc. are essentially MPI calls, such as a blocking receive, in a separate thread