controller_main.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <NTL/ZZ.h>
  2. #include <iostream>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include "desired_resources.h"
  7. #include "controller.h"
  8. NTL_CLIENT
  9. // The total number of workers
  10. static unsigned short total_workers = 1;
  11. // The total number of nodes (that is, dpnodes)
  12. static unsigned short total_nodes = 1;
  13. // The amount of memory we can use per dpnode
  14. static unsigned short GB_mem_per_node = 1;
  15. // Input: order
  16. // Output: desired_dpnodes, max_workers, dpfreq
  17. void custom_desired_resources(const ZZ &order,
  18. unsigned short &desired_dpnodes, unsigned int &max_workers,
  19. unsigned int &dpfreq)
  20. {
  21. unsigned short custom_total_workers = total_workers;
  22. unsigned short custom_total_nodes = total_nodes;
  23. #ifdef MAKE_VERSIONS_COMPARABLE
  24. custom_total_nodes = 1;
  25. // override the total number of nodes so that only
  26. // one dpnode is used for each subproblem and the
  27. // results are comparable to the dlrho version
  28. #endif
  29. #if defined(SAVE_DPS) || defined(MAKE_VERSIONS_COMPARABLE)
  30. custom_total_workers = 1;
  31. // (1) can't use multiple workers when saving dps since
  32. // we want the order of dps to be deterministic
  33. // (2) the dlrho version uses 1 worker per subproblem
  34. #endif
  35. unsigned short freq_reduction_threshold = 4;
  36. // this should be okay in most cases and shouldn't cause
  37. // any negative effects if it's too low
  38. return desired_resources(order, custom_total_workers,
  39. custom_total_nodes, GB_mem_per_node,
  40. freq_reduction_threshold,
  41. desired_dpnodes, max_workers, dpfreq);
  42. }
  43. static void boundcb(const char *boundaddr, unsigned short boundport)
  44. {
  45. cout << "Listening on " << boundaddr << ":" << boundport << "\n";
  46. const char *fdenv = getenv("CONTROLLER_BOUNDCB_FD");
  47. if (fdenv) {
  48. int fd = atoi(fdenv);
  49. if (fd > 2) {
  50. write(fd, &boundport, 2);
  51. write(fd, boundaddr, strlen(boundaddr));
  52. close(fd);
  53. }
  54. }
  55. }
  56. int main(int argc, char **argv)
  57. {
  58. #ifdef SAVE_DPS
  59. std::cerr << "Note: Saving the distinguished points. Do not run huge problems or else it will use up all of your disk space.\n";
  60. #ifndef DERANDOMIZE
  61. std::cerr << "Saving DPs without derandomization!\n";
  62. #endif
  63. #endif
  64. unsigned short bindport = 0;
  65. Worklist worklist;
  66. if (controller_parse_args(argc, argv, bindport, worklist, total_workers,
  67. total_nodes, GB_mem_per_node)) {
  68. std::cerr << "Usage: " << argv[0] << " [-p listenport] [-w num_workers] [-n num_dpnodes] [-m GB_mem_per_node] [-r reps] N1 iter1 N2 iter2 ...\n";
  69. return 1;
  70. }
  71. return controller_main(worklist, bindport, boundcb);
  72. }