openmp_getmax.c 603 字节
Newer Older
B
Ben 已提交
1 2
/* See compilation notes in atomic_factors.c, openmp_atoms.c, or pthread_factors.c*/

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
int get_max(int *array, long int max){
    int thread_ct = omp_get_max_threads();
    int maxes[thread_ct];
    memset(maxes, 0, sizeof(int)*thread_ct);

    #pragma omp parallel for
    for (long int i=0; i< max; i++){
        int this_thread = omp_get_thread_num();
        if (array[i] > maxes[this_thread])
            maxes[this_thread] = array[i];
    }

    int global_max=0;
    for (int i=0; i< thread_ct; i++)
        if (maxes[i] > global_max)
            global_max = maxes[i];
    return global_max;
}