Skip to content

Commit

Permalink
Adapt the debugger to use the improved MPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupert Nash authored and Rupert Nash committed Oct 10, 2013
1 parent 563b050 commit 829e6fa
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 91 deletions.
9 changes: 4 additions & 5 deletions Code/debug/Debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace hemelb
namespace debug
{

Debugger* Debugger::Init(const char * const executable)
Debugger* Debugger::Init(const char * const executable, const net::MpiCommunicator& comm)
{
/* Static member function that implements the singleton pattern.
* Use the namespace function PlatformDebuggerFactory to
Expand All @@ -24,7 +24,7 @@ namespace hemelb
*/
if (Debugger::singleton == NULL)
{
Debugger::singleton = PlatformDebuggerFactory(executable);
Debugger::singleton = PlatformDebuggerFactory(executable, comm);
}
Debugger::singleton->Attach();
return Debugger::singleton;
Expand All @@ -39,10 +39,9 @@ namespace hemelb
// Init static members
Debugger* Debugger::singleton = NULL;

Debugger::Debugger(const char* const executable)
Debugger::Debugger(const char* const executable, const net::MpiCommunicator& comm) :
mExecutable(executable), mCommunicator(comm)
{
// Ctor
mExecutable = std::string(executable);
}

// Dtor
Expand Down
9 changes: 5 additions & 4 deletions Code/debug/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define HEMELB_DEBUG_DEBUGGER_H

#include <string>
#include "net/MpiCommunicator.h"

namespace hemelb
{
Expand All @@ -24,26 +25,26 @@ namespace hemelb
*/
public:
// the singleton pattern
static Debugger* Init(const char *const);
static Debugger* Init(const char *const, const net::MpiCommunicator& comm);
static Debugger* Get(void);

virtual void BreakHere(void) = 0;
virtual void Print(const char* iFormat, ...) = 0;

protected:
Debugger(const char* const executable);
Debugger(const char* const executable, const net::MpiCommunicator& comm);
virtual ~Debugger();

virtual void Attach() = 0;

std::string mExecutable;

const net::MpiCommunicator mCommunicator;
// Singleton pattern
static Debugger* singleton;

};

Debugger* PlatformDebuggerFactory(const char* const executable);
Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);

}
}
Expand Down
35 changes: 21 additions & 14 deletions Code/debug/OSX/OsxDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,36 @@ namespace hemelb
{
namespace debug
{
OsxDebugger::OsxDebugger(const char* const executable) : ActiveDebugger(executable) {}

const std::string OsxDebugger::GetPlatformInterpreter(void) const {
OsxDebugger::OsxDebugger(const char* const executable, const net::MpiCommunicator& comm) :
ActiveDebugger(executable, comm)
{
}

const std::string OsxDebugger::GetPlatformInterpreter(void) const
{
return std::string("osascript");
}

const std::string OsxDebugger::GetPlatformScript(void) const {
std::string include (__FILE__);

const std::string OsxDebugger::GetPlatformScript(void) const
{
std::string include(__FILE__);
std::string debugOsxDir = include.substr(0, include.rfind('/'));

return debugOsxDir + "/MPIdebug.scpt";
}

const std::string OsxDebugger::GetPlatformGdbScript(void) const {
std::string include (__FILE__);

const std::string OsxDebugger::GetPlatformGdbScript(void) const
{
std::string include(__FILE__);
std::string debugOsxDir = include.substr(0, include.rfind('/'));

return debugOsxDir + "/resume.gdb";
}

Debugger* PlatformDebuggerFactory(const char * const executable) {
return new OsxDebugger(executable);
Debugger* PlatformDebuggerFactory(const char * const executable, const net::MpiCommunicator& comm)
{
return new OsxDebugger(executable, comm);
}

} // namespace debug
} // namespace hemelb
6 changes: 3 additions & 3 deletions Code/debug/OSX/OsxDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace hemelb
const std::string GetPlatformGdbScript(void) const;

// C'tor...
OsxDebugger(const char* const executable);
OsxDebugger(const char* const executable, const net::MpiCommunicator& comm);
// ... which the factory function needs to be able to get at.
friend Debugger* PlatformDebuggerFactory(const char* const executable);
friend Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);

};

// Factory. Don't be calling this.
Debugger* PlatformDebuggerFactory(const char* const executable);
Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);
}
}

