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

+ 26 - 0
dpnode.cc

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

+ 2 - 0
dpstream.cu

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

+ 8 - 0
parrhoasm.cu

@@ -31,6 +31,8 @@
 
 
 // #define CHECK_RESULTS
 // #define CHECK_RESULTS
 
 
+// #define VERBOSE
+
 // #include "cuPrintf.cu"
 // #include "cuPrintf.cu"
 
 
 #define BITS_PER_WORD (8 * sizeof(unsigned int))
 #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)
     while(stop_computing == false)
 #endif
 #endif
     {
     {
+#ifdef VERBOSE
 	cerr << getpid() << " Launch " << ++launchcount << "...\n";
 	cerr << getpid() << " Launch " << ++launchcount << "...\n";
+#else
+	++launchcount;
+#endif
 	cudaMulmod<<< nblocks, nthreads/nblocks /*tpb*/, 0 >>>(d_ts,
 	cudaMulmod<<< nblocks, nthreads/nblocks /*tpb*/, 0 >>>(d_ts,
 	    order_0, order_1, order_2, dpfreq);
 	    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);
 	stop_computing = DPstreamParse(cbdata);
 	//cudaPrintfExtractDPE(dpcallback, cbdata);
 	//cudaPrintfExtractDPE(dpcallback, cbdata);
 	//cudaPrintfDisplay(stdout, true);
 	//cudaPrintfDisplay(stdout, true);
+#ifdef VERBOSE
 	cerr << getpid() << "\n";
 	cerr << getpid() << "\n";
+#endif
     }
     }
     gettimeofday(&et, NULL);
     gettimeofday(&et, NULL);
 
 

+ 12 - 11
worker.cc

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