Ian Goldberg 14 лет назад
Родитель
Сommit
5c6cb43565
2 измененных файлов с 33 добавлено и 28 удалено
  1. 1 1
      Makefile
  2. 32 27
      mpi.cc

+ 1 - 1
Makefile

@@ -25,7 +25,7 @@ CXX ?= g++
 
 WORDS = 24
 
-CXXFLAGS=-g -Wall -O0
+CXXFLAGS=-g -Wall -O2
 CPPFLAGS=-DWORDS=$(WORDS) -I$(LIBEVENT)/include -I$(GMP)/include -UVERBOSE
 NVCCOPTS=-g -arch sm_20 --ptxas-options=-v -O2
 NVCC=nvcc $(NVCCOPTS)

+ 32 - 27
mpi.cc

@@ -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) {