|
|
@@ -97,6 +97,8 @@ int main(int argc, char **argv)
|
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
|
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
|
|
|
|
|
|
+ char boundportaddr[259];
|
|
|
+
|
|
|
if (rank == 0) {
|
|
|
// Start the controller
|
|
|
pipe(controllerfds);
|
|
|
@@ -112,41 +114,44 @@ int main(int argc, char **argv)
|
|
|
} else {
|
|
|
// Parent; close the write half of the pipe
|
|
|
close(controllerfds[1]);
|
|
|
- unsigned short boundport;
|
|
|
- char boundaddr[257];
|
|
|
int res;
|
|
|
|
|
|
- res = read(controllerfds[0], &boundport, 2);
|
|
|
+ memset(boundportaddr, '\0', 259);
|
|
|
+ res = read(controllerfds[0], boundportaddr, 2);
|
|
|
if (res < 2) return 1;
|
|
|
- res = read(controllerfds[0], boundaddr, 256);
|
|
|
+ res = read(controllerfds[0], boundportaddr+2, 256);
|
|
|
if (res < 1) return 1;
|
|
|
close(controllerfds[0]);
|
|
|
- boundaddr[res] = '\0';
|
|
|
-
|
|
|
- std::cerr << "Parent reports controller bound to " << boundaddr << ":" << boundport << "\n";
|
|
|
-
|
|
|
- char portstr[10];
|
|
|
- sprintf(portstr, "%hu", boundport);
|
|
|
-
|
|
|
- // The child will spawn two of its own children to be the
|
|
|
- // workers
|
|
|
- if (fork_and_remember(children) == 0) {
|
|
|
- close_highfds_except(-1);
|
|
|
- execl("./worker", "./worker", boundaddr, portstr, "0", NULL);
|
|
|
- return 1;
|
|
|
- } else if (fork_and_remember(children) == 0) {
|
|
|
- close_highfds_except(-1);
|
|
|
- execl("./worker", "./worker", boundaddr, portstr, "0", NULL);
|
|
|
- return 1;
|
|
|
- } else if (fork_and_remember(children) == 0) {
|
|
|
- // And a dpnode
|
|
|
- close_highfds_except(-1);
|
|
|
- execl("./dpnode", "./dpnode", boundaddr, portstr, NULL);
|
|
|
- return 1;
|
|
|
- }
|
|
|
+
|
|
|
+ // std::cerr << "Parent reports controller bound to " << boundaddr << ":" << boundport << "\n";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ MPI_Bcast(boundportaddr, 259, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
|
+
|
|
|
+ unsigned short boundport;
|
|
|
+ memmove(&boundport, boundportaddr, 2);
|
|
|
+ char portstr[10];
|
|
|
+ sprintf(portstr, "%hu", boundport);
|
|
|
+ const char *boundaddr = boundportaddr + 2;
|
|
|
+
|
|
|
+ // The child will spawn two of its own children to be the
|
|
|
+ // workers
|
|
|
+ if (fork_and_remember(children) == 0) {
|
|
|
+ close_highfds_except(-1);
|
|
|
+ execl("./worker", "./worker", boundaddr, portstr, "0", NULL);
|
|
|
+ return 1;
|
|
|
+ } else if (fork_and_remember(children) == 0) {
|
|
|
+ close_highfds_except(-1);
|
|
|
+ execl("./worker", "./worker", boundaddr, portstr, "0", NULL);
|
|
|
+ return 1;
|
|
|
+ } else if (fork_and_remember(children) == 0) {
|
|
|
+ // And a dpnode
|
|
|
+ close_highfds_except(-1);
|
|
|
+ execl("./dpnode", "./dpnode", boundaddr, portstr, NULL);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
// Now wait for all the children
|
|
|
vector<pid_t>::iterator pidit;
|
|
|
for (pidit = children.begin(); pidit != children.end(); ++pidit) {
|