title: How to parallelize reading lines from an input file when lines get independently processed?
body: <p>I just started off with OpenMP using C++. My serial code in C++ looks something like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char* argv[]) {
      string line;
      std::ifstream inputfile(argv[1]);
  
      if(inputfile.is_open()) {
          while(getline(inputfile, line)) {
              // Line gets processed and written into an output file
          }
      }
  }
  </code></pre>
  
  <p>Because each line is pretty much independently processed, I was attempting to use OpenMP to parallelize this because the input file is in the order of gigabytes. So I'm guessing that first I need to get the number of lines in the input file and then parallelize the code this way. Can someone please help me out here?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  #include &lt;stdlib.h&gt;
  
  #ifdef _OPENMP
  #include &lt;omp.h&gt;
  #endif
  
  int main(int argc, char* argv[]) {
      string line;
      std::ifstream inputfile(argv[1]);
  
      if(inputfile.is_open()) {
          //Calculate number of lines in file?
          //Set an output filename and open an ofstream
          #pragma omp parallel num_threads(8)
          {
              #pragma omp for schedule(dynamic, 1000)
              for(int i = 0; i &lt; lines_in_file; i++) {
                   //What do I do here? I cannot just read any line because it requires random access
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>Important Things</strong></p>
  
  <ol>
  <li>Each line is independently processed</li>
  <li>Order of the results don't matter</li>
  </ol>