SlideShare une entreprise Scribd logo
1  sur  71
Parallel Programming Patterns


                Аудиторія: розробники

                Олександр Павлишак, 2011
                pavlyshak@gmail.com
Зміст
-   Тренд
-   Основні терміни
-   Managing state
-   Паралелізм
-   Засоби
Вчора
Сьогодні
Завтра
Що відбувається?
-   Ріст частоти CPU вповільнився
-   Через фізичні обмеження
-   Free lunch is over
-   ПЗ більше не стає швидшим саме по собі
Сучасні тренди
- Manycore, multicore
- GPGPU, GPU acceleration, heterogeneous
  computing
- Distributed computing, HPC
Основні поняття
- Concurrency
  - Many interleaved threads of control
- Parallelism
  - Same result, but faster
- Concurrency != Parallelism
  - It is not always necessary to care about concurrency
    while implementing parallelism
- Multithreading
- Asynchrony
Задачі
- CPU-bound
  - number crunching
- I/O-bound
  - network, disk
Стан
- Shared
  - accessible by more than one thread
  - sharing is transitive
- Private
  - used by single thread only
Task-based program

         Application

       Tasks (CPU, I/O)

Runtime (queuing, scheduling)

Processors (threads, processes)
Managing state
Isolation
- Avoiding shared state
- Own copy of state
- Examples:
  - process isolation
  - intraprocess isolation
  - by convention
Immutability
-   Multiple read -- not a problem!
-   All functions are pure
-   Requires immutable collections
-   Functional way: Haskell, F#, Lisp
Synchronization
- The only thing that remains to deal with
  shared mutable state
- Kinds:
  - data synchronization
  - control synchronization
Data synchronization
- Why? To avoid race conditions and data
  corruption
- How? Mutual exclusion
- Data remains consistent
- Critical regions
  - locks, monitors, critical sections, spin locks
- Code-centered
  - rather than associated with data
