Parcourir la source

Output timestamp and host information to the cout log

Ian Goldberg il y a 14 ans
Parent
commit
a1d3f9fa44
7 fichiers modifiés avec 51 ajouts et 5 suppressions
  1. 17 2
      controller.cc
  2. 2 0
      dlrho.cc
  3. 1 1
      mpi.cc
  4. 6 1
      parrhoasm.cu
  5. 6 1
      worker.cc
  6. 5 0
      worker.h
  7. 14 0
      worker_main.cc

+ 17 - 2
controller.cc

@@ -28,6 +28,9 @@ NTL_CLIENT
 
 // #undef VERBOSE
 
+// Used to prefix output from this process
+std::string output_prefix;
+
 struct SubproblemProgress;
 
 typedef std::set<struct bufferevent *> BESet;
@@ -403,8 +406,14 @@ static void computation_complete(void)
     sprintf(length_buf, "%lld.%03lld s", computation_length_ms / 1000,
 					    computation_length_ms % 1000);
 
-    cout << "expon = " << expon << "\n";
-    cout << ctrlstate.worklist[0].first << " ";
+    char timestamp[20];
+    sprintf(timestamp, "%d.%06d",
+	    (int)ended_working.tv_sec, (int)ended_working.tv_usec);
+
+    cout << timestamp << ":" << output_prefix << ": " <<
+	    "expon = " << expon << "\n";
+    cout << timestamp << ":" << output_prefix << ": " <<
+	    ctrlstate.worklist[0].first << " ";
     ZZ base_exp = PowerMod(ctrlstate.base, expon, ctrlstate.rho);
     if (base_exp == ctrlstate.target) {
 	cout << "CORRECT in " << length_buf << "\n";
@@ -821,6 +830,12 @@ int controller_main(const Worklist &worklist, unsigned short bindport,
 	return 0;
     }
 
+    // Initialize the output prefix
+    char prefix[300];
+    gethostname(prefix, 256);
+    strcat(prefix, "-C");
+    output_prefix = std::string(prefix);
+
     ctrlstate.worklist = worklist;
 
     // Read the modulus and the factorization of its totient from the

+ 2 - 0
dlrho.cc

@@ -33,6 +33,8 @@
 
 NTL_CLIENT
 
+string output_prefix;
+
 typedef map<std::string, pair<ZZ,ZZ> > DTable;
 
 struct CBData {

+ 1 - 1
mpi.cc

@@ -143,7 +143,7 @@ int main(int argc, char **argv)
 	return 1;
     } else if (fork_and_remember(children) == 0) {
 	close_highfds_except(-1);
-	execl("./worker", "./worker", boundaddr, portstr, "0", NULL);
+	execl("./worker", "./worker", boundaddr, portstr, "1", NULL);
 	return 1;
     } else if (fork_and_remember(children) == 0) {
 	// And a dpnode

+ 6 - 1
parrhoasm.cu

@@ -29,6 +29,8 @@
 #include <utility>
 #include <map>
 
+#include "worker.h"
+
 // #define CHECK_RESULTS
 
 // #define VERBOSE
@@ -536,8 +538,11 @@ cout << i << ": " << l_Z[i] << " != " << l_z[i + t * WORDS] << "\n";
     }
 #endif
 
+    char timestamp[20];
+    sprintf(timestamp, "%d.%06d", et.tv_sec, et.tv_usec);
+
     unsigned long long totnanos = totmicros * 1000;
-    cout << totmicros << " us / " << nthreads << " = " << totmicros / nthreads << " us / " << (nmult*launchcount) << " = " << totnanos / ((unsigned long long)nthreads * nmult * launchcount) << " ns\n";
+    cout << timestamp << ":" << output_prefix << ": " << totmicros << " us / " << nthreads << " = " << totmicros / nthreads << " us / " << (nmult*launchcount) << " = " << totnanos / ((unsigned long long)nthreads * nmult * launchcount) << " ns\n";
     cout.flush();
     //cudaPrintfEnd();
     DPstreamEnd();

+ 6 - 1
worker.cc

@@ -136,7 +136,12 @@ static void start_working(void)
 #ifdef VERBOSE
     cerr << "Starting work\n";
 #endif
-    cout << "Subproblem " << wrkctrlstate.current_problem->problemid << "\n";
+    struct timeval now;
+    gettimeofday(&now, NULL);
+    char timestamp[20];
+    sprintf(timestamp, "%d.%06d", (int)now.tv_sec, (int)now.tv_usec);
+
+    cout << timestamp << ":" << output_prefix << ": Subproblem " << wrkctrlstate.current_problem->problemid << "\n";
     cout.flush();
     wrkctrlstate.worker_thread_state = WT_RUNNING;
     if (pthread_create(&wrkctrlstate.worker_thread, NULL,

+ 5 - 0
worker.h

@@ -1,6 +1,11 @@
 #ifndef __WORKER_H__
 #define __WORKER_H__
 
+#include <string>
+
+// Used to prefix output from this process
+extern std::string output_prefix;
+
 int worker_main(const char *controller_host, unsigned short controller_port);
 
 #endif

+ 14 - 0
worker_main.cc

@@ -1,8 +1,15 @@
+#include <string>
+
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
 
 #include "worker.h"
 
+// Used to prefix output from this process
+std::string output_prefix;
+
 int main(int argc, char **argv)
 {
     if (argc != 4) {
@@ -12,5 +19,12 @@ int main(int argc, char **argv)
 
     unsigned short controller_port = strtoul(argv[2], NULL, 10);
 
+    // Initialize the output prefix
+    char prefix[300];
+    gethostname(prefix, 256);
+    strcat(prefix, "-");
+    strcat(prefix, argv[3]);
+    output_prefix = std::string(prefix);
+
     return worker_main(argv[1], controller_port);
 }