Distinguishes multi-processor computer architectures according to how they can be classified along the two independent dimensions of Instruction Stream and Data Stream.
Each of these dimensions can have only one of two possible states: Single or Multiple.
Parallel Architectures
Shared Memory
All processors can have access to all memory as a global address space.
Multiple processors can operate independently but share same memory resources.
Uniform Memory Access (UMA)
Shared Memory
Non-Uniform Memory Access (NUMA)
- Advantages
- User-friendly global address space
- Fast and Uniform data sharing between tasks
- Disadvantages
- Lack of scalability between memory and CPUs relationship
- Synchronization relies on programmer
Distributed Memory
Requires a communication network to connect inter-processor memory.
- Advantages
- Memory is scalable with number of CPUs
- Each CPU can rapidly access its own memory
- Cost effectiveness: can use commodity, off-the-shelf processors and networking
- Disadvantages
- Data communication is mostly responsability of the programmer
- Global memory data structures can not easily map to this memory organization
- Non-uniform memory access times
Hybrid Distributed-Shared Memory
The largest and fastest computers in the world today employ both shared and distributed memory.
- Advantages/Disadvantages
- Whatever is common to both shared and distributed memory architectures.
- Increased scalability is an important advantage
- Increased programmer complexity is an important disadvantage
Parallel Programming Pattern's Definition
In the book of Patterns for Parallel Programming from Massingill, Sanders and Mattson, there's a pattern language that helps on the process of understanding and designing parallel programs.
Finding Concurrency
Programmers should start their design of a parallel solution by analyzing the problem within the problem's domain to expose exploitable concurrency.
Is the problem large enough and the results significant enough to justify?
Algorithm Structure
Our goal is to refine the design and move it closer to a program that can execute tasks concurrently by mapping the concurrency onto multiple UEs running on a parallel computer.
The key issue at this stage is to decide which pattern or patterns are most appropriate for the problem.
Supportting Structures
We call these patterns Supporting Structures because they describe software constructions or "structures" that support the expression of parallel algorithms.
Implementation mechanisms
Create the set of UEs.
Manage interactions between them and their access to shared resources
A thread is defined as an independent stream of instructions that can be scheduled to run as such by the operating system.
Pthreads - Create / Termination (exit)
Create
#include <pthread.h>
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start)(void *), void *arg);
// Returns 0 on success, or a positive error number on error
By default, a thread is joinable, meaning that when it terminates, another thread can obtain its return status using pthread_join().
Sometimes, we don’t care about the thread’s return status; we simply want the system to automatically clean up and remove the thread when it terminates.
We can mark the thread as detached, by making a call to pthread_detach() specifying the thread’s ID.
#include <pthread.h>
int pthread_detach(pthread_t thread);
// Returns 0 on success, or a positive error number on error
We need to ensure that the function we call are thread-safe.
A bug in one thread can damage all of the threads in the process.
Each thread is competing for use of the finite virtual address space of the host process.
Dession making points
Dealing with signals in a multithreaded application requires careful design.
In a multithreaded application, all threads must be running the same program.
In a multiprocess application, different processes can run different programs.
Aside from data, threads also share certain other information.
e.g. file descriptors, signal dispositions, current working directory, and user and group IDs.