Critical region
|Thread 1               |Thread 2
|// ...                 |// ...
|lock (locker)          |
|{                      |
|   // ...              |
|   data.Operation();   |
|   // ...              |
|}                      |
|// ...                 |lock (locker)
|                       |{
|                       |   // ...
|                       |   data.Operation();
                        |   // ...
Control synchronization
- To coordinate control flow
  - exchange data
  - orchestrate threads
- Waiting, notifications
  - spin waiting
  - events
  - alternative: continuations
Three ways to manage state
- Isolation: simple, loosely coupled, highly
scalable, right data structures, locality
- Immutability: avoids sync
- Synchronization: complex, runtime overheads,
contention

- in that order
Паралелізм
Підходи до розбиття задач
- Data parallelism
- Task parallelism
- Message based parallelism
Data parallelism
How?

- Data is divided up among hardware processors
- Same operation is performed on elements
- Optionally -- final aggregation
Data parallelism
When?

- Large amounts of data
- Processing operation is costly
- or both
Data parallelism
Why?

- To achieve speedup

- For example, with GPU acceleration:
  - hours instead of days!
Data parallelism
Embarrassingly parallel problems
- parallelizable loops
- image processing



Non-embarrassingly parallel problems
- parallel QuickSort
Data parallelism
                               ...
                         ...


  Thread 1    Thread 2
Data parallelism
Structured parallelism

- Well defined begin and end points
- Examples:
  - CoBegin
  - ForAll
CoBegin

var firstDataset = new DataItem[1000];
var secondDataset = new DataItem[1000];
var thirdDataset = new DataItem[1000];

Parallel.Invoke(
    () => Process(firstDataset),
    () => Process(secondDataset),
    () => Process(thirdDataset)
    );
Parallel For

var items = new DataItem[1000 * 1000];
// ...
Parallel.For(0, items.Length,
    i =>
        {
            Process(items[i]);
        });
Parallel ForEach

var tickers = GetNasdaqTickersStream();
Parallel.ForEach(tickers,
    ticker =>
        {
            Process(ticker);
        });
Striped Partitioning
                           ...




    Thread 1    Thread 2
Iterate complex data structures

var tree = new TreeNode();
// ...
Parallel.ForEach(
    TraversePreOrder(tree),
    node =>
        {
            Process(node);
        });
Iterate complex data
                Thread 1




                Thread 2




         ...
Declarative parallelism
var items = new DataItem[1000 * 1000];
// ...
var validItems =
    from item in items.AsParallel()
    let processedItem = Process(item)
    where processedItem.Property > 42
    select Convert(processedItem);

foreach (var item in validItems)
{
    // ...
}
Data parallelism
Challenges

-   Partitioning
-   Scheduling
-   Ordering
-   Merging
-   Aggregation
-   Concurrency hazards: data races, contention
Task parallelism
How?

- Programs are already functionally partitioned:
statements, methods etc.
- Run independent pieces in parallel
- Control synchronization
- State isolation
Task parallelism
Why?

- To achieve speedup
Task parallelism
Kinds
- Structured
  - clear begin and end points
- Unstructured
  - often demands explicit synchronization
Fork/join
-   Fork: launch tasks asynchronously
-   Join: wait until they complete
-   CoBegin, ForAll
-   Recursive decomposition
Fork/join
       Task 1



               Task 2



      Task 3




Seq                     Seq
Fork/join


Parallel.Invoke(
    () => LoadDataFromFile(),
    () => SavePreviousDataToDB(),
    () => RenewOtherDataFromWebService());
Fork/join
Task loadData =
    Task.Factory.StartNew(() => {
        // ...
    });
Task saveAnotherDataToDB =
    Task.Factory.StartNew(() => {
        // ...
    });
// ...
Task.WaitAll(loadData, saveAnotherDataToDB);
// ...
Fork/join
void Walk(TreeNode node) {
  var tasks = new[] {
      Task.Factory.StartNew(() =>
          Process(node.Value)),
      Task.Factory.StartNew(() =>
          Walk(node.Left)),
      Task.Factory.StartNew(() =>
          Walk(node.Right))
  };
  Task.WaitAll(tasks);
}
Fork/join recursive


       Root    Node

               Left
Seq    Left                 Seq
               Right

       Right   Node

               Left

               Right
Dataflow parallelism: Futures
Task<DataItem[]> loadDataFuture =
    Task.Factory.StartNew(() =>
    {
        //...
        return LoadDataFromFile();
    });

var dataIdentifier = SavePreviousDataToDB();
RenewOtherDataFromWebService(dataIdentifier);
//...
DisplayDataToUser(loadDataFuture.Result);
Dataflow parallelism: Futures

        Future




Seq              Seq     Seq
Dataflow parallelism: Futures

                                  Future

                         Future


                Future


Seq       Seq               Seq    Seq     Seq
Continuations

                       Task
                Task

       Task



Seq           Seq             Seq
Continuations
var loadData = Task.Factory.StartNew(() => {
        return LoadDataFromFile();
    });

var writeToDB = loadData.ContinueWith(dataItems =>
    {
        WriteToDatabase(dataItems.Result);
    });

var reportToUser = writeToDB.ContinueWith(t =>
    {
        // ...
    });
reportProgressToUser.Wait();
Producer/consumer
                   pipeline


reading           parsing            storing

                            parsed
          lines                                DB
                             lines
Producer/consumer
         pipeline

lines



        parsed
         lines




                 DB
Producer/consumer
var lines =
    new BlockingCollection<string>();

Task.Factory.StartNew(() =>
  {
    foreach (var line in File.ReadLines(...))
        lines.Add(line);
    lines.CompleteAdding();
  });
Producer/consumer
var dataItems =
  new BlockingCollection<DataItem>();

Task.Factory.StartNew(() =>
    {
        foreach (var line in
          lines.GetConsumingEnumerable()
        )
            dataItems.Add(Parse(line));
        dataItems.CompleteAdding();
    });
Producer/consumer
var dbTask = Task.Factory.StartNew(() =>
    {
        foreach (var item in
          dataItems.GetConsumingEnumerable()
        )
            WriteToDatabase(item);
    });

dbTask.Wait();
Task parallelism
Challenges

- Scheduling
- Cancellation
- Exception handling
- Concurrency hazards: deadlocks, livelocks,
priority inversions etc.
Message based parallelism
- Accessing shared state vs. local state
- No distinction, unfortunately
- Idea: encapsulate shared state changes into
  messages
- Async events
- Actors, agents
Засоби
Concurrent data structures
-   Concurrent Queues, Stacks, Sets, Lists
-   Blocking collections,
-   Work stealing queues
-   Lock free data structures
-   Immutable data structures
Synchronization primitives
-   Critical sections,
-   Monitors,
-   Auto- and Manual-Reset Events,
-   Coundown Events,
-   Mutexes,
-   Semaphores,
-   Timers,
-   RW locks
-   Barriers
Thread local state
- A way to achieve isolation


var parser = new ThreadLocal<Parser>(
    () => CreateParser());

Parallel.ForEach(items,
    item => parser.Value.Parse(item));
Thread pools
ThreadPool.QueueUserWorkItem(_ =>
    {
        // do some work
    });
Async
Task.Factory.StartNew(() =>
    {
        //...
        return LoadDataFromFile();
    })
    .ContinueWith(dataItems =>
        {
            WriteToDatabase(dataItems.Result);
        })
    .ContinueWith(t =>
        {
            // ...
        });
Async
var dataItems =
    await LoadDataFromFileAsync();

textBox.Text = dataItems.Count.ToString();

await WriteToDatabaseAsync(dataItems);

// continue work
Технології
-   TPL, PLINQ, C# async, TPL Dataflow
-   PPL, Intel TBB, OpenMP
-   CUDA, OpenCL, C++ AMP
-   Actors, STM
-   Many others
Підсумок
-   Програмування для багатьох CPU
-   Concurrency != parallelism
-   CPU-bound vs. I/O-bound tasks
-   Private vs. shared state
Підсумок
- Managing state:
  - Isolation
  - Immutability
  - Synchronization
     - Data: mutual exclusion
     - Control: notifications
Підсумок
- Паралелізм:
  - Data parallelism: scalable
  - Task parallelism: less scalable
  - Message based parallelism
Підсумок
- Data parallelism
  -   CoBegin
  -   Parallel ForAll
  -   Parallel ForEach
  -   Parallel ForEach over complex data structures
  -   Declarative data parallelism
- Challenges: partitioning, scheduling, ordering,
  merging, aggregation, concurrency hazards
Підсумок
- Task parallelism: structured, unstructured
  - Fork/Join
     - CoBegin
     - Recursive decomposition
  - Futures
  - Continuations
  - Producer/consumer (pipelines)
- Challenges: scheduling, cancellation,
  exceptions, concurrency hazards
Підсумок
- Засоби/інструменти
  -   Компілятори, бібліотеки
  -   Concurrent data structures
  -   Synchronization primitives
  -   Thread local state
  -   Thread pools
  -   Async invocations
  -   ...
Q/A

Contenu connexe

Tendances

Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3PoguttuezhiniVP
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLJohn David Duncan
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelinesTimothy Farkas
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenPostgresOpen
 
Tulsa techfest Spark Core Aug 5th 2016
Tulsa techfest Spark Core Aug 5th 2016Tulsa techfest Spark Core Aug 5th 2016
Tulsa techfest Spark Core Aug 5th 2016Mark Smith
 
Oracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive PlansOracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive PlansFranck Pachot
 
Introduction to MapReduce and Hadoop
Introduction to MapReduce and HadoopIntroduction to MapReduce and Hadoop
Introduction to MapReduce and HadoopMohamed Elsaka
 
CBO choice between Index and Full Scan: the good, the bad and the ugly param...
CBO choice between Index and Full Scan:  the good, the bad and the ugly param...CBO choice between Index and Full Scan:  the good, the bad and the ugly param...
CBO choice between Index and Full Scan: the good, the bad and the ugly param...Franck Pachot
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationmysqlops
 
Anatomy of classic map reduce in hadoop
Anatomy of classic map reduce in hadoop Anatomy of classic map reduce in hadoop
Anatomy of classic map reduce in hadoop Rajesh Ananda Kumar
 
Event Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data ProcessorsEvent Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data ProcessorsInvenire Aude
 
Nhibernate Part 2
Nhibernate   Part 2Nhibernate   Part 2
Nhibernate Part 2guest075fec
 

Tendances (14)

Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
 
Micro services workshop
Micro services workshopMicro services workshop
Micro services workshop
 
Developing for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQLDeveloping for Node.JS with MySQL and NoSQL
Developing for Node.JS with MySQL and NoSQL
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelines
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
 
Tulsa techfest Spark Core Aug 5th 2016
Tulsa techfest Spark Core Aug 5th 2016Tulsa techfest Spark Core Aug 5th 2016
Tulsa techfest Spark Core Aug 5th 2016
 
Oracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive PlansOracle Join Methods and 12c Adaptive Plans
Oracle Join Methods and 12c Adaptive Plans
 
Introduction to MapReduce and Hadoop
Introduction to MapReduce and HadoopIntroduction to MapReduce and Hadoop
Introduction to MapReduce and Hadoop
 
CBO choice between Index and Full Scan: the good, the bad and the ugly param...
CBO choice between Index and Full Scan:  the good, the bad and the ugly param...CBO choice between Index and Full Scan:  the good, the bad and the ugly param...
CBO choice between Index and Full Scan: the good, the bad and the ugly param...
 
Pig
PigPig
Pig
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimization
 
Anatomy of classic map reduce in hadoop
Anatomy of classic map reduce in hadoop Anatomy of classic map reduce in hadoop
Anatomy of classic map reduce in hadoop
 
Event Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data ProcessorsEvent Processing and Integration with IAS Data Processors
Event Processing and Integration with IAS Data Processors
 
Nhibernate Part 2
Nhibernate   Part 2Nhibernate   Part 2
Nhibernate Part 2
 

En vedette

Selecting BI Tool - Proof of Concept - Андрій Музичук
Selecting BI Tool - Proof of Concept - Андрій МузичукSelecting BI Tool - Proof of Concept - Андрій Музичук
Selecting BI Tool - Proof of Concept - Андрій МузичукIgor Bronovskyy
 
Юрчук Андрій - Технологія Qt
Юрчук Андрій - Технологія QtЮрчук Андрій - Технологія Qt
Юрчук Андрій - Технологія QtIgor Bronovskyy
 
03 - chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)
03 -  chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)03 -  chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)
03 - chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)Igor Bronovskyy
 
