I have this C++ code.
Loop goes throgh the matrix, finds the min element in each row and subtracts it from each element of corresponding row. Variable myr is a summ of all min elements
Trying to parallel for:
int min = 0; int myr = 0; int temp[SIZE][SIZE]; int size = 0; ...//some initialization omp_set_num_threads(1); start_time = omp_get_wtime(); #ifdef _OPENMP #pragma omp parallel for firstprivate(min, size) reduction(+:myr) #endif for(int i = 0; i < size; i++){ min = INFINITY; for(int j = 0; j < size; j++){ if (temp[i][j] < min) min = temp[i][j]; } myr+=min; for(int j = 0; j < size; j++) temp[i][j]-=min; } end_time = omp_get_wtime(); if I set omp_set_num_threads(2); this part of code starts working slower.
My proc has 2 cores
Why code works slower with 2 threads?