Вы находитесь на странице: 1из 2

Shared Address Space

Thread-is a single stream of control in the flow of a program Consider the following code segment that computes the product of two dense matrices of size n x n.

This for loop has n^2 iterationshas n^2 threads which could be executed independently

Instead use the above function that calls another function, create_thread, a C function to define a thread, allowing the loop to be spread over multiple processes Logical Memory Model o All memory is globally accessible to every thread o Since threads are invoked as function calls, the stack corresponding to the function call is treated as being local to the thread Since threads are scheduled at run time, it is not possible to determine which stacks are livedo not treat stacks as global Below, in figure, M=memory modules, holding thread-local(stack-allocated) data. P=threads

Advantages of Threads over Message Passing o Software Portability Threaded applications can be developed on serial machines and run on parallel machines without any changes.-good since supercomputer time is often expensive and scarce o Latency Hiding One of the major overheads in programs (both serial and parallel) is the access latency for memory access, I/O, and communication. By allowing multiple threads to execute on the same processor, threaded APIs enable this latency to be hidden

i.e. while one thread is waiting for a communication operation, other threads can utilize the CPU, thus masking associated overhead. o Scheduling and Load Balancing Threaded APIs allow the programmer to specify a large number of concurrent tasks and support system-level dynamic mapping of tasks to processors with a view to minimizing idling overheads By providing this support at the system level, threaded APIs rid the programmer of the burden of explicit scheduling and load balancing. o Ease of Programming, Widespread Use Threaded programs are significantly easier to write than corresponding programs using message passing APIs-due to above reasons Achieving identical levels of performance for the two programs may require additional effort, however POSIX Thread API o Basics: Creation and Termination

Creates a single thread that corresponds to invocation of the function thread_function Once successful creation of a thread has occurred, a unique identifier is associated with the thread and assigned to the location pointed to by thread_handle This thread has the attributes described by the attribute argumentif NULL, a thread with default attributes is created.

Вам также может понравиться