在一个更大的程序中,我写了这段代码:
static void search_minmax(int *min_out, int *max_out,
const int data[], const size_t stride, const size_t n) {
/* finds the smallest and largest members of a dataset */
int min = data[0 * stride];
int max = data[0 * stride];
size_t i;
#pragma omp parallel for num_threads(NUM_THREADS) schedule(static) reduction(max:max) reduction(min:min)
for (i = 0; i < n; i++) {
int xi = data[i * stride];
if (xi < min)
min = xi;
if (xi > max)
max = xi;
}
*min_out = min;
*max_out = max;
}
首先看它我觉得它有效,但事实上,在我的程序中,这个算法减慢了作用。我看不出错误。有人可以帮我指出来吗?