Pin benchmark threads to cores with likwid-pin
Pin benchmark threads to fixed cores with likwid-pin from LIKWID 5.4, so pthread and OpenMP workers stop migrating between runs and results stay repeatable.
Threads that the scheduler is free to move make a benchmark noisy: a worker lands on a busy core in one run and a quiet one in the next. likwid-pin from LIKWID 5.4 pins each thread of an unmodified binary to a core from a list you give it, by wrapping pthread_create.
OMP_NUM_THREADS=4 likwid-pin -c 0-3 ./stencil[pthread wrapper]
[pthread wrapper] MAIN -> 0
[pthread wrapper] PIN_MASK: 0->1 1->2 2->3
[pthread wrapper] SKIP MASK: 0x0
threadid 140190228739840 -> core 1 - OK
threadid 140190220347136 -> core 2 - OK
threadid 140190211954432 -> core 3 - OKThe main thread goes to the first core in the list, and each thread created afterwards takes the next one. The thread ids differ on every run. Runtimes that start helper threads that do no work, such as the Intel OpenMP runtime, need a skip mask like -s 0x1, or the helper steals a core from a real worker. The -c list uses physical processor ids, as the likwid-pin page explains. It does not work on statically linked binaries, because the wrapper is injected with LD_PRELOAD.