Procházet zdrojové kódy

Moved almost all output to #ifdef VERBOSE

The controller still outputs the final answer and the timings,
and the worker still outputs the subproblem id and the CUDA compute times.
Ian Goldberg před 14 roky
rodič
revize
03af039f7f
5 změnil soubory, kde provedl 53 přidání a 14 odebrání
  1. 5 3
      controller.cc
  2. 26 0
      dpnode.cc
  3. 2 0
      dpstream.cu
  4. 8 0
      parrhoasm.cu
  5. 12 11
      worker.cc

+ 5 - 3
controller.cc

@@ -26,7 +26,7 @@ extern "C" {
 
 NTL_CLIENT
 
-#define DEBUG
+#undef VERBOSE
 
 struct SubproblemProgress;
 
@@ -245,7 +245,7 @@ struct SubproblemProgress : Subproblem {
 	for (unsigned short i = 0; i < num_ipports; ++i) {
 	    bufferevent_write(bev, ipports[i].ipport, 6);
 	}
-#ifdef DEBUG
+#ifdef VERBOSE
 	cerr << "Added worker " << bev << " to subproblem "
 		<< problemid << "\n";
 #endif
@@ -556,8 +556,8 @@ static void controller_dpnode_reader(struct bufferevent *bev, void *ctx)
 		memmove(&DPip, ipport, 4);
 		memmove(&DPport, ipport+4, 2);
 		{
+#ifdef VERBOSE
 		    struct in_addr DPaddr = { DPip };
-#ifdef DEBUG
 		    fprintf(stderr, "DP node at %s:%d\n", inet_ntoa(DPaddr), ntohs(DPport));
 #endif
 		    if (ctrlstate.dpnodes.working.count(bev) > 0) {
@@ -771,7 +771,9 @@ int controller_main(const char *modulus_file, unsigned short bindport)
 
     ctrlstate.listener = controller_create(evbase, bindport, &myip, &myport);
     struct in_addr myaddr = { myip };
+#ifdef VERBOSE
     printf("Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
+#endif
 
     ctrlstate.problems_remaining = 2;
 

+ 26 - 0
dpnode.cc

@@ -22,6 +22,8 @@ extern "C" {
 #include "subproblem.h"
 #include "dpnode.h"
 
+#undef VERBOSE
+
 typedef map<std::string, pair<ZZ,ZZ> > DTable;
 
 typedef enum {
@@ -96,6 +98,7 @@ static void dpnode_event_cb(struct bufferevent *bev, short events,
     void *ctx)
 {
     if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
+#ifdef VERBOSE
 	cerr << "Closing connection " << bev << " ";
 	if (events & BEV_EVENT_EOF) {
 	    cerr << "EOF";
@@ -104,6 +107,7 @@ static void dpnode_event_cb(struct bufferevent *bev, short events,
 	    cerr << "ERR (" << evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()) << ")";
 	}
 	cerr << "\n";
+#endif
 	DPNodeConnInfo *info = (DPNodeConnInfo*)ctx;
 	delete info;
 	dpctrlstate.workers.erase(bev);
@@ -154,7 +158,9 @@ static void dpnode_reader(struct bufferevent *bev, void *ctx)
 	    ZZ binv;
 	    if (InvModStatus(binv, bdiff, order) == 0) {
 		ZZ expon = MulMod(binv, adiff, order);
+#ifdef VERBOSE
 		cerr << "Collision after " << dpctrlstate.numdps << " DPs\n";
+#endif
 		unsigned char exponbytes[3+3*sizeof(unsigned int)];
 		exponbytes[0] = 'E';
 		memmove(exponbytes+1,
@@ -180,7 +186,9 @@ static void dpnode_accept_cb(struct evconnlistener *listener,
     struct event_base *base = evconnlistener_get_base(listener);
     struct bufferevent *bev = bufferevent_socket_new(
 	    base, fd, BEV_OPT_CLOSE_ON_FREE);
+#ifdef VERBOSE
     cerr << "accepted connection " << bev << "\n";
+#endif
 
     bufferevent_setcb(bev, dpnode_reader, NULL,
 	    dpnode_event_cb, info);
@@ -198,7 +206,9 @@ struct evconnlistener *dpnode_create(struct event_base *evbase,
     struct evconnlistener *ecl = listener_create(evbase, 0,
 	dpnode_accept_cb, NULL, ip, boundport, false);
 
+#ifdef VERBOSE
     cerr << "Listening at " << ecl << "\n";
+#endif
 
     return ecl;
 }
@@ -217,20 +227,26 @@ struct DPControllerConnInfo {
 
 static void stop_problem(void)
 {
+#ifdef VERBOSE
     cerr << "Stopping problem\n";
+#endif
     if (dpctrlstate.current_problem) {
 	delete dpctrlstate.current_problem;
 	dpctrlstate.current_problem = NULL;
     }
     if (dpctrlstate.listener) {
+#ifdef VERBOSE
 	cerr << "Closing listener " << dpctrlstate.listener << "\n";
+#endif
 	evconnlistener_free(dpctrlstate.listener);
 	dpctrlstate.listener = NULL;
     }
     std::set<struct bufferevent *>::iterator wit;
     for (wit = dpctrlstate.workers.begin(); wit != dpctrlstate.workers.end();
 	    ++wit) {
+#ifdef VERBOSE
 	cerr << "Closing connection " << *wit << "\n";
+#endif
 	bufferevent_free(*wit);
     }
     dpctrlstate.workers.clear();
@@ -252,13 +268,17 @@ static void start_problem(struct bufferevent *bev,
 
     stop_problem();
     dpctrlstate.current_problem = new Subproblem(subproblem);
+#ifdef VERBOSE
     dpctrlstate.current_problem->dump(cerr);
+#endif
 
     // Create the DPNode server socket
     dpctrlstate.listener = dpnode_create(bufferevent_get_base(bev),
 	    &myip, &myport);
+#ifdef VERBOSE
     struct in_addr myaddr = { myip };
     fprintf(stderr, "Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
+#endif
     unsigned char idstring[7];
     idstring[0] = 'L';
     memmove(idstring+1, &myip, 4);
@@ -280,7 +300,9 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 	    case DPCCSTATE_AWAITCMD:
 		if (len < 1) return;
 		bufferevent_read(bev, cmd, 1);
+#ifdef VERBOSE
 		cerr << "Received command " << cmd[0] << "\n";
+#endif
 		switch(cmd[0]) {
 		    case 'P':
 			info->state = DPCCSTATE_RDPROBLEM;
@@ -308,7 +330,9 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 		// Shut down
 		delete info;
 		event_base_loopbreak(bufferevent_get_base(bev));
+#ifdef VERBOSE
 		cerr << "END conenction " << bev << "\n";
+#endif
 		dpctrlstate.workers.erase(bev);
 		bufferevent_free(bev);
 		return;
@@ -329,7 +353,9 @@ static void controllerconn_event_cb(struct bufferevent *bev, short events,
 		controllerconn_event_cb, new DPControllerConnInfo());
 	dpctrlstate.controller_bev = bev;
     } else if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
+#ifdef VERBOSE
 	fprintf(stderr, "Closing connection to controller and exiting\n");
+#endif
 	event_base_loopbreak(bufferevent_get_base(bev));
 	bufferevent_free(bev);
     }

+ 2 - 0
dpstream.cu

@@ -95,7 +95,9 @@ bool DPstreamParse(void *data)
     // Get the number of words in the buffer
     unsigned int bufsize;
     cudaMemcpyFromSymbol(&bufsize, DPbuffertail, sizeof(unsigned int));
+#ifdef VERBOSE
     cerr << getpid() << " " << bufsize / DPrecordsize << " DPs\n";
+#endif
     unsigned int *dpbuf = (unsigned int*)calloc(bufsize, sizeof(unsigned int));
     bool stop_computing = false;
     if (dpbuf) {

+ 8 - 0
parrhoasm.cu

@@ -31,6 +31,8 @@
 
 // #define CHECK_RESULTS
 
+// #define VERBOSE
+
 // #include "cuPrintf.cu"
 
 #define BITS_PER_WORD (8 * sizeof(unsigned int))
@@ -478,7 +480,11 @@ void cuda_dl(const ZZ_p &base, const ZZ_p &target, const ZZ &order,
     while(stop_computing == false)
 #endif
     {
+#ifdef VERBOSE
 	cerr << getpid() << " Launch " << ++launchcount << "...\n";
+#else
+	++launchcount;
+#endif
 	cudaMulmod<<< nblocks, nthreads/nblocks /*tpb*/, 0 >>>(d_ts,
 	    order_0, order_1, order_2, dpfreq);
 
@@ -487,7 +493,9 @@ void cuda_dl(const ZZ_p &base, const ZZ_p &target, const ZZ &order,
 	stop_computing = DPstreamParse(cbdata);
 	//cudaPrintfExtractDPE(dpcallback, cbdata);
 	//cudaPrintfDisplay(stdout, true);
+#ifdef VERBOSE
 	cerr << getpid() << "\n";
+#endif
     }
     gettimeofday(&et, NULL);
 

+ 12 - 11
worker.cc

@@ -23,7 +23,7 @@ extern "C" {
 
 NTL_CLIENT
 
-#define DEBUG
+#undef VERBOSE
 
 typedef enum {
     WRKCCSTATE_AWAITCMD,
@@ -102,7 +102,7 @@ static void *worker_thread_start(void *data)
 
 static void stop_working(void)
 {
-#ifdef DEBUG
+#ifdef VERBOSE
     cerr << "Stopping work\n";
 #endif
     if (wrkctrlstate.worker_thread_state != WT_NOT_RUNNING) {
@@ -116,7 +116,7 @@ static void stop_working(void)
     vector<struct bufferevent *>::iterator bevit;
     for (bevit = wrkctrlstate.dpnodes.begin();
 	    bevit != wrkctrlstate.dpnodes.end(); ++bevit) {
-#ifdef DEBUG
+#ifdef VERBOSE
 	cerr << "Closing connection to " << *bevit << "\n";
 #endif
 	bufferevent_free(*bevit);
@@ -132,9 +132,10 @@ static void stop_working(void)
 
 static void start_working(void)
 {
-#ifdef DEBUG
+#ifdef VERBOSE
     cerr << "Starting work\n";
 #endif
+    cout << "Subproblem " << wrkctrlstate.current_problem->problemid << "\n";
     wrkctrlstate.worker_thread_state = WT_RUNNING;
     if (pthread_create(&wrkctrlstate.worker_thread, NULL,
 			worker_thread_start, NULL)) {
@@ -148,7 +149,7 @@ static void dpconn_event_cb(struct bufferevent *bev, short events,
 {
     if (events & BEV_EVENT_CONNECTED) {
 	// We have successfully connected to the dpnode
-#ifdef DEBUG
+#ifdef VERBOSE
 	cerr << "Connection established to dpnode " << bev << "\n";
 #endif
 	bufferevent_enable(bev, EV_WRITE);
@@ -158,7 +159,7 @@ static void dpconn_event_cb(struct bufferevent *bev, short events,
 	    start_working();
 	}
     } else if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
-#ifdef DEBUG
+#ifdef VERBOSE
 	cerr << "Closing connection to dpnode " << bev << " ";
 	if (events & BEV_EVENT_EOF) {
 	    cerr << "EOF";
@@ -185,7 +186,7 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 	    case WRKCCSTATE_AWAITCMD:
 		if (len < 1) return;
 		bufferevent_read(bev, cmd, 1);
-#ifdef DEBUG
+#ifdef VERBOSE
 		cerr << "Command " << cmd[0] << " received\n";
 #endif
 		switch(cmd[0]) {
@@ -223,7 +224,7 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 		    for(i=0;i<info->num_dpnodes;++i) {
 			unsigned char ipport[6];
 			bufferevent_read(bev, ipport, 6);
-#ifdef DEBUG
+#ifdef VERBOSE
 			cerr << "Connecting to DPnode " <<
 				    int(ipport[0]) << "." <<
 				    int(ipport[1]) << "." <<
@@ -235,7 +236,7 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 			struct bufferevent *dpbev = client_create(
 				bufferevent_get_base(bev), ipport,
 				dpconn_event_cb, true);
-#ifdef DEBUG
+#ifdef VERBOSE
 			cerr << "Starting connection to dpnode " << dpbev << "\n";
 #endif
 			if (dpbev) {
@@ -252,7 +253,7 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 		// Shut down
 		delete info;
 		event_base_loopbreak(bufferevent_get_base(bev));
-#ifdef DEBUG
+#ifdef VERBOSE
 		cerr << "Closing connection to " << bev << "\n";
 #endif
 		bufferevent_free(bev);
@@ -275,7 +276,7 @@ static void controllerconn_event_cb(struct bufferevent *bev, short events,
     } else if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
 	fprintf(stderr, "Closing connection to controller and exiting\n");
 	event_base_loopbreak(bufferevent_get_base(bev));
-#ifdef DEBUG
+#ifdef VERBOSE
 	cerr << "Closing connection to " << bev << "\n";
 #endif
 	bufferevent_free(bev);