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