Parallelism

Purposes


Biological Parallelism

(Neural Networks)

Humans are smarter than computers.

Yet human neurons switch at rate of about

1 per 10-3 sec

while computer logic elements switch at rate of

1 per 10-9 sec,

106x faster


Human brain has about

1010 neurons

and 1013 connections between them.

 

Computer has a few million logic gates.


Humans are smarter because their neurons work in a more highly parallel fashion.


Parallelism can be exploited at many levels.
Logic Level


Instruction Execution Level


Process Level

A process is a program in execution.

Many processes can be run concurrently:

muliplexed among 1 processor

or

N processors


Processes by default don't share memory:

Each has its own address space

Communication is via pipes, sockets, ...


Processes on Unix Command Line

p1 & p2 & p3

p1 | p2 | p3

Processes in C code

fork( )

(returns id of child, or 0 if child)


Thread Level

A thread is similar to a process, but finer grain, lighter weight.

Threads are within a process, do share memory and other stuff.


Cluster/Network Level

Processes on different machines, possibly in different locations, communicate.


Languages supporting Threads

Java- built-in

rex

C/C++ depending on operating system


rex threads


Solaris threads (muddcs)


Real vs. Virtual Parallelism

Real: Separate physical processors

Virtual:

Processes are multiplexed among fewer processors

(e.g. 1 processor)


Java threads (see Ch 8, pp 210,211)

2 models:

(1) is simpler, easier to understand

(2) is used in all most Applets

Once you see (1), it is easier to see (2).


extends Thread model

See BouncingBalls (source BouncingBalls.java) for example.


Bouncing Balls

Each has its own state.


implements Runnable model

See source AltBouncingBalls.java for example.


Synchronization

Threads can get into each other's way:

one changes variable while other is reading

Difficult debugging

Some tools:


Network-level Parallelism

The network is the computer.

Sun Microsystems


Example: Client/Server


Communication over network takes place via data abstraction called "socket".

Each networked machine provides set of logical, numbered, ports.

One machine (client) can establish communication with another (server) by knowing:

(a) server's internet address

(b) server's port



Client/Server Code

(from "Java in a Nutshell" book)

Port # is agreed upon in advance ( 6789 )

Server:


Client:



Example

Server is running on turing at port 6789.

Connect from clients on turing, muddcs, or orion

cd ~cs/cs60/java

java Client turing

(host name)

connected to 173.134....

> foobar

raboof

> ....