Visual Studio 2010 and .NET Framework 4 Training Workshop

Slides:



Advertisements
Similar presentations
An overview of… Luis Guerrero Plain Concepts
Advertisements

James Kolpack, InRAD LLC popcyclical.com. CodeStock is proudly partnered with: Send instant feedback on this session via Twitter: Send a direct message.
Parallel Extensions to the.NET Framework Daniel Moth Microsoft
Virtual techdays INDIA │ 9-11 February 2011 Parallelism in.NET 4.0 Parag Paithankar │ Technology Advisor - Web, Microsoft India.
1 New Architectures Need New Languages A triumph of optimism over experience! Ian Watson 3 rd July 2009.
Daniel Moth  Parallel Computing Platform Microsoft Corporation TL26.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Parallel Programming in.NET Kevin Luty.  History of Parallelism  Benefits of Parallel Programming and Designs  What to Consider  Defining Types of.
Principles of Programming Chapter 1: Introduction  In this chapter you will learn about:  Overview of Computer Component  Overview of Programming 
Computer System Architectures Computer System Software
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Programming Paradigms for Concurrency Part 2: Transactional Memories Vasu Singh
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Lecture 21 Parallel Programming Richard Gesick. Parallel Computing Parallel computing is a form of computation in which many operations are carried out.
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Mtivity Client Support System Quick start guide. Mtivity Client Support System We are very pleased to announce the launch of a new Client Support System.
1 CS161 Introduction to Computer Science Topic #9.
Inside LINQ to Objects How LINQ to Objects work Inside LINQ1.
© 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.
Visual Studio 2010 and.NET Framework 4 Training Workshop.
CS 179: GPU Computing LECTURE 2: MORE BASICS. Recap Can use GPU to solve highly parallelizable problems Straightforward extension to C++ ◦Separate CUDA.
CSE 351 Caches. Before we start… A lot of people confused lea and mov on the midterm Totally understandable, but it’s important to make the distinction.
Tutorial 2: Homework 1 and Project 1
Chapter 4 – Thread Concepts
FOP: Multi-Screen Apps
AP CSP: Creating Functions & Top-Down Design
Project Management: Messages
Processes and threads.
Design Components are Code Components
OSCon 2012: Cloud Computing & Data Privacy David Mertz
Background on the need for Synchronization
Advanced OS Concepts (For OCR)
Chapter 4 – Thread Concepts
Async or Parallel? No they aren’t the same thing!
Other Important Synchronization Primitives
Lecture 25 More Synchronized Data and Producer/Consumer Relationship
The University of Adelaide, School of Computer Science
Introduction to Operating System (OS)
RFPMonkey.com External Review
Adding Assignments and Learning Units to Your TSS Course
Introduction to Events
Lecture 5: GPU Compute Architecture
CSCI/CMPE 3334 Systems Programming
Multi-Processing in High Performance Computer Architecture:
Multithreading Chapter 23.
Staying Afloat in the .NET Async Ocean
Introducing the Ideas One of Six Traits:
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Chapter 1 Introduction.
CSCE 313 – Introduction to UNIx process
Dr. Mustafa Cem Kasapbaşı
Concurrency: Mutual Exclusion and Process Synchronization
Hold up, wait a minute, let me put some async in it
Mastering Memory Modes
PERFORMANCE MEASURES. COMPUTATIONAL MODELS Equal Duration Model:  It is assumed that a given task can be divided into n equal subtasks, each of which.
Java Programming Introduction
Tonga Institute of Higher Education IT 141: Information Systems
- When you approach operating system concepts there might be several confusing terms that may look similar but in fact refer to different concepts:  multiprogramming, multiprocessing, multitasking,
Tonga Institute of Higher Education IT 141: Information Systems
Visual Studio 2010 和 .NET Framework 4 培训研讨会
CS703 – Advanced Operating Systems
“The Little Book on Semaphores” Allen B. Downey
Concurrency: Threads, Address Spaces, and Processes
Lecture 20 Parallel Programming CSE /8/2019.
Chapter 3: Process Management
Enhanced agent workspace for messaging
Presentation transcript:

Visual Studio 2010 and .NET Framework 4 Training Workshop

Parallel Computing for Managed Developers ESTIMATED TIME: 60 minutes Name Title Organization Email

Objectives Understand the importance of the “parallel computing shift” Understand the technologies introduced in the .NET Framework 4 that are easing this transition MESSAGING: Objectives for the session.

“I used to think that cyberspace was fifty years away “I used to think that cyberspace was fifty years away. What I thought was fifty years away, was only ten years away. And what I thought was ten years away... it was already here. I just wasn't aware of it yet.” - Bruce Sterling MESSAGING: It’s amazing how fast technology can sneak up on us. It’s important to remember that what we think is still years away from us is something that is actually already here and that we have to starting thinking about it now.

