|
@@ -4,6 +4,8 @@
|
|
|
#include <NTL/ZZ.h>
|
|
#include <NTL/ZZ.h>
|
|
|
|
|
|
|
|
#include "controller.h"
|
|
#include "controller.h"
|
|
|
|
|
+#include "worker.h"
|
|
|
|
|
+#include "dpnode.h"
|
|
|
|
|
|
|
|
NTL_CLIENT
|
|
NTL_CLIENT
|
|
|
|
|
|
|
@@ -16,6 +18,7 @@ static void boundcb(const char *boundaddr, unsigned short boundport)
|
|
|
// Write the port and addr to the pipe
|
|
// Write the port and addr to the pipe
|
|
|
write(controllerfds[1], &boundport, 2);
|
|
write(controllerfds[1], &boundport, 2);
|
|
|
write(controllerfds[1], boundaddr, strlen(boundaddr));
|
|
write(controllerfds[1], boundaddr, strlen(boundaddr));
|
|
|
|
|
+ close(controllerfds[1]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
|
|
void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
|
|
@@ -56,6 +59,8 @@ int main(int argc, char **argv)
|
|
|
|
|
|
|
|
int rank;
|
|
int rank;
|
|
|
|
|
|
|
|
|
|
+ int ret = 0;
|
|
|
|
|
+
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
|
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
|
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
|
|
|
|
|
|
@@ -63,35 +68,47 @@ int main(int argc, char **argv)
|
|
|
// Start the controller
|
|
// Start the controller
|
|
|
pipe(controllerfds);
|
|
pipe(controllerfds);
|
|
|
if (fork() == 0) {
|
|
if (fork() == 0) {
|
|
|
- // Child; close the read half of the pipe
|
|
|
|
|
- close(controllerfds[0]);
|
|
|
|
|
- unsigned short bindport;
|
|
|
|
|
- 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);
|
|
|
|
|
- } else {
|
|
|
|
|
- // Parent; close the write half of the pipe
|
|
|
|
|
|
|
+ // Child; close the write half of the pipe
|
|
|
close(controllerfds[1]);
|
|
close(controllerfds[1]);
|
|
|
unsigned short boundport;
|
|
unsigned short boundport;
|
|
|
- unsigned char boundaddr[257];
|
|
|
|
|
|
|
+ char boundaddr[257];
|
|
|
int res;
|
|
int res;
|
|
|
|
|
|
|
|
res = read(controllerfds[0], &boundport, 2);
|
|
res = read(controllerfds[0], &boundport, 2);
|
|
|
if (res < 2) return 1;
|
|
if (res < 2) return 1;
|
|
|
res = read(controllerfds[0], boundaddr, 256);
|
|
res = read(controllerfds[0], boundaddr, 256);
|
|
|
if (res < 1) return 1;
|
|
if (res < 1) return 1;
|
|
|
|
|
+ close(controllerfds[0]);
|
|
|
boundaddr[res] = '\0';
|
|
boundaddr[res] = '\0';
|
|
|
|
|
|
|
|
std::cerr << "Child bound to " << boundaddr << ":" << boundport << "\n";
|
|
std::cerr << "Child bound to " << boundaddr << ":" << boundport << "\n";
|
|
|
|
|
+
|
|
|
|
|
+ // The child will spawn two of its own children to be the
|
|
|
|
|
+ // workers
|
|
|
|
|
+ if (fork() == 0) {
|
|
|
|
|
+ return worker_main(boundaddr, boundport);
|
|
|
|
|
+ } else if (fork() == 0) {
|
|
|
|
|
+ return worker_main(boundaddr, boundport);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // And now become the dpnode
|
|
|
|
|
+ return dpnode_main(boundaddr, boundport);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Parent; close the read half of the pipe
|
|
|
|
|
+ close(controllerfds[0]);
|
|
|
|
|
+ unsigned short bindport;
|
|
|
|
|
+ Worklist worklist;
|
|
|
|
|
+
|
|
|
|
|
+ if (controller_parse_args(argc, argv, bindport, worklist)) {
|
|
|
|
|
+ std::cerr << "Usage: " << argv[0] << " [-p listenport] N1 iter1 N2 iter2 ...\n";
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret = controller_main(worklist, bindport, boundcb);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
MPI_Finalize();
|
|
MPI_Finalize();
|
|
|
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ return ret;
|
|
|
}
|
|
}
|