title: Flood fill in CUDA
body: <p>I got a task to do. I need to run a Flood Fill algorithm on CUDA. On CPU I have a non-recursive method with queue, but I dont have any idea how to do move this code to GPU so that it would run faster. Can anybody help?</p>
  
  <p>edit:
  this is my CPU code, just normal FloodFill with my little modifications</p>
  
  <pre><code>void cpuFloodFill(std::vector&lt;std::vector&lt;int&gt;&gt; *colorVector, int node)
  {
      std::queue&lt;int&gt; q;
      q.push(node);
  
      int i,j;
  
      while(!q.empty())
      {
          int k = q.front();
          q.pop();
  
          k2ij(k, &amp;i, &amp;j);
          if((*colorVector)[i][j] == COLOR_TARGET)
          {
              (*colorVector)[i][j] = COLOR_REPLACEMENT;           
              if(i - 1 &gt;= 0 &amp;&amp; i - 1 &lt; X &amp;&amp; j &gt;= 0 &amp;&amp; j &lt; Y)
                  q.push(ij2k(i - 1, j));
  
              if(i + 1 &gt;= 0 &amp;&amp; i + 1 &lt; X &amp;&amp; j &gt;= 0 &amp;&amp; j &lt; Y)
                  q.push(ij2k(i + 1, j));
  
              if(i &gt;= 0 &amp;&amp; i &lt; X &amp;&amp; j - 1 &gt;= 0 &amp;&amp; j - 1 &lt; Y)
                  q.push(ij2k(i, j - 1));
  
              if(i &gt;= 0 &amp;&amp; i &lt; X &amp;&amp; j + 1 &gt;= 0 &amp;&amp; j + 1 &lt; Y)
                  q.push(ij2k(i, j + 1));
          }
  
      }
  }
  </code></pre>