Baby Names DEMO: Use BabyNames

“Moore’s Law scaling should easily let us hit the 80-core mark in mainstream processors within the next ten years and quite possibly even sooner.” - Justin Ratner, CTO, Intel MESSAGING: Now this has a great impact on the capabilities of our applications. Thanks to the ever-increasing power of our computers, computing power has been on a steady incline. And for the most part, our applications have been able to track this computing power increase merely by relying on the fact that faster computers will be released that will, in turn, make their own applications faster (just by running on the faster hardware). In this world, sequential programming wasn’t a problem because the ever-increasing computer power allowed our sequential programs to keep on running faster and faster as new hardware was released. However, along this computing power trend, a shift was made to CPUs containing multiple cores. Computers now contained multiple cores, where each single core was slightly less powerful than a complete processor was before. And while it would be nice to think our applications could continue to follow the computing power trend just as they did before, that’s not reality. The reality is that if we continue to use the same programming models as we use today, our performance will plateau. Not only will it plateau, there is a possibility that performance will decrease a bit as many cores are introduced that each are just a little less powerful than their predecessors (for less power consumption, less heat dissapation, etc.). Cleary, new tools for us developers to write applications with are necessary.

The Parallel Computing Initiative Letting the brightest developers solve business problems, not concurrency problems. MESSAGING: Today, concurrency usually has to be done by the brightest developers in a business. The problem with this is that the brightest developers are then being consumed by concurrency minutia rather than being able to be focused on core business problems and helping the business’s bottom line. By providing new libraries and tools that make it easy to write parallel code, we hope to allow the best and brightest developers focus on the business problems at hand. This in turn enables other developers to be able to address concurrency and parallelism. This is the long term goal of Microsoft with the Parallel Computing Initiative. Visual Studio 2010 and .NET Framework 4 is merely the first step being taken in this direction. “Concurrency for the masses”

Concurrency Landscape For Visual Studio 2010 and the .NET Framework 4… System.Threading Parallel Extensions Unified Cancellation Model MESSAGING: There are three primary improvement areas in Visual Studio 2010 and .NET Framework 4 that we will discuss in this talk: System.Threading improvements, introduction of Parallel Extensions to the .NET Framework, and a new unified cancellation model coming in .NET Framework 4.

New System.Threading Primitives A Barrier is a synchronization primitive that enforces the stopping of execution between a number of threads or processes at a given point and prevents further execution until all threads or processors have reached the given point. A CountdownEvent is a synchronization primitive that enables ongoing tracking of a given workload in order to determine if processing of that workload is finished or not. YUCK! MESSAGING: Several important new primitives coming to System.Threading Barrier and CountdownEvent make coordinating multithreaded code easier than it was before Technical descriptions are boring and not the best candidate for learning Let’s learn Barrier and CountdownEvent through analogy

Barrier “Let’s all caravan over to Seattle! We’ll meet at the gas station and leave from there.” - Charlie Dennis Mac Barrier MESSAGING: The new Barrier synchronization primitive allows you to provide “sync-points” where all threads/tasks of execution meet at. Then, no threads/tasks continue until all of them have arrived at the barrier. This is a way that now you can easily introduce “check points” into your parallel operations if there are naturally areas where you want different execution units to meet. A Barrier can be re-used multiple times to issue many “check points” that could occur in the code. As an example, think about a road trip. If some friends are taking a road trip to Seattle, for instance, they might all meet at the gas station first. They shouldn’t leave the gas station until all of them arrive so they can leave together. In this case, the gas station itself could represent the barrier. There is a natural “check point” that occurs before all of them leave and start driving again to Seattle. Charlie Gas Station Seattle

Unified Cancellation Cancellation Token Source “Sir, we are ready to seat you…” - Hostess Cancellation Token Source MESSAGING: A new unified cancellation model is being introduced with .NET Framework 4. This new model allows many different operations (like separate threads of execution, I/O calls, etc.) to be organized in such a way that they can all be cancelled with one simple call in a unified way (no matter what the operation itself is). The new CancellationTokenSource and CancellationToken constructs is what the new unified cancellation model is comprised of. The CancellationTokenSource is the core of this model. From a CancellationTokenSource, you can pass out as many CancellationTokens as you wish to various types of operations that are or are not happening in parallel. Then you can use the CancellationTokenSource to signify that everything needs to be cancelled by calling a Cancel() method. Then the cancellation is reflected in all the various tokens. One key aspect of this new model is that the individual tokens that are passed out have no way to signify cancellation themselves. There is also no way to get from a reference to a CancellationToken back to the original CancellationTokenSource. This is by design. When you are passing out tokens to as many operations as you need to in order to keep your cancellation unified, the last thing you want to do is to allow some random token to be able to signify a Cancel() request and then cancel all the other processing that is happening. Think of this another way, compare cancellation tokens by the devices handed out at some restaurants to signify that you (as the customer) are ready to be seated. Though you have the device in your hand, there is no possible way for you personally to make it go off (that would kind of defeat the purpose). The only party that can signal that you are “ready to be seated” is the restaurant itself. This is the same relationship the CancellationTokenSource and CancellationToken have to each other. Cancellation Token

