Commit ab322fd9 authored by Vadim Markovtsev's avatar Vadim Markovtsev
Browse files

Fix the infinitite loop in reading files

parent bc70271a
...@@ -79,6 +79,10 @@ Options: ...@@ -79,6 +79,10 @@ Options:
--window_size <int> --window_size <int>
Specifies the window size for computing co-occurrence stats; Specifies the window size for computing co-occurrence stats;
default 10. default 10.
--num_threads <int>
The number of workers to calculate the co-occurrence matrix;
default 4.
)"; )";
struct cooc_t { struct cooc_t {
...@@ -448,7 +452,7 @@ void CoocCounter::Count() { ...@@ -448,7 +452,7 @@ void CoocCounter::Count() {
fin_.seekg(start_); fin_.seekg(start_);
int nlines = 0; 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. // Buffer a single sentence.
std::vector<int> sentence; std::vector<int> sentence;
bool eos; bool eos;
...@@ -633,6 +637,8 @@ int main(int argc, char *argv[]) { ...@@ -633,6 +637,8 @@ int main(int argc, char *argv[]) {
std::vector<pthread_t> threads; std::vector<pthread_t> threads;
std::vector<CoocCounter*> counters; std::vector<CoocCounter*> counters;
const off_t nbytes_per_thread = input_size / num_threads; 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; pthread_attr_t attr;
if (pthread_attr_init(&attr) != 0) { if (pthread_attr_init(&attr) != 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment