Skip to content

Commit 05398d5

Browse files
committed
Allow verbose output for thread affinity debugging
1 parent a93b107 commit 05398d5

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

BUILD.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
::
2+
(rm -rf build && mkdir build && cd build && env PATH="$HOME/src/spack-view/bin:$PATH" cmake -G Ninja -DCMAKE_CXX_COMPILER="$HOME/src/spack-view/bin/g++" -DCMAKE_CXX_FLAGS="-march=native" -DCMAKE_FIND_ROOT_PATH="$HOME/spack-view" -DGTEST_ROOT="$HOME/src/spack-view" ..)
3+
pushd build
4+
ninja
5+
ninja hello && env FUNHPC_NUM_NODES=1 FUNHPC_NUM_PROCS=1 FUNHPC_NUM_THREADS=8 QTHREAD_NUM_SHEPHERDS=1 QTHREAD_NUM_WORKERS_PER_SHEPHERD=8 $HOME/src/spack-view/bin/mpirun -np 1 ./hello
6+
popd

funhpc/hwloc.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ struct thread_layout {
6565
node_thread = node_proc * proc_nthreads + proc_thread;
6666
node_nthreads = node_nprocs * proc_nthreads;
6767

68+
const bool verbose = cxx::envtol("FUNHPC_VERBOSE", "0");
69+
if (verbose)
70+
if (proc == 0 && proc_thread == 0) {
71+
std::ostringstream os;
72+
os << "FunHPC thread layout:\n";
73+
os << " proc: " << proc << " / " << nprocs << "\n";
74+
os << " node_proc: " << node_proc << " / " << node_nprocs << "\n";
75+
os << " node: " << node << " / " << nnodes << "\n";
76+
os << " proc_thread: " << proc_thread << " / " << proc_nthreads
77+
<< "\n";
78+
os << " node_thread: " << node_thread << " / " << node_nthreads
79+
<< "\n";
80+
std::cout << os.str() << std::flush;
81+
}
82+
6883
assert(invariant());
6984
}
7085
};
@@ -96,8 +111,24 @@ struct thread_affinity {
96111
oversubscribing
97112
? cxx::div_floor(tl.node_thread * node_npus, tl.node_nthreads).quot
98113
: cxx::div_exact(tl.node_thread * node_npus, tl.node_nthreads).quot;
99-
assert(thread_pu + thread_npus <= node_npus);
100114

115+
const bool verbose = cxx::envtol("FUNHPC_VERBOSE", "0");
116+
if (verbose)
117+
if (tl.proc == 0 && tl.proc_thread == 0) {
118+
std::ostringstream os;
119+
os << "FunHPC thread affinity:\n";
120+
os << " node_npus: " << node_npus << "\n";
121+
os << " undersubscribing: " << undersubscribing << "\n";
122+
os << " oversubscribing: " << oversubscribing << "\n";
123+
os << " thread_pu: " << thread_pu << " / " << thread_npus << "\n";
124+
std::cout << os.str() << std::flush;
125+
}
126+
127+
if (!oversubscribing) {
128+
assert(cxx::div_floor(node_npus, tl.node_nthreads).rem == 0);
129+
assert(cxx::div_floor(tl.node_thread * node_npus, tl.node_nthreads).rem ==
130+
0);
131+
}
101132
assert(invariant());
102133
}
103134
};

0 commit comments

Comments
 (0)