controller_main.cc 1.5 KB

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