c - detemine socket/processor of running thread -


i writing numa aware cache large objects (matrices of doubles) 4 socket server. observe intersocket communication bottleneck application. hence, want threads on different sockets have separate matrix caches. have bounded threads specific physical processors , need make threads select correct cache.

suppose cache defined in following way:

matrix_cache_t *cache[sockets_limit]; 

i need each thread know socket id , select correct cache, e.g. cache[0], cache[1], cache[2] or cache[3].

i writing application in c using openmp , suppose run on both windows , linux.

thank you

this partial response.

under windows can use getlogicalprocessorinformationex() api using either relationnumanode or relationprocessorpackage relation. gives bits of processors in respective relationship, correspond affinity bits used tie thread processor.

under linux can use sched_getcpu

#include <stdio.h> #include <sched.h>  int sched_getcpu();  int main() {     (void) printf("cpu %d\n", sched_getcpu()); } 

socket id can found in /proc/cpuinfo or /sys/devices/system/cpu/cpu0/topology/physical_package_id


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -