title: cuda compute wrong result in multiply counters
body: <p>i am writing a code in cuda to try learning some concepts , here is the problem :  </p>
  
  <p>in line <strong>@@@</strong> if i use <strong>(i*i)</strong> it works well and result of multiply is true . but when i'm putting <strong>(i*j)</strong> counter , instead of <strong>(i*i)</strong> it produce wrong results. i think it may be my fault to set wrong <strong>dimgrid &amp; dimblock</strong> or something else !!! any idea how to solve the problem ?<br>
  i put the c++ version at the end of my code to compare results.
  thank you for your advise.</p>
  
  <p>Here is my code :  </p>
  
  <pre><code>#include "cuda.h"
  #include "stdio.h"
  #include "stdlib.h"
  #include "iostream"
  #include "time.h"
  
  double diffclock(clock_t clock1,clock_t clock2) 
  {
  double diffticks=clock1-clock2;
  double diffms=(diffticks*10)/CLOCKS_PER_SEC;
  return diffms;
  } 
  
  using namespace std;
  __global__ void add( int *c)
  {
  
  int i = threadIdx.x + blockIdx.x * blockDim.x;
  int j = threadIdx.y + blockIdx.y * blockDim.y;
  int k = threadIdx.z + blockIdx.z * blockDim.z;
  int nx,ny,nz;
  nx = 512;
  ny = 512 ;
  nz = 51200 ;
  if ((i &lt; nx) &amp;&amp; (j &lt; ny) &amp;&amp; (k &lt; nz))
  {
  
      *c = i*i; // **@@@**
  
  }
  }
  
  int main()
  {
  printf("****************************************************************\n");
  printf("                  CUDA_C COMPARISONE MODEL                          \n");
  printf("\n");
  printf("\n");
  printf("this program will produce 512 * 512 * 51,200 for loop iteration \n");
  printf("you can compare time elapsed between c++ version &amp; cuda version \n");
  printf("\n");
  printf("\n");
  
  printf("\n");
  printf("****************************************************************\n");
  cudaEvent_t beginEvent;
  cudaEvent_t endEvent;
  cudaEventCreate( &amp;beginEvent );
  cudaEventCreate( &amp;endEvent );
  int c;
  int *dev_c;
  cudaMalloc((void**)&amp;dev_c, sizeof(int));
  dim3 dimgrid (16 , 16);
  dim3 dimblock(32 , 32);
  cudaEventRecord( beginEvent, 0 );
  add&lt;&lt;&lt;dimgrid,dimblock&gt;&gt;&gt;(dev_c);
  cudaMemcpy(&amp;c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
  cudaEventRecord( endEvent, 0 );
  cudaEventSynchronize( endEvent );
  float timeValue;
  cudaEventElapsedTime( &amp;timeValue, beginEvent, endEvent );
  printf( "Time elapsed in G-p-u : %f  ms \n" ,timeValue );
  printf("_____________________________________________________\n");
  printf("G-p-u multiply computation is =====&gt;&gt;&gt; %d\n", c);
  printf("_____________________________________________________\n");
  
  
  // c++  code :
  
  int n1 = 512 ;
  int n2 = 512 ;
  int n3 = 51200;
  
  clock_t begin=clock();
  
  int cp , ii,jj,kk;
  for(kk=0; kk&lt;n3; kk++)
    for(ii=0; ii&lt;n2; ii++)
      for(jj=0; jj&lt;n1; jj++)
           cp = (ii)*(jj);
  
  clock_t end=clock();
  cout &lt;&lt; "Time elapsed in C-p-u : " &lt;&lt; double(diffclock(end,begin)) &lt;&lt; " ms"&lt;&lt; endl;
  printf("_____________________________________________________\n");
  printf("_____________________________________________________\n");
  
  printf("C-p-u multiply computation is =====&gt;&gt;&gt; %d\n", cp);
  cudaFree(dev_c);
  return 0;
  }
  </code></pre>