System.Threading and the new Unified Cancellation Model DEMO: Use BarrierDemo. Also use BarrierDemo to show the new unified cancellation model via CancellationToken/CancellationTokenSource

Parallel Extensions is a Parallel Extensions is a .NET Library that supports declarative and imperative data parallelism, imperative task parallelism, and a set of data structures that make coordination easier. Parallel LINQ (PLINQ) Task Parallel Library (TPL) Coordination Data Structures (CDS) MESSAGING: Parallel Extensions is simply a .NET library (meaning, normal .NET code that can be used by any .NET-based language). It contains three different pieces: PLINQ, TPL, and CDS (System.Collections.Concurrent). Parallel Extensions addresses everything from declarative and imperative data parallelism, to imperative task parallelism.

From Threads To Tasks DEMO: Use TaskDemo

“Work Stealing” in Action MESSAGING: The task scheduler in Parallel Extensions is very smart and powerful. There are two aspects that make it so: the ability for different worker threads to “steal work” from other threads when there is work to be done, and the addressing of data locality when a thread is determining what work to actually do. When a thread needs to find more work to do, it looks in three different places (in the following order): It’s local queue The global queue Other thread’s queues that have work to be done It’s important to know that data locality is addressed when a thread needs to grab more work to do: When pulling from the local queue, the worker pulls the last item added to the queue. This is because the last item added to the queue has the greatest chance of still being fresh in the cache, as opposed to older items which are more likely have expired and been flushed from cache. When pulling from another worker’s queue, the current worker pulls the oldest item added to the queue. This is because the oldest item added to the queue has the greatest chance of not being in the cache even for its local worker (and hence needing to load in anyways). Worker Thread 1 Worker Thread p Program Thread Task 3 Task 1 Task 4 Task 5 Task 2

Parallel Static Class When program statements are independent… …they can be parallelized StatementA(); StatementB(); StatementC(); MESSAGING: With the introduction of the new Parallel static class, it becomes much easier to parallelize independent statements. The great thing is that if program statements are completely independent from each other (i.e. they don’t share any common shared stated between the various calls are require the calls to take place in a given order), they can easily be parallelized using the new Parallel.Invoke() method. There are other static methods declared off the Parallel class that make other parallel operations easy as well (like Parallel.For() and Parallel.ForEach(). We’ll take a look at some of these in the demo. So one might ask: “Well, if it’s that simple, why doesn’t the compiler just do this for automatically?” The problem is that it’s not quite that simple. In our world of imperative code and shared state, there’s no easy way to guarantee that these methods being called don’t have some sort of state somewhere that they are sharing. It could be five method calls deep, it could be ten, it could be more. You, as the developer, are the one with the necessary knowledge to know where this is true. Therefore, Parallel.Invoke() is strictly an opt-in process. Otherwise, we could do more damage than good. Parallel.Invoke( () => StatementA(), () => StatementB(), () => StatementC() );

Parallel Static Class DEMO: Use ParallelDemo

PLINQ Parallel LINQ (PLINQ) enables developers to easily leverage manycore with a minimal impact to existing LINQ programming model var q = from p in people         where p.Name == queryInfo.Name && p.State == queryInfo.State && p.Year >= yearStart && p.Year <= yearEnd         orderby p.Year ascending         select p; .AsParallel() MESSAGING: PLINQ is a technology that allows developers to _easily_ leverage manycore. The great thing about PLINQ is that if you are using LINQ-to-objects, there is a very minimal impact to your code in order for it to use PLINQ. All it takes to use PLINQ is adding “.AsParallel()” to your query. This will turn the query into a PLINQ query and will use the PLINQ execution engine when executed. One small change, and your code now takes advantage of all the hardware available to you. NOTES: AsParallel() works by returning an IParallelEnumerable so every subsequent query operator works against the new IParallelEnumerable rather than the normal IEnumerable. See the hands-on lab for Parallel Extensions for more details.

PLINQ DEMO: Use PLINQDemo

Unified Cancellation Model Recap For Visual Studio 2010 and the .NET Framework 4.0… System.Threading Parallel Extensions Unified Cancellation Model MESSAGING: So to recap, parallel computing enhancements for managed developers in Visual Studio 2010 and .NET Framework 4 are comprised of three different areas: System.Threading improvements, introduction of Parallel Extensions to the .NET Framework, and the newly introduced unified cancellation model (CancellationToken/CancellationTokenSource).

Questions?