controller_main.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. return desired_resources(order, total_nodes,
  20. GB_mem_per_node, desired_dpnodes,
  21. max_workers, dpfreq);
  22. }
  23. static void boundcb(const char *boundaddr, unsigned short boundport)
  24. {
  25. cout << "Listening on " << boundaddr << ":" << boundport << "\n";
  26. const char *fdenv = getenv("CONTROLLER_BOUNDCB_FD");
  27. if (fdenv) {
  28. int fd = atoi(fdenv);
  29. if (fd > 2) {
  30. write(fd, &boundport, 2);
  31. write(fd, boundaddr, strlen(boundaddr));
  32. close(fd);
  33. }
  34. }
  35. }
  36. int main(int argc, char **argv)
  37. {
  38. unsigned short bindport = 0;
  39. Worklist worklist;
  40. if (controller_parse_args(argc, argv, bindport, worklist,
  41. total_nodes, GB_mem_per_node)) {
  42. std::cerr << "Usage: " << argv[0] << " [-p listenport] [-n num_nodes] [-m GB_mem_per_node] [-r reps] N1 iter1 N2 iter2 ...\n";
  43. return 1;
  44. }
  45. return controller_main(worklist, bindport, boundcb);
  46. }