Delivering business intelligence - Rava
Delivering business intelligence - RavaDelivering business intelligence - Rava
Delivering business intelligence - RavaIgor Bronovskyy
 
11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...
11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...
11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...Igor Bronovskyy
 
Mobile market - Ivasyshyn
Mobile market - IvasyshynMobile market - Ivasyshyn
Mobile market - IvasyshynIgor Bronovskyy
 
From web to mobile - Василь Кричун
From web to mobile - Василь КричунFrom web to mobile - Василь Кричун
From web to mobile - Василь КричунIgor Bronovskyy
 
Code driven testing -- oleksandr pavlyshak
Code driven testing -- oleksandr pavlyshakCode driven testing -- oleksandr pavlyshak
Code driven testing -- oleksandr pavlyshakIgor Bronovskyy
 
Improve performance of developer - Khodak
Improve performance of developer  - KhodakImprove performance of developer  - Khodak
Improve performance of developer - KhodakIgor Bronovskyy
 
Техніки швидкого читання - Любомир Ходак
Техніки швидкого читання - Любомир ХодакТехніки швидкого читання - Любомир Ходак
Техніки швидкого читання - Любомир ХодакIgor Bronovskyy
 
Правила конкурсного відбору для студентів ВНЗ м. Івано-Франківська у 2014 ро...
Правила конкурсного відбору  для студентів ВНЗ м. Івано-Франківська у 2014 ро...Правила конкурсного відбору  для студентів ВНЗ м. Івано-Франківська у 2014 ро...
Правила конкурсного відбору для студентів ВНЗ м. Івано-Франківська у 2014 ро...Igor Bronovskyy
 
