Commit 02e400ac authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

add affinity.


Former-commit-id: c8a5f35fc4f66fe2d023b713896c7c7f82ef25f3
parent 08693c54
......@@ -22,10 +22,10 @@
CC=gcc
FC=gfortran
OPTS=-DTIMER -DCOUNTER -DCPU_TPS=2.67e9 -DHAVE_ZLIB
OPTS=-DTIMER -DCOUNTER -DCPU_TPS=2.67e9 -DHAVE_ZLIB -DHAVE_SETAFFINITY -D_GNU_SOURCE
CFLAGS=-O3 -g -std=gnu99 -Wall -Werror -march=native -mtune=native -ffast-math -fomit-frame-pointer -malign-double -fstrict-aliasing -fopenmp
# CFLAGS=-O0 -g -std=gnu99 -Wall -Werror -fopenmp
LDFLAGS=-lm -lpthread -fopenmp -lz
LDFLAGS=-std=gnu99 -lm -lpthread -fopenmp -lz
FFLAGS=$(CFLAGS)
......
......@@ -27,6 +27,7 @@
#include <float.h>
#include <limits.h>
#include <omp.h>
#include <sched.h>
/* Local headers. */
#include "cycle.h"
......@@ -1582,6 +1583,9 @@ struct task *queue_gettask ( struct queue *q , int blocking , int keep ) {
void runner_init ( struct runner *r , struct space *s , int nr_threads , int nr_queues , int policy ) {
#if defined(HAVE_SETAFFINITY)
cpu_set_t cpuset;
#endif
int k, qid, nrq;
/* Store the values. */
......@@ -1647,6 +1651,15 @@ void runner_init ( struct runner *r , struct space *s , int nr_threads , int nr_
r->threads[k].r = r;
if ( pthread_create( &r->threads[k].thread , NULL , &runner_main , &r->threads[k] ) != 0 )
error( "Failed to create runner thread." );
#if defined(HAVE_SETAFFINITY)
/* Set the cpu mask to zero | r->id. */
CPU_ZERO( &cpuset );
CPU_SET( r->threads[k].id , &cpuset );
/* Apply this mask to the runner's pthread. */
if ( pthread_setaffinity_np( r->threads[k].thread , sizeof(cpu_set_t) , &cpuset ) != 0 )
error( "Failed to set thread affinity." );
#endif
}
/* Wait for the runner threads to be in place. */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment