Distributed Shared Memory
Distributed Shared Memory
Distributed Shared Memory
Chapter 9
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-2
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-3
DSM System
Still need messages or mechanisms to get data to processor, but
these are hidden from the programmer:
Interconnection
network
Messages
Processor Computers
Memory
Shared memory
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-4
Advantages of DSM
• System scalable
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-5
Disadvantages of DSM
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-6
• Hardware
• Software
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-7
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-8
Memory
Page
Virtual memory fault
page table
Processors
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-9
• Treadmarks
Page based DSM system
Apparently not now available
• JIAJIA
C based
Obtained at UNC-Charlotte but required significant
modifications for our system (in message-passing calls)
• Adsmith object based
C++ library routines
We have this installed on our cluster - chosen for teaching
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-10
Consistency Models
• Strict Consistency - Processors sees most recent update,
i.e. read returns the most recent wrote to location.
• Sequential Consistency - Result of any execution same as
an interleaving of individual programs.
• Relaxed Consistency- Delay making write visible to reduce
messages.
• Weak consistency - programmer must use synchronization
operations to enforce sequential consistency when
necessary.
• Release Consistency - programmer must use specific
synchronization operators, acquire and release.
• Lazy Release Consistency - update only done at time of
acquire.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-11
Strict Consistency
Every write immediately visible
write(y)
read(x)
read(y)
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-12
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-13
Release Consistency
Process A Process B
acquire(lock1)
write(x)
write(y)
release(lock1)
acquire(lock1)
read(x)
read(y)
release(lock1)
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-14
Process A Process B
acquire(lock1)
write(x)
write(y)
release(lock1)
acquire(lock1)
read(x)
read(y)
release(lock1)
Adsmith
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-16
Adsmith
• User-level libraries that create distributed shared memory
system on a cluster.
• Object based DSM - memory seen as a collection of
objects that can be shared among processes on different
processors.
• Written in C++
• Built on top of pvm
• Freely available - installed on UNCC cluster
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-17
Adsmith Routines
These notes are based upon material in Adsmith User Interface
document.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-18
Initialization/Termination
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-19
Process Creation
adsm_spawn(filename, count)
Example
adsm_spawn(“prog1”,10);
Process “join”
adsmith_wait();
will cause the process to wait for all its child processes (processes it
created) to terminate.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-21
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-22
adsm_refresh()
adsm_flush()
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-23
Synchronization accesses
• Semaphores
• Mutex’s (Mutual exclusion variables)
• Barriers.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-24
Semaphore routines
Four routines:
wait()
signal()
set()
get().
class AdsmSemaphore {
public:
AdsmSemaphore( char *identifier, int init = 1 );
void wait();
void signal();
void set( int value);
void get();
};
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-25
Two routines
lock
unlock()
class AdsmMutex {
public:
AdsmMutex( char *identifier );
void lock();
void unlock();
};
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-26
Example
int *sum;
AdsmMutex x(“mutex”);
x.lock();
adsm_refresh(sum);
*sum += partial_sum;
adsm_flush(sum);
x.unlock();
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-27
Barrier Routines
barrier()
class AdsmBarrier {
public:
AdsmBarrier( char *identifier );
void barrier( int count);
};
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-28
Example
AdsmBarrier barrier1(“sample”);
.
.
barrier1.barrier(procno);
.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-29
Non-synchronization Accesses
refresh and flush take place on home location (rather than locally)
and immediately.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-30
• Prefetch
• Bulk Transfer
• Combined routines for critical sections
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-31
Prefetch
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-32
Bulk Transfer
enum AdsmBulkType {
adsmBulkBegin,
AdsmBulkEnd
}
Example
adsm_refresh(AdsmBulkBegin);
adsm_refresh(x);
adsm_refresh(y);
adsm_refresh(z);
adsm_refresh(AdsmBulkEnd);
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-34
adsm_atomic_begin()
adsm_atomic_end()
Acquire adsm_atomic_begin()
Refresh
local code
Flush
Release adsm_atomic_end()
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-35
Example
int *x = (int*)adsm_malloc)”x”,sizeofint(int));
adsm_atomic(x,”[int] @=@+10”);
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-36
Collect Access
Example
(from page 10 of Adsmith User Interface document):
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-37
Other Features
Pointers
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-38
Message passing
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-39
For getting host ids (zero to number of hosts -1) or process id (zero
to number of processes -1):
int adsm_procno();
- Returns process id of calling process.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-40
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-41
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-42
Reader/Writer Policies
• Single reader/single writer policy - simple to do with
centralized servers
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-43
Request current
value of x update x to x’
return
current
(local) int x; value of x (local) int x;
read(x)
acknowledge
write completed
write(x, x’);
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-44
read(x)
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-45
Request current
value of x update x to x’
if local copy invalid
return
Process current Process
value of x
(local) int x; (local) int x;
invalidate x
message
read(x)
write(x, x’);
acknowledge
write completed
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-46
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-47
Overlapping Regions
Example
Processor/computer
Pi
Sphere of influence
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-48
Communication Switch
Data region
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-49
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-50
Servers
Processes
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.
slides9-51
DSM Projects
• Write a DSM system in C++ using MPI for the
underlying message-passing and process
communication.
• Write a DSM system in Java using MPI for the
underlying message-passing and process
communication.
• (More advanced) One of the fundamental
disadvantages of software DSM system is the lack of
control over the underlying message passing. Provide
parameters in a DSM routine to be able to control the
message-passing. Write routines that allow
communication and computation to be overlapped.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, 2004 Pearson Education Inc. All rights reserved.