"Introduction to High Performance Computing for Scientists and Engineers" is the book !!
sched_setaffinity 讓你把 thread 跑在指定的 cpu core 上 , 但是 ,
你只知道 你的主機有兩個 socket 各有四個 core , 但是 你不知道 cpu0 ~ cpu7 ,
那四個是 socket1 , 那四個是 socket2 , 不知道的話, 怎麼使用 sched_setaffinity ?
使用 likwid 這個 tool , 安裝之後執行 : ./likwid-topology -g 產生以下的 output :
-------------------------------------------------------------
CPU type: Intel Core Westmere processor
*************************************************************
Hardware Thread Topology
*************************************************************
Sockets: 1
Cores per socket: 2
Threads per core: 2
-------------------------------------------------------------
HWThread Thread Core Socket
0 0 0 0
1 0 2 0
2 1 0 0
3 1 2 0
-------------------------------------------------------------
Socket 0: ( 0 2 1 3 )
-------------------------------------------------------------
*************************************************************
Cache Topology
*************************************************************
Level: 1
Size: 32 kB
Cache groups: ( 0 2 ) ( 1 3 )
-------------------------------------------------------------
Level: 2
Size: 256 kB
Cache groups: ( 0 2 ) ( 1 3 )
-------------------------------------------------------------
Level: 3
Size: 4 MB
Cache groups: ( 0 2 1 3 )
-------------------------------------------------------------
*************************************************************
NUMA Topology
*************************************************************
NUMA domains: 1
-------------------------------------------------------------
Domain 0:
Processors: 0 1 2 3
Relative distance to nodes: 10
Memory: 1123.29 MB free of total 3919 MB
-------------------------------------------------------------
*************************************************************
Graphical:
*************************************************************
Socket 0:
+---------------------+
| +-------+ +-------+ |
| | 0 2 | | 1 3 | |
| +-------+ +-------+ |
| +-------+ +-------+ |
| | 32kB | | 32kB | |
| +-------+ +-------+ |
| +-------+ +-------+ |
| | 256kB | | 256kB | |
| +-------+ +-------+ |
| +-----------------+ |
| | 4MB | |
| +-----------------+ |
+---------------------+
非常明顯 , core0 and core2 share L1,L2 cache , core1 and core3 share L1,L2 cache,
and core0 to core3 share L3 cache ....其實這顆 cpu 只有兩個 cores , 但是因為它有
hyperthreading , 所以 OS 眼光來看 就是 4 cores !! 至於 NUMA , 就是把主機分 group ,
每個 group 有 cpu and main memory , group 之間使用 bus 連接 , 要注意同 group 之間
運算快 , 不同 group 之間資料交換那就慢了 , 我手上沒有 NUMA 架構的主機 , 無法測試 !!
留言列表