title: What does #pragma unroll do exactly? Does it affect the number of threads?
body: <p>I'm new to CUDA, and I can't understand loop unrolling. I've written a piece of code to understand the technique</p>
  
  <pre><code>__global__ void kernel(float *b, int size)
  {
      int tid = blockDim.x * blockIdx.x + threadIdx.x;
   #pragma unroll
      for(int i=0;i&lt;size;i++)
          b[i]=i;
  }
  </code></pre>
  
  <p>Above is my kernel function. In <code>main</code> I call it like below</p>
  
  <pre><code>int main()
  {
      float * a; //host array
      float * b; //device array
      int size=100;
  
      a=(float*)malloc(size*sizeof(float));
      cudaMalloc((float**)&amp;b,size);
      cudaMemcpy(b, a, size, cudaMemcpyHostToDevice);
  
      kernel&lt;&lt;&lt;1,size&gt;&gt;&gt;(b,size); //size=100
  
      cudaMemcpy(a, b, size, cudaMemcpyDeviceToHost);
  
      for(int i=0;i&lt;size;i++)
          cout&lt;&lt;a[i]&lt;&lt;"\t";
  
      _getch();
  
      return 0;
  }
  </code></pre>
  
  <p>Does it mean I have <code>size</code>*<code>size</code>=10000 threads running to execute the program? Are 100 of them created when loop is unrolled?</p>