How big is n?
OpenMP parallel for . GOMP ( OpenMP, gcc), (dynamic,1) . , ( i-1 i+1) , , . . , :
#pragma omp parallel for schedule(dynamic,1024)
1024 . , ( , , "" ). , , , L1 L2 .
, for , .
#pragma omp parallel for schedule(static)
, .
, OpenMP . , GOMP_CPU_AFFINITY.
Edit:
, gcc 4.2.1, , . , GOMP schedule(static).
#include <stdio.h>
#include <omp.h>
int main(int argc, char** argv)
{
int i;
#pragma omp parallel for
for (i=0; i<15; i++) {
int id = omp_get_thread_num();
printf("%d assigned to thread %d\n", i, id);
}
}
:
$ ./test_sched | sort -n
0 assigned to thread 0
1 assigned to thread 0
2 assigned to thread 0
3 assigned to thread 0
4 assigned to thread 0
5 assigned to thread 0
6 assigned to thread 0
7 assigned to thread 0
8 assigned to thread 1
9 assigned to thread 1
10 assigned to thread 1
11 assigned to thread 1
12 assigned to thread 1
13 assigned to thread 1
14 assigned to thread 1