前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
/* See compilation notes in atomic_factors.c, openmp_atoms.c, or pthread_factors.c*/
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; }