Wednesday, February 18, 2009

What is multi-processing? What is multi-tasking? What is multi-threading? What is multi-programming?

Multi tasking, programming and time sharing are variations of the same thing.

Single tasking is a system where once a programme starts, no other programme can run until it has ended. Eg early home computers, you loaded a prog. ran it then moved on to the next prog.

Multi tasking/programming/ time sharing is where several progs are running at the same time, but only 1 prog is actually being worked on at any moment in time. The system will share its time between progs that need some action, but always only 1 prog at a time. If a prog needs data from disk/ram it will wait for the data to arrive. This time is used to work on other progs that already have the data needed. The earliest versions of this merely "time sliced" or shared equally between progs whether they needed time or not.

Multi processing is where you have, for example, 2 processors that allows work to be done on 2 progs at the same time. Big servers start at 32 processors and go up from there.

Lets say that you need to add 2 numbers, the hardware sequence runs something like:-
    Fetch the instruction
    Decode it
    fetch the 1st number from memory store in a register
    fetch the 2nd number etc etc
    add the 2 numbers and store the result in another register.

Multi threading allows several parts of the program to be processed without waiting for the first instruction to finish.

In the above example, each step is undertaken by a different part of the hardware, so when our instruction above has been fetched, it goes away and fetches the next instruction, so all the steps of instructions are working their way through a "pipeline". Modern processors have multi pipelines to make things even quicker. This is why some processors with a lower clock speed can out perform other CPUs. This effectively simulates multiprocessing as different progs can be in different pipelines (hyperthreading).

It is not unusual to have multiple processors, with multiple pipelines working on 1 prog. Usually something like weather forcasting where lots of similar data from many sources needs manipulating.

No comments: