title: Finding maximum and minimum with CUBLAS
body: <p>I'm having problems grasping why my function that finds maximum and minimum in a range of doubles using CUBLAS doesn't work properly.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>void findMaxAndMinGPU(double* values, int* max_idx, int* min_idx, int n)
  {
      double* d_values;
      cublasHandle_t handle;
      cublasStatus_t stat;
      safecall( cudaMalloc((void**) &amp;d_values, sizeof(double) * n), "cudaMalloc     (d_values) in findMaxAndMinGPU");
      safecall( cudaMemcpy(d_values, values, sizeof(double) * n, cudaMemcpyHostToDevice), "cudaMemcpy (h_values &gt; d_values) in findMaxAndMinGPU");
      cublasCreate(&amp;handle);
  
      stat = cublasIdamax(handle, n, d_values, sizeof(double), max_idx);
      if (stat != CUBLAS_STATUS_SUCCESS)
          printf("Max failed\n");
  
      stat = cublasIdamin(handle, n, d_values, sizeof(double), min_idx);
      if (stat != CUBLAS_STATUS_SUCCESS)
          printf("min failed\n");
  
      cudaFree(d_values);
      cublasDestroy(handle);
  }
  </code></pre>
  
  <p>Where values is the values to search within. The max_idx and min_idx are the index of the found numbers in values.
  The results from the CUBLAS-calls seems rather random and output wrong indexes.</p>
  
  <p>Anyone with a golly good answer to my problem? I am a tad sad at the moment :(</p>