controller_main.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <NTL/ZZ.h>
  2. #include <iostream>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "controller.h"
  6. NTL_CLIENT
  7. static unsigned short total_nodes = 0;
  8. static unsigned short GB_mem_per_node = 0;
  9. void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
  10. unsigned int &max_workers, unsigned int &dpfreq)
  11. {
  12. // How many DPnodes should we use for a problem of this size?
  13. desired_dpnodes = 1;
  14. // How many workers would we like to use?
  15. ZZ sorder = SqrRoot(order >> 46);
  16. if (NumBits(sorder) > 30) {
  17. // Just use all the workers we can find
  18. max_workers = 4294967295U; // 2^32 - 1
  19. } else {
  20. max_workers = trunc_long(sorder,31) + 1;
  21. }
  22. // By default, 1 in 1000 points are distinguihed points. The
  23. // number in the next line is 2^32/1000
  24. dpfreq = 4294967;
  25. if (order < 1000) {
  26. // Just make every point a DP
  27. dpfreq = 4294967295U;
  28. } else if (NumBits(order) < 27) {
  29. // The frequency of DPs should be 10/sqrt(order) to avoid
  30. // a DP-free cycle, so dpfreq = (10*2^32)/sqrt(order)
  31. ZZ f = (to_ZZ(10) << 32) / SqrRoot(order);
  32. dpfreq = trunc_long(f, 31);
  33. }
  34. }
  35. static void boundcb(const char *boundaddr, unsigned short boundport)
  36. {
  37. cout << "Listening on " << boundaddr << ":" << boundport << "\n";
  38. const char *fdenv = getenv("CONTROLLER_BOUNDCB_FD");
  39. if (fdenv) {
  40. int fd = atoi(fdenv);
  41. if (fd > 2) {
  42. write(fd, &boundport, 2);
  43. write(fd, boundaddr, strlen(boundaddr));
  44. close(fd);
  45. }
  46. }
  47. }
  48. int main(int argc, char **argv)
  49. {
  50. unsigned short bindport = 0;
  51. Worklist worklist;
  52. if (controller_parse_args(argc, argv, bindport, worklist,
  53. total_nodes, GB_mem_per_node)) {
  54. std::cerr << "Usage: " << argv[0] << " [-p listenport] [-n num_nodes] [-m GB_mem_per_node] [-r reps] N1 iter1 N2 iter2 ...\n";
  55. return 1;
  56. }
  57. return controller_main(worklist, bindport, boundcb);
  58. }