Prechádzať zdrojové kódy

Fix the infinitite loop in reading files

Vadim Markovtsev 8 rokov pred
rodič
commit
ab322fd9c8
1 zmenil súbory, kde vykonal 7 pridanie a 1 odobranie
  1. 7 1
      swivel/fastprep.cc

+ 7 - 1
swivel/fastprep.cc

@@ -79,6 +79,10 @@ Options:
   --window_size <int>
       Specifies the window size for computing co-occurrence stats;
       default 10.
+
+  --num_threads <int>
+      The number of workers to calculate the co-occurrence matrix;
+      default 4.
 )";
 
 struct cooc_t {
@@ -448,7 +452,7 @@ void CoocCounter::Count() {
   fin_.seekg(start_);
 
   int nlines = 0;
-  for (off_t filepos = start_; filepos < end_; filepos = fin_.tellg()) {
+  for (off_t filepos = start_; filepos < end_ && !fin_.eof(); filepos = fin_.tellg()) {
     // Buffer a single sentence.
     std::vector<int> sentence;
     bool eos;
@@ -633,6 +637,8 @@ int main(int argc, char *argv[]) {
   std::vector<pthread_t> threads;
   std::vector<CoocCounter*> counters;
   const off_t nbytes_per_thread = input_size / num_threads;
+  std::cout << "Running " << num_threads << " threads, each on "
+            << nbytes_per_thread << " bytes" << std::endl;
 
   pthread_attr_t attr;
   if (pthread_attr_init(&attr) != 0) {