debugger.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright AlainMiniussi 20014 - 20015.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <cstdlib>
  6. #include "debugger.hpp"
  7. std::vector<int> extract_paused_ranks(int argc, char** argv) {
  8. std::vector<int> paused;
  9. for (int i=1; i < argc; ++i) {
  10. paused.push_back(std::atoi(argv[i]));
  11. }
  12. return paused;
  13. }
  14. void wait_for_debugger(std::vector<int> const& processes, boost::mpi::communicator const& comm)
  15. {
  16. int i = 1;
  17. bool waiting = std::find(processes.begin(), processes.end(), comm.rank()) != processes.end();
  18. for (int r = 0; r < comm.size(); ++r) {
  19. if (comm.rank() == r) {
  20. std::cout << "Rank " << comm.rank() << " has PID " << getpid();
  21. if (waiting) {
  22. std::cout << " and is waiting.";
  23. }
  24. std::cout << std::endl;
  25. }
  26. comm.barrier();
  27. }
  28. if (std::find(processes.begin(), processes.end(), comm.rank()) != processes.end()) {
  29. while (i != 0) {
  30. sleep(5);
  31. }
  32. }
  33. std::cout << "Rank " << comm.rank() << " will proceed.\n";
  34. }
  35. void wait_for_debugger(boost::mpi::communicator const& comm)
  36. {
  37. std::vector<int> all;
  38. for (int r = 0; r < comm.size(); ++r) {
  39. all.push_back(r);
  40. }
  41. wait_for_debugger(all, comm);
  42. }