C Review

Array / pointer duality

This is useful for splitting up problems into parts

Threads

A thread is like a “virtual CPU”

Multiple threads execute within the same process

Analogy: children playing with blocks

Making threads wait their turn is called synchronization

Pthreads

Pthreads = “POSIX Threads”

A standard API for writing multithreaded programs on Unix

Also supported by Cygwin under windows.

Brief overview of API:

Important data type: pthread_t

Each child thread executes a start function. The start function is analogous to the main function in a C/C++ program (or the main method in a Java program).

[Review synopsis of each API function.]

[Write a hello world using pthreads.]

Embarrassing Parallelism

Problems that are extremely easy to solve using parallel computation are called embarrassingly parallel.

Typical structure:

Example application: computing the sum of an array of 16 bit integers.

Question: how would you parallelize this computation?

Example pthreads program: hello_pthread,c

Lab 6

Parallelize a sequential program to compute the sum of an array of 16 bit integer values.