gpars: groovy parallelism for java

Download GPars: Groovy Parallelism for Java

If you can't read please download the document

Upload: russel-winder

Post on 16-Apr-2017

1.435 views

Category:

Technology


0 download

TRANSCRIPT

GPars: Groovy Parallelism for Java

Groovy Parallelism for Java

Prof Russel WinderDirectorIt'z Interactive Ltd

e: [email protected]

e: [email protected]

t: @russel_winder

Prof Russel Winder

Company director, independent consultant, analyst, author, expert witness, trainer, mentor,

Involved with GPars, Groovy, Gant, Gradle, GroovyFX,
Python, SCons

Ex-theoretical physicist, ex-UNIX systems programmer,
ex-computer science academic. Still human.

Interstitial Advert

?

Introduction

Concurrency

A technique for doing lots of little bits of work,
one at a time, and then leaving them for later.

Co-routines.

Concurrency

Concurrency is also a technique for
simulating parallelism on a uni-processor.

Time-division multiplexing.

Concurrency

Locks, semaphores, monitors all introduced to manage shared mutable memory in the presence of concurrency.

Operating systems techniques.

Parallelism

Having more than one thing happening at the same time: multiple processors or cores working on a single program at the same time.

The only reason for
using parallelism is
to make computations
take less time.

Observation

Squirrels use locks when managing their food resources.

Some
Interaction

Question

Who is interested in harnessing parallelism
for performance improvement?

Question

Who uses synchronized in Java?

Question

Who uses synchronized in Java?

You are doing it wrong.

Question (with subsidiaries)

Who uses explicit locks in Java?Who is not using java.util.concurrent?

Who is using java.util.concurrent?

Question (with subsidiaries)

Who uses explicit locks in Java?Who is not using java.util.concurrent?

Who is using java.util.concurrent?

You are definitely doing it wrong.

Rationale

The purpose of locks is to prevent parallelism.

Locks prevent performance improvement.

Consequence

Squirrels deny parallelism of consumption.

Squirrels deny performance improvement.

Being
Positive

Forward Looking

Can Java 8 make things better?

Java 8 Streams

Internal rather than external iteration.

Functional programming approaches.

Threads as infrastructure.

This is the real biggy,programmers do not
explicitly manage threads.

Example

What is the value of ?

Easy, it's obviously.

It's simples

2009

Approximating ?

Find an estimate of the value of .

Approximate an integration with a summation.

Quadrature

Embarrassingly parallel

Addition is associative and commutative.

Sum all the areas of the rectangles.

a + b + c + d = (a + b) + (c + d)

Can sum partial sums.

Parallelism

Scatter/gather

Farmer/worker

Fork/join

Map/reduce

Code

Software Architectures

ActorsIndependent processes communicating via asynchronous exchange of messages.

CSPSequential processes connected by channels using synchronous message exchange (rendezvous).

DataflowOperators connected by channels with activity triggered by arrival of data on the channels.

Data ParallelTransform a sequence to another sequence where all individual actions happen at the same time.

Software Architectures

Data ParallelTransform a sequence to another sequence where all individual actions happen at the same time.

Software Architectures

ActorsIndependent processes communicating via asynchronous exchange of messages.

Software Architectures

DataflowOperators connected by channels with activity triggered by arrival of data on the channels.

Software Architectures

CSPSequential processes connected by channels using synchronous message exchange (rendezvous).

Software Architectures

Active ObjectsAn object that is actually an actor but looks like a full service object.

AgentsA wrapper for some shared mutable state.

Software Transactional MemoryWrappers for mutable values that uses transactions rather than locks.

Fork/JoinAn toolkit for tree structured concurrency and parallelism.

More
Code

Mantra

Squirrels deny parallelism.

Squirrels deny performance improvement.

Programmers' code should not emulate squirrel behaviour.

Endnote

Source Code

The sample codes are in a Git repository on

GitHub and my own website.

The End

Interstitial Advert

?

Groovy Parallelism for Java

Prof Russel WinderDirectorIt'z Interactive Ltd

e: [email protected]

e: [email protected]

t: @russel_winder

Click to edit the title text format

Q&A