огляд і особливості Symfony 2.0 - Анатолій Квасніков
огляд і особливості Symfony 2.0  - Анатолій Квасніковогляд і особливості Symfony 2.0  - Анатолій Квасніков
огляд і особливості Symfony 2.0 - Анатолій КвасніковIgor Bronovskyy
 
Скільки коштує проект і чому так.....
Скільки коштує проект і чому так.....Скільки коштує проект і чому так.....
Скільки коштує проект і чому так.....Igor Bronovskyy
 
12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...
12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...
12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...Igor Bronovskyy
 
Побудова ефективної команди - Андрій Бабала
Побудова ефективної команди - Андрій БабалаПобудова ефективної команди - Андрій Бабала
Побудова ефективної команди - Андрій БабалаIgor Bronovskyy
 

En vedette (19)

Selecting BI Tool - Proof of Concept - Андрій Музичук
Selecting BI Tool - Proof of Concept - Андрій МузичукSelecting BI Tool - Proof of Concept - Андрій Музичук
Selecting BI Tool - Proof of Concept - Андрій Музичук
 
Юрчук Андрій - Технологія Qt
Юрчук Андрій - Технологія QtЮрчук Андрій - Технологія Qt
Юрчук Андрій - Технологія Qt
 
03 - chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)
03 -  chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)03 -  chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)
03 - chomu prohramisty ne testuiut - yurii chulovskyi - it event 2013 (5)
 
