diff --git a/Code/debug/Debugger.cc b/Code/debug/Debugger.cc index 66b250f02..a7925e9ff 100644 --- a/Code/debug/Debugger.cc +++ b/Code/debug/Debugger.cc @@ -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 @@ -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; @@ -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 diff --git a/Code/debug/Debugger.h b/Code/debug/Debugger.h index 1c19ffe02..fe3c50f17 100644 --- a/Code/debug/Debugger.h +++ b/Code/debug/Debugger.h @@ -11,6 +11,7 @@ #define HEMELB_DEBUG_DEBUGGER_H #include +#include "net/MpiCommunicator.h" namespace hemelb { @@ -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); } } diff --git a/Code/debug/OSX/OsxDebugger.cc b/Code/debug/OSX/OsxDebugger.cc index b6fb5eb8f..cf25b6d47 100644 --- a/Code/debug/OSX/OsxDebugger.cc +++ b/Code/debug/OSX/OsxDebugger.cc @@ -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 diff --git a/Code/debug/OSX/OsxDebugger.h b/Code/debug/OSX/OsxDebugger.h index 13878b5a7..e0df27031 100644 --- a/Code/debug/OSX/OsxDebugger.h +++ b/Code/debug/OSX/OsxDebugger.h @@ -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); } } diff --git a/Code/debug/common/ActiveDebugger.cc b/Code/debug/common/ActiveDebugger.cc index 56ec89231..2880fe507 100644 --- a/Code/debug/common/ActiveDebugger.cc +++ b/Code/debug/common/ActiveDebugger.cc @@ -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) { } @@ -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. @@ -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); @@ -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) diff --git a/Code/debug/common/ActiveDebugger.h b/Code/debug/common/ActiveDebugger.h index 4a3aa2a51..b3aa74286 100644 --- a/Code/debug/common/ActiveDebugger.h +++ b/Code/debug/common/ActiveDebugger.h @@ -36,7 +36,7 @@ namespace hemelb typedef std::vector 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 diff --git a/Code/debug/linux/LinuxDebugger.cc b/Code/debug/linux/LinuxDebugger.cc index 46f642ee1..99d9110a6 100644 --- a/Code/debug/linux/LinuxDebugger.cc +++ b/Code/debug/linux/LinuxDebugger.cc @@ -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 diff --git a/Code/debug/linux/LinuxDebugger.h b/Code/debug/linux/LinuxDebugger.h index f31d0e368..c8a011f2c 100644 --- a/Code/debug/linux/LinuxDebugger.h +++ b/Code/debug/linux/LinuxDebugger.h @@ -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); } } diff --git a/Code/debug/none/NullDebugger.cc b/Code/debug/none/NullDebugger.cc index 17ef11f55..b7e894880 100644 --- a/Code/debug/none/NullDebugger.cc +++ b/Code/debug/none/NullDebugger.cc @@ -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); } } } diff --git a/Code/debug/none/NullDebugger.h b/Code/debug/none/NullDebugger.h index b03f697d1..691db31b2 100644 --- a/Code/debug/none/NullDebugger.h +++ b/Code/debug/none/NullDebugger.h @@ -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); } } diff --git a/Code/main.cc b/Code/main.cc index 9907768aa..369da220f 100644 --- a/Code/main.cc +++ b/Code/main.cc @@ -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 { diff --git a/Code/unittests/main.cc b/Code/unittests/main.cc index fdb9c8b93..082f1aaf1 100644 --- a/Code/unittests/main.cc +++ b/Code/unittests/main.cc @@ -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;