title: How to parallelize tasks with variable-number-of-tasks in PPL
body: <p>I'm normally used to using OpenMP for parallelizing tasks. However, I thought I might give Parallel Patterns Library a shot when I started working on a new project recently.</p>
  
  <p>Problem is that I have to store data in the list structure, which would have varying sizes throughout the process. I could parallelize lists with OpenMP with creating tasks with each iteration, and I tried to accomplish the same thing with the following code</p>
  
  <pre><code>#include &lt;list&gt;
  #include &lt;ppl.h&gt;
  #include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  using namespace std;
  using namespace Concurrency;
  
  void expo(double x){
      double r = 1;
  
      for(int i = 0 ; i&lt;1000000 ; ++i){
          r *= x;
      }
      cout &lt;&lt; r &lt;&lt; " ";
  }
  
  int wmain()
  {
      int begin,end;
      list&lt;int&gt; numbers;
      for(int i=1; i&lt;11 ; ++i){
          numbers.push_back(i);
      }
  
      list&lt;int&gt;::iterator lit;
  
      structured_task_group tasks;
      begin = GetTickCount();
      for(lit=numbers.begin() ; lit!=numbers.end() ; lit++){
          int k = *lit;
          auto task1 = make_task([&amp;k](){ expo(k); });
          tasks.run(task1);
          tasks.wait();
      }
      end = GetTickCount();
      printf("elapsed: %d ms",end - begin);
      cin.get();
      return 0;
  }
  </code></pre>
  
  <p>But, as you can see, I have to wait to the completion of the task inside the for-loop, which implies a serial execution. If I place "tasks.wait()" after the for-loop, I am getting an error, and the compiler says that there is a wait command missing after the run command. </p>
  
  <p>How can I get around this problem? </p>
  
  <p>By the way, do you know any good tutorial on PPL? I have found this page (http://msdn.microsoft.com/en-us/library/dd492418.aspx) which didn't seem to me as the perfect tutorial for a beginner. </p>
  
  <p>Thanks in advance!</p>