Presentation is loading. Please wait.

Presentation is loading. Please wait.

Winter, 2004CSS490 M++1 Textbook No Corresponding Chapter Instructor: Munehiro Fukuda These slides were thoroughly the instructor’s original materials.

Similar presentations


Presentation on theme: "Winter, 2004CSS490 M++1 Textbook No Corresponding Chapter Instructor: Munehiro Fukuda These slides were thoroughly the instructor’s original materials."— Presentation transcript:

1 Winter, 2004CSS490 M++1 Textbook No Corresponding Chapter Instructor: Munehiro Fukuda These slides were thoroughly the instructor’s original materials.

2 Winter, 2004CSS490 M++2 Thread Migration overview Moving: CPU status Stack (Heap) LAN/SAN Distributed Shared Memory (in most cases) Local memory Migrating a thread Memory access Actual memory access with high latency

3 Winter, 2004CSS490 M++3 Thread Migration Examples System modelsExamplesRemark SMPActive threads Migrating threads to a different processor of SMP for dynamic load balancing DSMOlden, Nomadic threads Dispatching threads to a remote site close to data they access Message Passing uPVM, Ariadne, PM2 Injecting threads to another process for dynamic load balancing Remote Execution Nexus Sending a function/arguments with a thread to a remote for remote execution

4 Winter, 2004CSS490 M++4 M++ Mobile Agents Merits:Inherent parallelism and multi-agent-base applications Demerit:Performance problem because of their interpretation Thread Migration Merit:Fast migration Demerits:DSM needed and No navigational autonomy Logical Network Global application-specific network Constructed at run time Node data referred to after migrating that node. Extension of C++ Language Agent encapsulated by object-oriented language Navigational autonomy with strong migration

5 Winter, 2004CSS490 M++5 Multi-Agent Approach Simulate the interaction among agents Advantages: Overcomes the limitations of mathematical techniques Encapsulates simulation models Allows open-ended simulation Disadvantages: Performance Parallel programming

6 Winter, 2004CSS490 M++6 Parallelizing Multi-Agent Application with MPI MPI Process must maintain each agent as a static object maintain as a simulation space a two-dimensional array change each status periodically exchange them with remote processes Synchronize with remote processes LAN/SAN Process 1 Object Queue Obj 6 Obj 5 Obj 4 Obj 3 Obj 2 Obj 1 null Object Queue Obj 6 Obj 5 Obj 4 Obj 3 Obj 2 Obj 1 null Obj 7 Process 2 Exchange

