-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtpin.cpp
66 lines (56 loc) · 1.48 KB
/
tpin.cpp
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
#include <cstdio>
#include <omp.h>
#include <sched.h>
#include <string>
#include <thread>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
int nthreads_per_core = THREADS_PER_CORE;
int ndomains = NUMA_DOMAINS;
int ncores = thread::hardware_concurrency() / nthreads_per_core;
int ncores_per_domain = ncores / ndomains;
vector<vector<int>> pin_counter(ndomains, vector<int>(ncores_per_domain, 0));
#pragma omp parallel
{
int tid = omp_get_thread_num();
int cpu = sched_getcpu();
int n = omp_get_num_threads();
int sock = cpu % ndomains;
int core = (cpu / ndomains) % ncores_per_domain;
int hw_thread_idx = cpu / ncores;
#pragma omp atomic
pin_counter[sock][core]++;
string graphical = "";
for (int j = 0; j < ndomains; j++) {
string s(ncores_per_domain, '-');
if (j == sock) {
s[core] = '0' + hw_thread_idx;
}
graphical += "[" + s + "] ";
}
#pragma omp for ordered
for (int i = 0; i < n; i++) {
#pragma omp ordered
if (tid == i) {
printf("%3i on %3i %s\n", tid, cpu, graphical.c_str());
}
}
}
string pinned = "";
for (int i = 0; i < ndomains; i++) {
string tmp = "";
for (auto c : pin_counter[i]) {
if (c == 0) {
tmp += "-";
} else if (c < 10) {
tmp += to_string(c);
} else {
tmp += "#";
}
}
pinned += "[" + tmp + "] ";
}
printf(" counts %s\n", pinned.c_str());
return 0;
}