310 likes | 323 Views
This paper discusses the design and implementation of a parallel debugger for MASS, a multi-agent spatial simulation. The debugger provides visualization and debugging capabilities for programs written in MASS, allowing users to run, pause, and resume simulations and visualize both macroscopic and microscopic aspects of the program.
E N D
A Parallel Debugger of Mutli-Agent Spatial Simulation (MASS) Hongbin Li 12/03/2014 Faculty Advisor: Dr. Fukuda A parallel debugger of MASS
Table of Content Table of Content • Introduction • Design & Implementation • Result • Metrics • Conclusion • References A parallel debugger of MASS
Introduction Why debugger for MASS? A parallel debugger of MASS
Introduction Why debugger for MASS? - cont • Graphic visualization is a good idea to explain complex parallel program • Tools such as MASON, Repast are developed to debug parallel programs • however they are totally independent with MASS. • MASS programmers need to develop a separate program base on MASON and Repast for just simulation purpose • So a debugger tool that tightly-coupled with MASS library is necessary A parallel debugger of MASS
Introduction What is MASS • Multi-Agent Spatial Simulation • Agent and place based parallel library • Run in a cluster of multi-core computing nodes • Different from MPI, MASS highly abstract the data structure, simplify the data partition • Can be applied to many place agent based programs A parallel debugger of MASS
Introduction What is MASS - cont • public object[] callAll( int function_id, object[] arguments ) • Calls the method specified with functionId of all array elements as passing arguments[i] to element[i]’s method, and receives a return value from it into Object[i]. Slave: callAll(); callAll Message Master: callAll(); Return value Slave: callAll(); callAll Message Return value callAll Message Return value Slave: callAll(); A parallel debugger of MASS
Table of Content Table of Content • Introduction • Design & Implementation • Result • Metrics • Conclusion • References A parallel debugger of MASS
Design & Implementation A Debugger of MASS • The debugger is specific for parallel programs written in MASS, help to visualize and debug these programs • Features • Parallel and Distributed • Macroscopic and Microscopic visualization • Play, pause, resume, after each iteration • Simulation and Visualization in GUI A parallel debugger of MASS
Design & Implementation Architecture A parallel debugger of MASS
Design & Implementation Design & Implementation • Front - GUI • Run in any PC • Java Swing and 2D/3D graphics • Data transmission state machine • Back-end • Run inside MASS library • Debugger_base is a place, responsible for collecting data from user program and interact with GUI • Debugger • Technologies • Java, C++, OOP • Java Swing and 2D/3D graphics • Networking programming, network protocol design • Multi-Threading and synchronization constructs A parallel debugger of MASS
Design & Implementation Code: GUI – Init DataConnection publicclass DebuggerGUI implements DataEventListener{ publicstaticvoid main(String[] args) { DebuggerGUI debuggerGui = new DebuggerGUI(); debuggerGui.initDataConnection } } 1 Create DataConnection object bt_connect.addActionListener(new ActionListener() { @Override publicvoid actionPerformed(ActionEvent e) { TCPClientConnection tcpConnection = new TCPClientConnection(); tcpConnection.execute(); }); User click “Connect” button 2 privateclass TCPClientConnection extends SwingWorker<Boolean, Void>{ @Override protected Boolean doInBackground(){ int counter = 50; while(counter>=0){ try{ socket = new Socket(serverAddress, PORT); } catch (Exception e){} if(socket != null){ returntrue; } counter--; } returnfalse; } @Override protectedvoid done(){ boolean result = get(); if(result){ DataConnection.start(); } } 3 Use a background thread to connect server and Start DataConnection thread A parallel debugger of MASS
Design & Implementation Code: GUI – OnReceiveData publicclass DataConnection extends Thread{ private Socket socket; private ObjectInputStream input; private ObjectOutputStream output; public DataConnection(DebuggerGUI debuggerGUI){ } @Override publicvoid run(){ while(true){ switch(guiCommand){ case Constants.GUI_CMD_IDLE: //receive data from backend break; case Constants.GUI_CMD_RECV_DATA: receiveDataFromMASS(); break; case Constants.GUI_CMD_PAUSE: pauseComputation(); break; case Constants.GUI_CMD_RESUME: resumeComputation(); break; case Constants.GUI_CMD_INJECT_PLACE: injectPlaceData(); break; default: break; } } } } publicclass DebuggerGUI implements DataEventListener{ @Override publicvoid onReceiveData(Object[] objects) { // function of DataEventListenerinterface // get called when Dataconnection receiveDataFromMASS } @Override publicvoid initApplicationSpec(String name, int size) { // function of DataEventListenerinterface // get called when Dataconnection receiveDataFromMASS } } SwingUtilities.invokeLater(new Runnable(){ @Override publicvoid run(){ listener.onReceiveData(DebuggerGUI.places); } }); When DataConnection thread received data from back end, it will dispatch a message to GUI thread A parallel debugger of MASS
Design & Implementation Code: GUI – send user command bt_pause.addActionListener(new ActionListener() { @Override publicvoid actionPerformed(ActionEvent e) { dataConnection.setPauseCommand(Constants.GUI_CMD_PAUSE); }); publicclass DataConnection extends Thread{ private Socket socket; private ObjectInputStream input; private ObjectOutputStream output; public DataConnection(DebuggerGUI debuggerGUI){ } @Override publicvoid run(){ while(true){ switch(guiCommand){ case Constants.GUI_CMD_IDLE: //receive data from backend break; case Constants.GUI_CMD_RECV_DATA: receiveDataFromMASS(); break; case Constants.GUI_CMD_PAUSE: pauseComputation(); break; case Constants.GUI_CMD_RESUME: resumeComputation(); break; case Constants.GUI_CMD_INJECT_PLACE: injectPlaceData(); break; default: break; } } } } 1 publicvoid setPauseCommand(int cmd){ synchronized(this){ guiCommand = cmd; } } 2 User click button-> update guiCommand variable in DataConnection->the next iteration will match new command A parallel debugger of MASS
Design & Implementation Code: Backend – Debugger_base package MASS; publicclass Debugger_base extends Place { protected Object fetchDebugData(Object argument) { // fetch debug data return (Object)placeDebugData; } protected Object InjectDebugData(Object argument) { //inject debug data returnnull; } protectedstaticvoid updateDataConnectionThread(int status){ // update state machine } privatevoid startTCPSocketServer() { new Thread() { }.start(); } privateclass SocketGUIConnection extends Thread { public SocketGUIConnection(ObjectOutputStream output, ObjectInputStream input) { } @Override publicvoid run() { while (true) { synchronized(debuggerInstance){ } } } } } Debugger_base class that extends Place Class. Two methods defined for callAll: fetchDebugData and InjectDebugData A private class SocketGUIConnection extends Thread is responsible for communication with GUI A parallel debugger of MASS
Design & Implementation Code: Backend – Agent/Place • Change in MASS library, add two methods to Agent and Place public Object getDebugData() { return null; } publicvoid setDebugData(Object argument) { } A parallel debugger of MASS
Design & Implementation Code: Backend – Data transfer @Override publicvoid run() { String cmd = ""; while (true) { synchronized(debuggerInstance){ probeGUICmd(); switch (dataConnectionThreadstatus){ case STATUS_SEND_PLACE_DATA: //dataConnectionThreadstatus = STATUS_READY; synchronized(sending_lock){ try{ output.writeObject("cmdPlaceData"); } catch (IOException ioe){ if(!isPlaceAgentMode){ sending_lock[0] = false; sending_lock.notifyAll(); } } synchronized(sending_place_lock){ sending_place_lock[0] = false; sending_place_lock.notify(); } break; case STATUS_SEND_AGENT_DATA: //dataConnectionThreadstatus = STATUS_READY; synchronized(sending_lock){ try{ output.writeObject("cmdAgentData"); } catch (IOException ioe){ sending_lock[0] = false; sending_lock.notifyAll(); } default: break; } } } for ( inttime = 0; time < maxTime; time++ ) { Debugger.sync(); //……user application…… Object[] debugParam = new Integer[nProcesses]; debugger.callAll(Debugger.fetchDebugData_, debugParam); Debugger.sendDataToGUI(SEND_PLACE_DATA); Debugger.sendDataToGUI(SEND_AGENT_DATA);// debugger.callAll(Debugger.fetchAgentDebugData_, debugParam); } 1 publicstaticvoidsync(){ synchronized(Debugger_base.sending_lock){ if(Debugger_base.sending_lock[0]){ try{ Debugger_base.sending_lock.wait(); }catch(Exception e){} } } synchronized(Debugger_base.stop_lock){ if(Debugger_base.stop_lock[0]){ try{ Debugger_base.stop_lock.wait(); }catch(Exception e){} } } } 3 2 protectedstaticvoid updateDataConnectionThread(int status){ synchronized(debuggerInstance){ dataConnectionThreadstatus = status; } } A parallel debugger of MASS
Table of Content Table of Content • Introduction • Design & Implementation • Result • Metrics • Conclusion • References A parallel debugger of MASS
Result Simulate Wave2D A parallel debugger of MASS
Result Simulate RandomWalk A parallel debugger of MASS
Table of Content Table of Content • Introduction • Design & Implementation • Result • Metrics • Conclusion • References A parallel debugger of MASS
Metrics Metrics • Performance • Scalability • Usability • Burden A parallel debugger of MASS
Metrics Metrics - Performance • Time: • Wait and send • Space • depends on the application 2 dimension place array, each place has a double value A parallel debugger of MASS
Metrics Metrics - Scalability • Scalability means how scalable the debugger to support various applications • It is a long term metrics, various applications of MASS can be simulated by MASS debugger A parallel debugger of MASS
Metrics Metrics - Usability A parallel debugger of MASS
Metrics Metrics - Burden Step 1: Create Places for debugger Places debugger = new Places(Debugger_HANDLER_ID, "Debugger", (Object)(handler),nProcesses); debugger.callAll(Debugger.init_); for ( int time = 0; time < maxTime; time++ ) { Step 2: sync with debugger data transmission thread before next iteration Debugger.sync(); // user’s code Step 3: call debugger callAll to send place and agent data debugger.callAll(Debugger.fetchDebugData_, debugParam); Debugger.sendDataToGUI(Debugger_SEND_PLACE_DATA); Debugger.sendDataToGUI(Debugger_SEND_AGENT_DATA); debugger.callAll(Debugger.fetchAgentDebugData_, debugParam); } A parallel debugger of MASS
Metrics Metrics – Burden cont A parallel debugger of MASS for ( int time = 0; time < maxTime; time++ ) { Debugger.sync(); // user’s code debugger.callAll(Debugger.fetchDebugData_, debugParam); Debugger.sendDataToGUI(Debugger_SEND_PLACE_DATA); Debugger.sendDataToGUI(Debugger_SEND_AGENT_DATA); debugger.callAll(Debugger.fetchAgentDebugData_, debugParam); }
Table of Content Table of Content • Introduction • Design & Implementation • Result • Metrics • Conclusion • References A parallel debugger of MASS
Conclusion Conclusion • Done • Visualize overall MASS applications’ behavior • Inspect/modify place/agent memory • Pause/Resume • Limitations • If number of places are huge, its hard to displace the graphic in just one window, and it is very hard to user to pinpoint one spot • User applications need to embed debugger code into their applications • Future work • Magnify Glass feature • Embed MASS debugger into MASS library • Develop C++ version Debugger • 3D graphic support A parallel debugger of MASS
Table of Content Table of Content • Introduction • Design & Implementation • Result • Metrics • Conclusion • References A parallel debugger of MASS
References References Sean Luke, department of Computer Science at George Mason University. MASON Sallach, Collier, Howe, North. Repast http://repast.sourceforge.net/repast_3/ Steven S. Lumetta and David E, Culler. The Mantis Parallel Debugger Blaise Barney, Lawrence Livermore National Laboratory, TotalViewhttps://computing.llnl.gov/tutorials/totalview/ Nick Collier, Repast HPC Manual, August 13, 2013 Cherri M. Pancake, Sue Utter, Advances in Parallel Debuggers: New Approaches to Visualization, December 29, 1989 Eileen Kraemer and John T. Stasko, The visualization of parallel systems: an overview, July 1992, College of Computing, Georgia Institute of Technology Hal-00697093 published in 7th International Joint Conference on Computer Vision, Imaging and Computer Graphics Theory and Applications, Rome: Italy (2012) A parallel debugger of MASS
Q&A Thank You ! A parallel debugger of MASS