1 / 25

CSS490 M++ Textbook No Corresponding Chapter

CSS490 M++ Textbook No Corresponding Chapter. Instructor: Munehiro Fukuda These slides were thoroughly the instructor’s original materials. Thread Migration overview. Moving: CPU status Stack (Heap). Migrating a thread. Memory access. Memory access.

tan
Download Presentation

CSS490 M++ Textbook No Corresponding Chapter

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Thread MigrationExamples CSS490 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 CSS490 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 CSS490 M++

  6. Object Queue Object Queue Obj 5 Obj 6 Obj 2 Obj 3 Obj 4 Obj 4 Obj 6 Obj 3 Obj 2 Obj 1 Obj 1 Obj 5 null null Exchange 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 Process 2 Process 1 Obj 7 LAN/SAN CSS490 M++

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

  9. M++ Execution Model 1 Logical Network hop(1@2) Node create Node with 3@2 Link Link 3 1 1 Thread Node Node Node Daemon Network 1 2 3 Daemon Daemon Daemon Physical Network LAN/SAN CSS490 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<Node> with 1; // Creating a network node, (link, and thread) hop( 1 ); // Migrating itself (and forking) node<Node>.var = 10; // Accessing the current node, (and link) } }; CSS490 M++

  11. M++ Compilation Includes three pieces of agent code • 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]% Compile it with the m++ compiler Message printed out from m++ Three executable files obtained CSS490 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]% CSS490 M++

  13. M++ Daemon Invocation 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]% • 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. CSS490 M++

  14. M++ Thread Launching 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]% • 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 CSS490 M++

  15. M++ Language in DetailsThread Definitions and Deployment 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<Child>(“I am Thread No”, idstr); } } • A thread constructor receives arguments starting from argv[4] • A thread immediately starts its own execution in main( ). CSS490 M++

  16. M++ Language in DetailsNetwork Components CSS490 M++

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

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

  19. Thread 2 Thread 1 Place write read var Daemon M++ Language in DetailsInter-Thread Communication • Indirect communication: threads can read and write the same variable on the same node. • Thread 1 hop( node3@daemon1 ); node<Place>.var = 10; • Thread 2 hop( node3@daemon1 ); myVar = node<Place>.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; Direct myVar myVar Indirect CSS490 M++

  20. M++ Language in DetailsThread 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. CSS490 M++

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

  22. Main Main A A B B C C 1 2 1 A C A B C A B C Main C Main ImplementationThread Scheduling Sthread Library Pthread Library User level Kernel level 1: 1: 2: CSS490 M++

  23. Thread 2 Thread 3 ImplementationZero-copy communication Receiver Sender User Area User Area Pin-downed pages Thread 1 Thread 1 (2) Thread 2 Thread 2 (3) gather scatter Thread 3 Thread 3 Immediate resumption Packed Threads Packed Thread Kernel Area Kernel Area RAM RAM (1) Zero-copy transfer Network Interface Network Interface CSS490 M++

  24. Exercises (No turn-in) • Consider the pros and cons of MPI and M++ when used to design a multi-agent application. • Why and when is thread migration necessary? • What is zero-copy communication? Why is it so effective? CSS490 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 CSS490 M++

More Related