title: OpenMP: writing into std::map concurrently
body: <p>i have a <code>std::map</code> with the key being identical to the thread_num. each thread is writing into the value, a <code>std::vector</code> here. hence it is guaranteed that each thread is only operating on "his" <code>std::vector</code>.</p>
  
  <p>Example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;omp.h&gt;
  #include &lt;map&gt;
  #include &lt;vector&gt;
  
  
  int main(void) {
  
      std::map&lt;unsigned int, std::vector&lt;unsigned int&gt; &gt; M;
  
  // initialize map using first touch policy:
  #pragma omp parallel for schedule(static,1)
      for (int i=0; i&lt;omp_get_num_procs(); ++i) {
  #pragma omp critical
          M[omp_get_thread_num()] = std::vector&lt;unsigned int&gt;();
      }
  
  // do some parallel operations:
  #pragma omp parallel for schedule(static)
      for (int i=0; i&lt;100; ++i) {
          M[omp_get_thread_num()].push_back(i);
      }
  
  // disp the content:
      for (auto it_key : M) {
          std::cout &lt;&lt; "thread " &lt;&lt; it_key.first &lt;&lt; " : {";
          for (auto it_vec : it_key.second) {
              std::cout &lt;&lt; it_vec &lt;&lt; " ";
          }
          std::cout &lt;&lt; "\b \b}" &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>the output looks as desired. the question would be whether the above code is legal? so i can  conclude that i can operate on a <code>std::map</code> in parallel, as long as i can guarantee that only one thread is operating on the secondary data of a specific key?</p>