 #include <stdio.h>
+#include <iostream>
 #include <cuComplex.h>
-#include <iostream>
 #include <getopt.h>
 #include <cmath>
 #include "offset.h"

      pixel->blue = rgb_value(200 - iter, 1000);
    }
  }
}

void threadConfigCalc(int maxThreads, int &threadsPerBlock1dim, int &numBlocksX, int &numBlocksY) {
  double sqroot = sqrt(maxThreads);
  threadsPerBlock1dim = exp2(fmin(floor(log2(sqroot)), 4));
  numBlocksY = floor(sqroot / threadsPerBlock1dim);
  numBlocksX = floor((double)maxThreads / (threadsPerBlock1dim * threadsPerBlock1dim * numBlocksY));
  printf("%d <= %d, threadsPerBlock: %dx%d, numBlocksXxnumBlocksY: %dx%d\n",
    threadsPerBlock1dim * threadsPerBlock1dim * numBlocksX * numBlocksY, maxThreads, threadsPerBlock1dim, threadsPerBlock1dim, numBlocksX, numBlocksY);
}

void generateImage(int width, int height, Offset offset, int maxThreads, const char* filename, bool quiet) {

  cudaMalloc(&bitmap.pixels, pixelsSize);

  int threadsPerBlock1dim, numBlocksX, numBlocksY;
  threadConfigCalc(maxThreads, threadsPerBlock1dim, numBlocksX, numBlocksY, quiet);

  dim3 threadsPerBlock(threadsPerBlock1dim, threadsPerBlock1dim);
  dim3 numBlocks(numBlocksX, numBlocksY);

  calc<<<numBlocks, threadsPerBlock>>>(offset, bitmap, quiet);

  cudaDeviceSynchronize();