Expand Down
64 changes: 23 additions & 41 deletions Code/debug/common/ActiveDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace hemelb
namespace debug
{

ActiveDebugger::ActiveDebugger(const char* const executable) :
Debugger(executable), mAmAttached(false), mPIds(NULL)
ActiveDebugger::ActiveDebugger(const char* const executable, const net::MpiCommunicator& comm) :
Debugger(executable, comm), mAmAttached(false), mPIds(NULL)
{
}

Expand Down Expand Up @@ -67,27 +67,15 @@ namespace hemelb
return;

volatile int amWaiting = 1;
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int nProcs;
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
mPIds = new VoI(nProcs);
int pId = getpid();
pid_t childPid = 0;

MPI_Gather((void*) &pId,
1,
net::MpiDataType(pId),
(void*) & (mPIds->front()),
1,
net::MpiDataType(mPIds->front()),
0,
MPI_COMM_WORLD);

if (rank == 0)

int childPid = -1;
// To rank 0
GatherProcessIds();

if (mCommunicator.Rank() == 0)
{
childPid = fork();

// Fork gives the PID of the child to the parent and zero to the child
if (childPid == 0)
{
// This function won't return.
Expand All @@ -99,7 +87,7 @@ namespace hemelb
while (amWaiting)
sleep(5);

if (rank == 0)
if (mCommunicator.Rank() == 0)
{
// Reap the spawner
int deadPid = waitpid(childPid, NULL, 0);
Expand All @@ -110,28 +98,22 @@ namespace hemelb

void ActiveDebugger::GatherProcessIds()
{
if (mAmAttached)
{
// Return a vector of the process ids
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int nProcs;
MPI_Comm_size(MPI_COMM_WORLD, &nProcs);

mPIds = new VoI(nProcs);
int rank = mCommunicator.Rank();
int nProcs = mCommunicator.Size();

int pId = getpid();
mPIds = new VoI(nProcs);

MPI_Gather((void*) &pId,
1,
net::MpiDataType(pId),
(void*) & (mPIds->front()),
1,
net::MpiDataType(mPIds->front()),
0,
MPI_COMM_WORLD);
int pId = getpid();

}
HEMELB_MPI_CALL(MPI_Gather,
((void*) &pId,
1,
net::MpiDataType(pId),
(void*) & (mPIds->front()),
1,
net::MpiDataType(mPIds->front()),
0,
mCommunicator));
}

void ActiveDebugger::SpawnDebuggers(void)
Expand Down
2 changes: 1 addition & 1 deletion Code/debug/common/ActiveDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace hemelb
typedef std::vector<std::string> VoS;// Vector of Strings

// C'tor
ActiveDebugger(const char* const executable);
ActiveDebugger(const char* const executable, const net::MpiCommunicator& comm);

bool mAmAttached;// Indicate attachment state
VoI* mPIds;// vector of process IDs
Expand Down
22 changes: 11 additions & 11 deletions Code/debug/linux/LinuxDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@ namespace hemelb
{
namespace debug
{
LinuxDebugger::LinuxDebugger(const char* const executable) :
ActiveDebugger(executable) {}
LinuxDebugger::LinuxDebugger(const char* const executable, const net::MpiCommunicator& comm) :
ActiveDebugger(executable, comm) {}

const std::string LinuxDebugger::GetPlatformInterpreter(void) const {
return std::string("bash");
}

const std::string LinuxDebugger::GetPlatformScript(void) const {
std::string include (__FILE__);
std::string debugLinuxDir = include.substr(0, include.rfind('/'));

return debugLinuxDir + "/launchGdbs.sh";
}

const std::string LinuxDebugger::GetPlatformGdbScript(void) const {
std::string include (__FILE__);
std::string debugLinuxDir = include.substr(0, include.rfind('/'));

return debugLinuxDir + "/resume.gdb";
}
Debugger* PlatformDebuggerFactory(const char * const executable) {
return new LinuxDebugger(executable);

Debugger* PlatformDebuggerFactory(const char * const executable, const net::MpiCommunicator& comm) {
return new LinuxDebugger(executable, comm);
}

} // namespace debug
} // namespace hemelb
6 changes: 3 additions & 3 deletions Code/debug/linux/LinuxDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace hemelb
const std::string GetPlatformGdbScript(void) const;

// C'tor...
LinuxDebugger(const char* const executable);
LinuxDebugger(const char* const executable, const net::MpiCommunicator& comm);
// ... which the factory function needs to be able to get at.
friend Debugger* PlatformDebuggerFactory(const char* const executable);
friend Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);

};

// Factory. Don't be calling this.
Debugger* PlatformDebuggerFactory(const char* const executable);
Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Code/debug/none/NullDebugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace hemelb
{
}

NullDebugger::NullDebugger(const char* const executable) :
Debugger(executable)
NullDebugger::NullDebugger(const char* const executable, const net::MpiCommunicator& comm) :
Debugger(executable, comm)
{
}

Debugger* PlatformDebuggerFactory(const char * const executable)
Debugger* PlatformDebuggerFactory(const char * const executable, const net::MpiCommunicator& comm)
{
return new NullDebugger(executable);
return new NullDebugger(executable, comm);
}
}
}
6 changes: 3 additions & 3 deletions Code/debug/none/NullDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace hemelb

protected:
void Attach(void);
NullDebugger(const char* const executable);
friend Debugger* PlatformDebuggerFactory(const char* const executable);
NullDebugger(const char* const executable, const net::MpiCommunicator& comm);
friend Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);
};

Debugger* PlatformDebuggerFactory(const char* const executable);
Debugger* PlatformDebuggerFactory(const char* const executable, const net::MpiCommunicator& comm);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Code/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ int main(int argc, char *argv[])
hemelb::log::Logger::Init();
try
{
hemelb::net::MpiCommunicator hemelbCommunicator = hemelb::net::MpiCommunicator::World();
// Start the debugger (no-op if HEMELB_USE_DEBUGGER is OFF)
hemelb::debug::Debugger::Init(argv[0]);
hemelb::debug::Debugger::Init(argv[0], hemelbCommunicator);

hemelb::net::MpiCommunicator hemelbCommunicator = hemelb::net::MpiCommunicator::World();
hemelb::net::NetworkTopology::Instance()->Init(hemelbCommunicator);
try
{
Expand Down
2 changes: 2 additions & 0 deletions Code/unittests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ int main(int argc, char **argv)
hemelb::log::Logger::Init();

hemelb::net::MpiCommunicator testCommunicator = hemelb::net::MpiCommunicator::World();
hemelb::debug::Debugger::Init(argv[0], testCommunicator);

hemelb::net::NetworkTopology::Instance()->Init(testCommunicator);

std::ostream * reportto=&std::cerr;
Expand Down

0 comments on commit 829e6fa

Please sign in to comment.