Delivering business intelligence - Rava
Delivering business intelligence - RavaDelivering business intelligence - Rava
Delivering business intelligence - Rava
 
Usability - Sadygov
Usability - SadygovUsability - Sadygov
Usability - Sadygov
 
11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...
11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...
11 - rozrobka prohramnoho zabezpechennia dlia vbudovanykh system - dmytro and...
 
Mobile market - Ivasyshyn
Mobile market - IvasyshynMobile market - Ivasyshyn
Mobile market - Ivasyshyn
 
From web to mobile - Василь Кричун
From web to mobile - Василь КричунFrom web to mobile - Василь Кричун
From web to mobile - Василь Кричун
 
Code driven testing -- oleksandr pavlyshak
Code driven testing -- oleksandr pavlyshakCode driven testing -- oleksandr pavlyshak
Code driven testing -- oleksandr pavlyshak
 
Improve performance of developer - Khodak
Improve performance of developer  - KhodakImprove performance of developer  - Khodak
Improve performance of developer - Khodak
 
Техніки швидкого читання - Любомир Ходак
Техніки швидкого читання - Любомир ХодакТехніки швидкого читання - Любомир Ходак
Техніки швидкого читання - Любомир Ходак
 
Strus
StrusStrus
Strus
 
Kordyak
KordyakKordyak
Kordyak
 
Правила конкурсного відбору для студентів ВНЗ м. Івано-Франківська у 2014 ро...
Правила конкурсного відбору  для студентів ВНЗ м. Івано-Франківська у 2014 ро...Правила конкурсного відбору  для студентів ВНЗ м. Івано-Франківська у 2014 ро...
Правила конкурсного відбору для студентів ВНЗ м. Івано-Франківська у 2014 ро...
 
огляд і особливості Symfony 2.0 - Анатолій Квасніков
огляд і особливості Symfony 2.0  - Анатолій Квасніковогляд і особливості Symfony 2.0  - Анатолій Квасніков
огляд і особливості Symfony 2.0 - Анатолій Квасніков
 
Скільки коштує проект і чому так.....
Скільки коштує проект і чому так.....Скільки коштує проект і чому так.....
Скільки коштує проект і чому так.....
 
Aws - Marfej
Aws - MarfejAws - Marfej
Aws - Marfej
 
12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...
12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...
12 - gradle. evoliutsiia system avtomatychnoi zbirky - sviatoslav babych - it...
 
Побудова ефективної команди - Андрій Бабала
Побудова ефективної команди - Андрій БабалаПобудова ефективної команди - Андрій Бабала
Побудова ефективної команди - Андрій Бабала
 

Similaire à Parallel programming patterns - Олександр Павлишак

Hadoop Introduction
Hadoop IntroductionHadoop Introduction
Hadoop IntroductionSNEHAL MASNE
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)Ortus Solutions, Corp
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...Ortus Solutions, Corp
 
Simplifying Apache Cascading
Simplifying Apache CascadingSimplifying Apache Cascading
Simplifying Apache CascadingMing Yuan
 
Sherlock Homepage (Maarten Balliauw)
Sherlock Homepage (Maarten Balliauw)Sherlock Homepage (Maarten Balliauw)
Sherlock Homepage (Maarten Balliauw)Visug
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Maarten Balliauw
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Maarten Balliauw
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/MultitaskingSasha Kravchuk
 
Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot NetNeeraj Kaushik
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLArie Leeuwesteijn
 
Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper David Paquette
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel ProcessingRTigger
 
Pegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computationsPegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computationsRafael Ferreira da Silva
 
A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark Anyscale
 
Eagle from eBay at China Hadoop Summit 2015
Eagle from eBay at China Hadoop Summit 2015Eagle from eBay at China Hadoop Summit 2015
Eagle from eBay at China Hadoop Summit 2015Hao Chen
 
Data Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby UsageData Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby UsageSATOSHI TAGOMORI
 
Hadoop institutes in Bangalore
Hadoop institutes in BangaloreHadoop institutes in Bangalore
Hadoop institutes in Bangaloresrikanthhadoop
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio
 

Similaire à Parallel programming patterns - Олександр Павлишак (20)

Hadoop Introduction
Hadoop IntroductionHadoop Introduction
Hadoop Introduction
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
 
Simplifying Apache Cascading
Simplifying Apache CascadingSimplifying Apache Cascading
Simplifying Apache Cascading
 
Sherlock Homepage (Maarten Balliauw)
Sherlock Homepage (Maarten Balliauw)Sherlock Homepage (Maarten Balliauw)
Sherlock Homepage (Maarten Balliauw)
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...
 
.NET Multithreading/Multitasking
.NET Multithreading/Multitasking.NET Multithreading/Multitasking
.NET Multithreading/Multitasking
 
Parallel Programming With Dot Net
Parallel Programming With Dot NetParallel Programming With Dot Net
Parallel Programming With Dot Net
 
Async and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NLAsync and parallel patterns and application design - TechDays2013 NL
Async and parallel patterns and application design - TechDays2013 NL
 
Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper
 
Parallel Processing
Parallel ProcessingParallel Processing
Parallel Processing
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Pegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computationsPegasus - automate, recover, and debug scientific computations
Pegasus - automate, recover, and debug scientific computations
 
A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark A Deep Dive into Structured Streaming in Apache Spark
A Deep Dive into Structured Streaming in Apache Spark
 
Eagle from eBay at China Hadoop Summit 2015
Eagle from eBay at China Hadoop Summit 2015Eagle from eBay at China Hadoop Summit 2015
Eagle from eBay at China Hadoop Summit 2015
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Data Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby UsageData Analytics Service Company and Its Ruby Usage
Data Analytics Service Company and Its Ruby Usage
 
Hadoop institutes in Bangalore
Hadoop institutes in BangaloreHadoop institutes in Bangalore
Hadoop institutes in Bangalore
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 