7 Winter, 2004CSS490 M++7 Parallelizing Multi-Agent Application with Mobile Agent We don ’ t need a control process! Each simulation entity works independently as an agent. LAN/SAN agent Shark { Shark( ) { … } void run( ) { while (alive) { compute( ); go( ); }

8 Winter, 2004CSS490 M++8 Performance Problem Mobile Agents: They were cognitive agents designed to perform large remote jobs. They are code in Java and Tcl, and thus interpreted. Their size is so big and their speed is so slow. Performance Improvement: Self-migrating threads Zero-copy migration library

9 Winter, 2004CSS490 M++9 M++ Execution Model Daemon Daemon Network LAN/SAN Logical Network Node Link 123 1 3 1 hop(1@2) Link create Node with 3@2 1 Thread Physical Network

10 Winter, 2004CSS490 M++10 M++ Language Overview class Node { // Defining nodes (and links) as C++ classes public: int var; }; thread Thread { // Defining an M++ thread private: main() { // Executing its own behavior independently create node with 1;// Creating a network node, (link, and thread) hop( 1 ); // Migrating itself (and forking) node.var = 10; // Accessing the current node, (and link) } };

11 Winter, 2004CSS490 M++11 M++ Compilation Source program must have an mpp extension. may include two or more agent code. The mpp compiler first preprocesses the source code into C++ files, each corresponding to a different agent. pass them to the g++ compiler, and generates executable files, each again corresponding to a different agent. m++@MEDUSA[16]% ls Car.mpp profile m++@MEDUSA[17]% m++ Car.mpp ***** compiling GSCashier ***** compiling SportsCar ***** compiling Truck m++@MEDUSA[18]% ls Car.mpp GSCashier* SportsCar* Truck* profile m++@MEDUSA[19]% Includes three pieces of agent code Compile it with the m++ compiler Message printed out from m++ Three executable files obtained

12 Winter, 2004CSS490 M++12 M++ Profile m++@MEDUSA[21]% cat profile port 10145 hostnum 4 mode sthread describe daemonid medusa 0 mnode1 1 mnode2 2 mnode3 3 describe_end m++@MEDUSA[22]% PortA socket port # used for thread migration Hostnum# PCs constituting the system ModePthread or sthread (the latter is the M++ original thread library) IP name and daemon ID Each PC ’ s IP name and is corresponding daemon ID (>= 0).

13 Winter, 2004CSS490 M++13 M++ Daemon Invocation Run “ thrd ” on each PC Open a new window for each PC and type thrd, OR Remotely login each PC and type “ nohup thrd& ” All thrd print out “ ready for being injected ” You are ready to launch new m++ threads. m++@mnode3[4]% nohup thrd& exit [1] 6659 logout rlogin: connection closed. m++@mnode2[3]% nohup thrd& exit [1] 6678 logout rlogin: connection closed. m++@mnode1[3]% nohup thrd& exit [1] 8200 logout rlogin: connection closed. m++@MEDUSA[10]% thrd& [1] 4954 port : 10145 Connction established to medusa with daemon 0 Connction established to mnode1 with daemon 1 Connction established to mnode2 with daemon 2 Connction established to mnode3 with daemon 3 Total daemon(s) : 4 Mode : sthread Stack : 65536 byte Ready for being injected. m++@MEDUSA[11]%

14 Winter, 2004CSS490 M++14 M++ Thread Launching To launch a M++ thread, type Inject target_IPname executable_file #threads arguments To stop the M++ system Bring back one of thrds to foreground and type cntl+c m++@MEDUSA[11]% inject medusa./GSCashier 1 Injected 1./GSCashier thread(s) to medusa m++@MEDUSA[12]% GSCashier: Waiting for cars. m++@MEDUSA[12]% inject medusa./Truck 1 Injected 1./Truck thread(s) to medusa m++@MEDUSA[13]% Truck: I'm at the GasStation. GSCashier: Injected fuel to Truck Diesel: 900 Regular: 1000 GSCashier: Waiting for cars. Truck: I'm filled with fuel. m++@MEDUSA[13]% fg thrd thrd: Interrupted. thrd: Closed all connections. thrd: Terminated. m++@MEDUSA[14]%

15 Winter, 2004CSS490 M++15 M++ Language in Details Thread Definitions and Deployment A thread constructor receives arguments starting from argv[4] A thread immediately starts its own execution in main( ). thread Child { // spawned by a Parent thread public: Child(int argc, const char** argv):id( atoi(argv[5])){ strncpy(msg, argv[4], 16 ); } void main() { cout << msg << id << endl; } private: char msg[16]; int id; }; thread Parent { // injected first public: void main( ); private: int i; char idstr[10]; }; void Parent::main( ) { for (i=0; i<10; i<++ ) { // spawn 10 Child threads sprintf(idstr, “%d”, i); create thread (“I am Thread No”, idstr); }

16 Winter, 2004CSS490 M++16 M++ Language in Details Network Components ComponentsDescriptionsDefinitions/usage Daemon class provides the current daemon status. It is system-predefined and read-only class. daemon.name( ) returns the IP name. daemon.id( ) returns the daemon id. daemon.total( ) returns #daemons DaemonObj class is defined by a user and shared by all threads on the same daemon. Read/write class DaemonObj { … }; thread T { … } // all thread Ts share daemonObj NodesIncludes an object of user- defined class. Each node can include an object of a different class. class Place { … }; Thread T { Void main( ) { create node ( ) with(nid@ did); } LinksAre visible from their endpoint nodes. They include an object of user-defined class. Each linke can include an object of a different class. class Path { … }; Thread T { void main( ) { create link ( ) with slid to (nid@ did) with(dlid); }

17 Winter, 2004CSS490 M++17 M++ Language in Details Logical Network Construction Node creation and destruction [e]create node (argsList) with (NodeId[@DaemonId]); [e]destroy node(NodeId[@DaemonId]); Link creation and destruction [e]create link (argsList) with (SrcLinkId) to (NodeId[@DaemonId] with (DestLinkId) [e]destory link(srcLinkId); Only available in thread main( ) class Place { }; class Path { }; thread Net { public: void main( ) { create node ( ) with( 1@1 ); create link ( ) with(10)to(1@1) with(20); } Daemon Init Daemon 0 1 0 Place 1 10 20 Path

18 Winter, 2004CSS490 M++18 M++ Language in Details Network Navigation [e]hop( [NodeId@DaemonId] ); [e]hopalong( srcLinkId ); [e]fork([ NodeId@DaemonId] ); [e]forkalong( srcLinkId ); class Place { }; class Path { }; thread Net { public: void main( ) { create node ( ) with( 1@1 ); create link ( ) with(10)to(1@1) with(20); hop( 1@1 ); hopalong( 20 ); forkalong( 10 ); cout << “hi!” << endl; } Daemon Init Daemon 0 1 0 Place 1 10 20 Path hi!

19 Winter, 2004CSS490 M++19 M++ Language in Details Inter-Thread Communication Indirect communication: threads can read and write the same variable on the same node. Thread 1 hop( node3@daemon1 ); node.var = 10; Thread 2 hop( node3@daemon1 ); myVar = node.var; Direct communication: A thread can access another thread directly. Thread 1 reads Thread2 myVar = Thread[2].myVar; Thread 2 writes Thread1 Thread[1].myVar = myVar; Daemon Place var write read Thread 1 Thread 2 myVar Indirect Direct

20 Winter, 2004CSS490 M++20 M++ Language in Details Thread Synchronization Nodes are monitors Unless a thread executes a network construction or a migration statement, it can continuously and exclusively run on the current node. Synchronization statements sleep: suspends until “ wakeup threadId ” or “ wakeupall ”. sleep node: suspends until “ wakeup[all] node ”. sleep daemon: suspends until “ wakeup[all] daemon ”. wakeup threadId: resumes the thread with threadId. wakeup node: resumes one thread sleeping on node. wakeup daemon: resumes one thread sleeping on daemon. wakeupall node: resumes all threads sleeping on node. wakeupall daemon: resumes all threads sleeping on daemon.

21 Winter, 2004CSS490 M++21 Transfer Src Daemon Src Daemon UsrClass thrvar; thread Thread { main() { : hop(); : } }; 200 UsrClass thrvar; 200 Execution Thread Pointer Virtual function table Pointer Virtual function table Dst Daemon Dst Daemon 200 Resume Thread New pointer Old pointer Copy constructor UsrClass thrvar; thread Thread { main() { : hop(); : } }; UsrClass thrvar; 200 Implementation State Capturing

22 Winter, 2004CSS490 M++22 AC CMain 1ABCMain12ABCMain ABCMainABC Pthread Library Sthread Library User level Kernel level 1: 2: Implementation Thread Scheduling

23 Winter, 2004CSS490 M++23 RAM Thread 1 RAM Network Interface Kernel Area User Area Sender Receiver Thread 2 Thread 3 Thread 1 Thread 2 Thread 3 (1) (3) (2) gather scatter Packed ThreadsPacked Thread Thread 2 Thread 3 Zero-copy transfer Pin-downed pages Immediate resumption Implementation Zero-copy communication

24 Winter, 2004CSS490 M++24 Exercises (No turn-in) 1. Consider the pros and cons of MPI and M++ when used to design a multi-agent application. 2. Why and when is thread migration necessary? 3. What is zero-copy communication? Why is it so effective?

25 Winter, 2004CSS490 M++25 Final Project Find a parallel application and program in both MPI and M++. Compare their programmability and performance. You may have a partner. One codes an MPI version, the other M++ version. Exclude the following applications (already programmed): Antfarm Artificial societies Growing neural network Matrix multiplication Mandelblot


Download ppt "Winter, 2004CSS490 M++1 Textbook No Corresponding Chapter Instructor: Munehiro Fukuda These slides were thoroughly the instructor’s original materials."

Similar presentations


Ads by Google