This is my code for the stage1 part of calculating the histogram and returning the most common pixel value for the image. How can I improve it because this parallelization is not giving me better performance?
#pragma omp parallel for private(t_y, p_x, p_y, tile_index, tile_offset, pixel_offset, pixel) schedule(dynamic, 1)
for (t_x = 0; t_x < openMP_TILES_X; ++t_x) {
for (t_y = 0; t_y < openMP_TILES_Y; ++t_y) {
const unsigned int tile_index = (t_y * openMP_TILES_X + t_x);
const unsigned int tile_offset = (t_y * openMP_TILES_X * TILE_SIZE * TILE_SIZE + t_x * TILE_SIZE);
// For each pixel within the tile
for (int p_x = 0; p_x < TILE_SIZE; ++p_x) {
for (int p_y = 0; p_y < TILE_SIZE; ++p_y) {
// Load pixel
const unsigned int pixel_offset = (p_y * openMP_input_image.width + p_x);
const unsigned char pixel = openMP_input_image.data[tile_offset + pixel_offset];
openMP_histograms[tile_index].histogram[pixel]++;
global_histogram[pixel]++;
}
}
}
}
// Find the most common contrast value
unsigned long long max_c = 0; // Max count of pixels with a specific contrast value
int max_i = -1; // Index (contrast value) of the histogram bin with max_c, init with an invalid value
#pragma omp parallel for private(i) schedule(dynamic)
for (i = 0; i < PIXEL_RANGE; ++i) {
if (max_c < global_histogram[i]) {
max_c = global_histogram[i];
max_i = i;
}
}