-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtbindings.nim
133 lines (126 loc) · 4.66 KB
/
tbindings.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import base
import hwloc/capi
import strutils
template ifSuccess(run,cont:untyped):untyped =
block:
let err = run
if err < 0:
echo "HWLOC error: ",err," <- ",astToStr(run)
stdout.flushFile
else:
cont
qexInit()
var c = getDefaultComm()
echo "rank ",myRank,"/",nRanks
threads: echo "thread ",threadNum,"/",numThreads
echo "hwloc compile-time API version: 0x", toHex(HWLOC_API_VERSION.int,8)
echo "hwloc run-time API version: 0x", toHex(hwloc_get_api_version().int,8)
const buflen = 64
var
topology:hwloc_topology_t
rootobj:hwloc_obj_t
policy:hwloc_membind_policy_t
ifSuccess hwloc_topology_init(topology.addr):
defer: hwloc_topology_destroy(topology)
ifSuccess hwloc_topology_load(topology):
var set = hwloc_bitmap_alloc()
defer: hwloc_bitmap_free(set)
#let cset_cpu = hwloc_topology_get_topology_cpuset(topology)
let topodepth = hwloc_topology_get_depth(topology)
echo "topology depth: ", topodepth
let n0 = hwloc_get_nbobjs_by_depth(topology, 0)
echo "nbobjs at depth 0: ", n0
rootobj = hwloc_get_obj_by_depth(topology, 0, 0)
let cset_cpu = hwloc_bitmap_dup(rootobj.cpuset);
ifSuccess hwloc_get_cpubind(topology, set, HWLOC_CPUBIND_PROCESS.cint):
var buffer = newStringOfCap buflen
buffer.setlen buflen
ifSuccess hwloc_bitmap_snprintf(cstring buffer, buflen, set):
var
ncur = hwloc_bitmap_weight(set)
ntot = hwloc_bitmap_weight(cset_cpu)
if myRank > 0:
c.pushSend(0, buffer.cstring, buflen)
c.pushSend(0, ncur.addr, sizeof ncur)
c.pushSend(0, ntot.addr, sizeof ntot)
c.waitSends
else:
for r in 0..<nRanks:
if r > 0:
c.pushRecv(r, buffer.cstring, buflen)
c.pushRecv(r, ncur.addr, sizeof ncur)
c.pushRecv(r, ntot.addr, sizeof ntot)
c.waitRecvs
echo "rank ",r," binds to cpuset ",buffer.cstring," using ",ncur," of ",ntot
threads:
var set = hwloc_bitmap_alloc()
defer: hwloc_bitmap_free(set)
var buffer = newStringOfCap buflen
buffer.setlen buflen
ifSuccess hwloc_get_cpubind(topology, set, HWLOC_CPUBIND_THREAD.cint):
ifSuccess hwloc_bitmap_snprintf(cstring buffer, buflen, set):
var
ncur = hwloc_bitmap_weight(set)
nth = numThreads
tid = threadNum
if myRank > 0:
threadMaster:
c.pushSend(0, nth.addr, sizeof nth)
c.waitSends
threadBarrier()
threadCritical:
c.pushSend(0, buffer.cstring, buflen)
c.pushSend(0, ncur.addr, sizeof ncur)
c.pushSend(0, tid.addr, sizeof tid)
c.waitSends
else:
threadCritical:
echoRaw "rank ",myRank," thread ",tid," binds to cpuset ",buffer.cstring," using ",ncur
stdout.flushFile
threadBarrier()
threadMaster:
for r in 1..<nRanks:
c.pushRecv(r, nth.addr, sizeof nth)
c.waitRecvs
for t in 0..<nth:
c.pushRecv(r, buffer.cstring, buflen)
c.pushRecv(r, ncur.addr, sizeof ncur)
c.pushRecv(r, tid.addr, sizeof tid)
c.waitRecvs
echoRaw "rank ",r," thread ",tid," binds to cpuset ",buffer.cstring," using ",ncur
stdout.flushFile
#let cset = hwloc_topology_get_topology_nodeset(topology)
let cset = rootobj.nodeset
var set = hwloc_bitmap_alloc()
defer: hwloc_bitmap_free(set)
ifSuccess hwloc_get_membind(topology, set, policy.addr, HWLOC_MEMBIND_BYNODESET.cint):
if myRank > 0:
c.pushSend(0, policy.addr, sizeof policy)
c.waitSends
else:
for r in 0..<nRanks:
if r > 0:
c.pushRecv(r, policy.addr, sizeof policy)
c.waitRecvs
echo "rank ",r," membind policy: ",policy
var buffer = newStringOfCap buflen
buffer.setlen buflen
ifSuccess hwloc_bitmap_snprintf(cstring buffer, buflen, set):
var
ncur = hwloc_bitmap_weight(set)
ntot = hwloc_bitmap_weight(cset)
if myRank > 0:
c.pushSend(0, buffer.cstring, buflen)
c.pushSend(0, ncur.addr, sizeof ncur)
c.pushSend(0, ntot.addr, sizeof ntot)
c.waitSends
else:
for r in 0..<nRanks:
if r > 0:
c.pushRecv(r, buffer.cstring, buflen)
c.pushRecv(r, ncur.addr, sizeof ncur)
c.pushRecv(r, ntot.addr, sizeof ntot)
c.waitRecvs
echo "rank ",r," binds to numa node ",buffer.cstring," using ",ncur," of ",ntot
stdout.flushFile
qexFinalize()