| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <NTL/ZZ.h>
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- #include "controller.h"
- NTL_CLIENT
- void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
- unsigned int &max_workers, unsigned int &dpfreq)
- {
- // How many DPnodes should we use for a problem of this size?
- desired_dpnodes = 1;
- // How many workers would we like to use?
- ZZ sorder = SqrRoot(order >> 46);
- if (NumBits(sorder) > 30) {
- // Just use all the workers we can find
- max_workers = 4294967295U; // 2^32 - 1
- } else {
- max_workers = trunc_long(sorder,31) + 1;
- }
- // By default, 1 in 1000 points are distinguihed points. The
- // number in the next line is 2^32/1000
- dpfreq = 4294967;
- if (order < 1000) {
- // Just make every point a DP
- dpfreq = 4294967295U;
- } else if (NumBits(order) < 27) {
- // The frequency of DPs should be 10/sqrt(order) to avoid
- // a DP-free cycle, so dpfreq = (10*2^32)/sqrt(order)
- ZZ f = (to_ZZ(10) << 32) / SqrRoot(order);
- dpfreq = trunc_long(f, 31);
- }
- }
- static void boundcb(const char *boundaddr, unsigned short boundport)
- {
- cout << "Listening on " << boundaddr << ":" << boundport << "\n";
- const char *fdenv = getenv("CONTROLLER_BOUNDCB_FD");
- if (fdenv) {
- int fd = atoi(fdenv);
- if (fd > 2) {
- write(fd, &boundport, 2);
- write(fd, boundaddr, strlen(boundaddr));
- close(fd);
- }
- }
- }
- int main(int argc, char **argv)
- {
- unsigned short bindport = 0;
- Worklist worklist;
- if (controller_parse_args(argc, argv, bindport, worklist)) {
- std::cerr << "Usage: " << argv[0] << " [-p listenport] N1 iter1 N2 iter2 ...\n";
- return 1;
- }
- return controller_main(worklist, bindport, boundcb);
- }
|