Dernier

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Dernier (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 

Parallel programming patterns - Олександр Павлишак

  • 1. Parallel Programming Patterns Аудиторія: розробники Олександр Павлишак, 2011 pavlyshak@gmail.com
  • 2. Зміст - Тренд - Основні терміни - Managing state - Паралелізм - Засоби
  • 6. Що відбувається? - Ріст частоти CPU вповільнився - Через фізичні обмеження - Free lunch is over - ПЗ більше не стає швидшим саме по собі
  • 7. Сучасні тренди - Manycore, multicore - GPGPU, GPU acceleration, heterogeneous computing - Distributed computing, HPC
  • 8. Основні поняття - Concurrency - Many interleaved threads of control - Parallelism - Same result, but faster - Concurrency != Parallelism - It is not always necessary to care about concurrency while implementing parallelism - Multithreading - Asynchrony
  • 9. Задачі - CPU-bound - number crunching - I/O-bound - network, disk
  • 10. Стан - Shared - accessible by more than one thread - sharing is transitive - Private - used by single thread only
  • 11. Task-based program Application Tasks (CPU, I/O) Runtime (queuing, scheduling) Processors (threads, processes)
  • 13. Isolation - Avoiding shared state - Own copy of state - Examples: - process isolation - intraprocess isolation - by convention
  • 14. Immutability - Multiple read -- not a problem! - All functions are pure - Requires immutable collections - Functional way: Haskell, F#, Lisp
  • 15. Synchronization - The only thing that remains to deal with shared mutable state - Kinds: - data synchronization - control synchronization
  • 16. Data synchronization - Why? To avoid race conditions and data corruption - How? Mutual exclusion - Data remains consistent - Critical regions - locks, monitors, critical sections, spin locks - Code-centered - rather than associated with data
  • 17. Critical region |Thread 1 |Thread 2 |// ... |// ... |lock (locker) | |{ | | // ... | | data.Operation(); | | // ... | |} | |// ... |lock (locker) | |{ | | // ... | | data.Operation(); | // ...
  • 18. Control synchronization - To coordinate control flow - exchange data - orchestrate threads - Waiting, notifications - spin waiting - events - alternative: continuations
  • 19. Three ways to manage state - Isolation: simple, loosely coupled, highly scalable, right data structures, locality - Immutability: avoids sync - Synchronization: complex, runtime overheads, contention - in that order
  • 21. Підходи до розбиття задач - Data parallelism - Task parallelism - Message based parallelism
  • 22. Data parallelism How? - Data is divided up among hardware processors - Same operation is performed on elements - Optionally -- final aggregation
  • 23. Data parallelism When? - Large amounts of data - Processing operation is costly - or both
  • 24. Data parallelism Why? - To achieve speedup - For example, with GPU acceleration: - hours instead of days!
  • 25. Data parallelism Embarrassingly parallel problems - parallelizable loops - image processing Non-embarrassingly parallel problems - parallel QuickSort
  • 26. Data parallelism ... ... Thread 1 Thread 2
  • 27. Data parallelism Structured parallelism - Well defined begin and end points - Examples: - CoBegin - ForAll
  • 28. CoBegin var firstDataset = new DataItem[1000]; var secondDataset = new DataItem[1000]; var thirdDataset = new DataItem[1000]; Parallel.Invoke( () => Process(firstDataset), () => Process(secondDataset), () => Process(thirdDataset) );
  • 29. Parallel For var items = new DataItem[1000 * 1000]; // ... Parallel.For(0, items.Length, i => { Process(items[i]); });
  • 30. Parallel ForEach var tickers = GetNasdaqTickersStream(); Parallel.ForEach(tickers, ticker => { Process(ticker); });
  • 31. Striped Partitioning ... Thread 1 Thread 2
  • 32. Iterate complex data structures var tree = new TreeNode(); // ... Parallel.ForEach( TraversePreOrder(tree), node => { Process(node); });
  • 33. Iterate complex data Thread 1 Thread 2 ...
  • 34. Declarative parallelism var items = new DataItem[1000 * 1000]; // ... var validItems = from item in items.AsParallel() let processedItem = Process(item) where processedItem.Property > 42 select Convert(processedItem); foreach (var item in validItems) { // ... }
  • 35. Data parallelism Challenges - Partitioning - Scheduling - Ordering - Merging - Aggregation - Concurrency hazards: data races, contention
  • 36. Task parallelism How? - Programs are already functionally partitioned: statements, methods etc. - Run independent pieces in parallel - Control synchronization - State isolation
  • 37. Task parallelism Why? - To achieve speedup
  • 38. Task parallelism Kinds - Structured - clear begin and end points - Unstructured - often demands explicit synchronization
  • 39. Fork/join - Fork: launch tasks asynchronously - Join: wait until they complete - CoBegin, ForAll - Recursive decomposition
  • 40. Fork/join Task 1 Task 2 Task 3 Seq Seq
  • 41. Fork/join Parallel.Invoke( () => LoadDataFromFile(), () => SavePreviousDataToDB(), () => RenewOtherDataFromWebService());
  • 42. Fork/join Task loadData = Task.Factory.StartNew(() => { // ... }); Task saveAnotherDataToDB = Task.Factory.StartNew(() => { // ... }); // ... Task.WaitAll(loadData, saveAnotherDataToDB); // ...
  • 43. Fork/join void Walk(TreeNode node) { var tasks = new[] { Task.Factory.StartNew(() => Process(node.Value)), Task.Factory.StartNew(() => Walk(node.Left)), Task.Factory.StartNew(() => Walk(node.Right)) }; Task.WaitAll(tasks); }
  • 44. Fork/join recursive Root Node Left Seq Left Seq Right Right Node Left Right
  • 45. Dataflow parallelism: Futures Task<DataItem[]> loadDataFuture = Task.Factory.StartNew(() => { //... return LoadDataFromFile(); }); var dataIdentifier = SavePreviousDataToDB(); RenewOtherDataFromWebService(dataIdentifier); //... DisplayDataToUser(loadDataFuture.Result);
  • 46. Dataflow parallelism: Futures Future Seq Seq Seq
  • 47. Dataflow parallelism: Futures Future Future Future Seq Seq Seq Seq Seq
  • 48. Continuations Task Task Task Seq Seq Seq
  • 49. Continuations var loadData = Task.Factory.StartNew(() => { return LoadDataFromFile(); }); var writeToDB = loadData.ContinueWith(dataItems => { WriteToDatabase(dataItems.Result); }); var reportToUser = writeToDB.ContinueWith(t => { // ... }); reportProgressToUser.Wait();
  • 50. Producer/consumer pipeline reading parsing storing parsed lines DB lines
  • 51. Producer/consumer pipeline lines parsed lines DB
  • 52. Producer/consumer var lines = new BlockingCollection<string>(); Task.Factory.StartNew(() => { foreach (var line in File.ReadLines(...)) lines.Add(line); lines.CompleteAdding(); });
  • 53. Producer/consumer var dataItems = new BlockingCollection<DataItem>(); Task.Factory.StartNew(() => { foreach (var line in lines.GetConsumingEnumerable() ) dataItems.Add(Parse(line)); dataItems.CompleteAdding(); });
  • 54. Producer/consumer var dbTask = Task.Factory.StartNew(() => { foreach (var item in dataItems.GetConsumingEnumerable() ) WriteToDatabase(item); }); dbTask.Wait();
  • 55. Task parallelism Challenges - Scheduling - Cancellation - Exception handling - Concurrency hazards: deadlocks, livelocks, priority inversions etc.
  • 56. Message based parallelism - Accessing shared state vs. local state - No distinction, unfortunately - Idea: encapsulate shared state changes into messages - Async events - Actors, agents
  • 58. Concurrent data structures - Concurrent Queues, Stacks, Sets, Lists - Blocking collections, - Work stealing queues - Lock free data structures - Immutable data structures
  • 59. Synchronization primitives - Critical sections, - Monitors, - Auto- and Manual-Reset Events, - Coundown Events, - Mutexes, - Semaphores, - Timers, - RW locks - Barriers
  • 60. Thread local state - A way to achieve isolation var parser = new ThreadLocal<Parser>( () => CreateParser()); Parallel.ForEach(items, item => parser.Value.Parse(item));
  • 62. Async Task.Factory.StartNew(() => { //... return LoadDataFromFile(); }) .ContinueWith(dataItems => { WriteToDatabase(dataItems.Result); }) .ContinueWith(t => { // ... });
  • 63. Async var dataItems = await LoadDataFromFileAsync(); textBox.Text = dataItems.Count.ToString(); await WriteToDatabaseAsync(dataItems); // continue work
  • 64. Технології - TPL, PLINQ, C# async, TPL Dataflow - PPL, Intel TBB, OpenMP - CUDA, OpenCL, C++ AMP - Actors, STM - Many others
  • 65. Підсумок - Програмування для багатьох CPU - Concurrency != parallelism - CPU-bound vs. I/O-bound tasks - Private vs. shared state
  • 66. Підсумок - Managing state: - Isolation - Immutability - Synchronization - Data: mutual exclusion - Control: notifications
  • 67. Підсумок - Паралелізм: - Data parallelism: scalable - Task parallelism: less scalable - Message based parallelism
  • 68. Підсумок - Data parallelism - CoBegin - Parallel ForAll - Parallel ForEach - Parallel ForEach over complex data structures - Declarative data parallelism - Challenges: partitioning, scheduling, ordering, merging, aggregation, concurrency hazards
  • 69. Підсумок - Task parallelism: structured, unstructured - Fork/Join - CoBegin - Recursive decomposition - Futures - Continuations - Producer/consumer (pipelines) - Challenges: scheduling, cancellation, exceptions, concurrency hazards
  • 70. Підсумок - Засоби/інструменти - Компілятори, бібліотеки - Concurrent data structures - Synchronization primitives - Thread local state - Thread pools - Async invocations - ...
  • 71. Q/A