controller_main.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 nodes (that is, dpnodes)
  10. static unsigned short total_nodes = 1;
  11. // The amount of memory we can use per dpnode
  12. static unsigned short GB_mem_per_node = 1;
  13. // Input: order
  14. // Output: desired_dpnodes, max_workers, dpfreq
  15. void custom_desired_resources(const ZZ &order,
  16. unsigned short &desired_dpnodes, unsigned int &max_workers,
  17. unsigned int &dpfreq)
  18. {
  19. unsigned short custom_total_nodes = total_nodes;
  20. #ifdef MAKE_VERSIONS_COMPARABLE
  21. custom_total_nodes = 1;
  22. // override the total number of nodes so that only
  23. // one dpnode is used for each subproblem and the
  24. // results are comparable to the dlrho version
  25. #endif
  26. return desired_resources(order, custom_total_nodes,
  27. GB_mem_per_node, desired_dpnodes,
  28. max_workers, dpfreq);
  29. }
  30. static void boundcb(const char *boundaddr, unsigned short boundport)
  31. {
  32. cout << "Listening on " << boundaddr << ":" << boundport << "\n";
  33. const char *fdenv = getenv("CONTROLLER_BOUNDCB_FD");
  34. if (fdenv) {
  35. int fd = atoi(fdenv);
  36. if (fd > 2) {
  37. write(fd, &boundport, 2);
  38. write(fd, boundaddr, strlen(boundaddr));
  39. close(fd);
  40. }
  41. }
  42. }
  43. int main(int argc, char **argv)
  44. {
  45. #ifdef SAVE_DPS
  46. std::cerr << "Note: Saving the distinguished points. Do not run huge problems or else it will use up all of your disk space.\n";
  47. #ifndef DERANDOMIZE
  48. std::cerr << "Saving DPs without derandomization!\n";
  49. #endif
  50. #endif
  51. unsigned short bindport = 0;
  52. Worklist worklist;
  53. if (controller_parse_args(argc, argv, bindport, worklist,
  54. total_nodes, GB_mem_per_node)) {
  55. std::cerr << "Usage: " << argv[0] << " [-p listenport] [-n num_nodes] [-m GB_mem_per_node] [-r reps] N1 iter1 N2 iter2 ...\n";
  56. return 1;
  57. }
  58. return controller_main(worklist, bindport, boundcb);
  59. }