











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












docsity.com
2
The RAM (Random Access Machine) model of computation assumes: There is a single processing unit There is an arbitrarily large amount of memory Accessing any arbitrarily chosen (i.e. random) memory location takes unit time
This simple model is very useful guide for algorithm design For maximum efficiency, “tuning” to the particular hardware is required
The RAM model breaks down when the assumptions are violated If an array is so large that only a portion of it fits in memory (the rest is on disk), very different sorting algorithms should be used
docsity.com
4
An obvious extension to the RAM model is the Parallel Random Access model, which assumes: There are multiple processing units There is an arbitrarily large amount of memory Accessing any memory location takes unit time
The third assumption is “good enough” for many in-memory sequential programs, but not good enough for parallel programs If the processing units share memory, then complicated and expensive synchronization mechanisms must be used If the processing units do not share memory, then each has its own (fast) local memory, and communicates with other processes by sending messages to them (much slower--especially if over a network!)
Bottom line: Because there seems to be no way to meet the unit time assumption, the PRAM model is seriously broken!
docsity.com
5
There are P standard sequential processors, each with its own local memory One of the processors may be acting as “controller,” doing things like initialization and synchronization Processors can access non-local memory over a communication network Non-local memory is between 100 times and 10000 times slower to access than local memory (based on common architectures) A processor can make only a very small number (maybe 1 or
docsity.com
7
It would be great if having N processors meant our programs would run N times as fast, but...
There is overhead involved in setting up the parallelism, which we don’t need to pay for a sequential program
There are parts of any program that cannot be parallelized
Some processors will be idle because there is nothing for them to do
Processors have to contend for the same resources, such as memory, and may have to wait for one another
docsity.com
8
Overhead is any cost incurred by the parallel algorithm but not by the corresponding sequential algorithm Communication among threads and processes (a single thread has no other threads with which to communicate) Synchronization is when one thread or process has to wait for results or events from another thread or process Contention for a shared resource, such as memory Java’s synchronized is used to wait for a lock to become free Extra computation to combine the results of the various threads or processes Extra memory may be needed to give each thread or process the memory required to do its job
docsity.com
10
If 75% of a process can be parallelized, and there are four processors, then the possible speedup is 1 / ((1 - 0.75) + 0.75/4) = 2.
But with 40 processors--ten times as many--the speedup is only 1 / ((1 - 0.75) + 0.75/40) = 3.
This has led many people (including Amdahl) to conclude that having lots of processors won’t help very much
However....
For many problems, as the data set gets larger, The inherently sequential part of the program remains (fairly) constant Thus, the sequential proportion P becomes smaller So: The greater the volume of data, the more speedup we can get
docsity.com
11
There is a load imbalance-- one process may have much less work to do than another A process must wait for access to memory or some other shared resource Data is registers is most quickly accessed Data in a cache is next most quickly accessed A level 1 cache is the fastest, but also the smallest A level 2 cache is larger, but slower Memory--RAM--is much slower Disk access is very much slower
docsity.com
There are various competing Java packages (such as Akka and Kilim) to support message passing, but nothing yet in the official Java release
Scala’s message passing is based on Erlang
docsity.com 13
docsity.com 14
Shared memory model—as in Java.
Actors An actor is a lightweight thread with its own private memory Actors can send messages to one another Messages are received in an actor’s “mailbox” (a queue) Actors can monitor the health of other actors
STM, Software Transactional Memory A copy is made of the input data to a function The function is computed The input data is compared to the current values of that data If nothing has changed, the function result is stored If the input data has changed, the result is discarded and the function is tried again with the new data
docsity.com 16
A function is a value It can be assigned to variables It can be passed as an argument to another function It can be returned as the result of a function call There are much briefer ways of writing a literal function Scala example: a => 101 * a A function acts like a function in mathematics If you call it with the same arguments, you will get the same result. Every time. Guaranteed. Functions have no side effects Immutable values are strongly emphasized over mutable values Some languages, such as Haskell, don’t allow mutable values at all Computation proceeds by the application of functions, not by changing the state of mutable variables
docsity.com 17
Instead of getting faster processors, we’re now getting more of them Consequently, parallelism, and concurrency, have become much more important
docsity.com 19