controller_main.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. int main(int argc, char **argv)
  34. {
  35. unsigned short bindport = 0;
  36. if (argc > 2 && !strncmp(argv[1], "-p", 2)) {
  37. // A port number was specified
  38. bindport = strtoul(argv[2], NULL, 10);
  39. argc -= 2;
  40. argv += 2;
  41. }
  42. if (argc < 3 || (argc % 2 == 0)) {
  43. std::cerr << "Usage: " << argv[0] << " [-p listenport] N1 iter1 N2 iter2 ...\n";
  44. return 1;
  45. }
  46. Worklist worklist;
  47. for (int i=1;i<argc;i+=2) {
  48. worklist.push_back(Workentry(argv[i], strtoul(argv[i+1], NULL, 10)));
  49. }
  50. return controller_main(worklist, bindport);
  51. }