Skip to content

Commit

Permalink
Add prefix to thread names, and additionally label worker threads wit…
Browse files Browse the repository at this point in the history
…h id
  • Loading branch information
Markus Wippler committed Mar 8, 2022
1 parent 3fa4ef8 commit 6218de3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions include/host_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ namespace detail {

host_queue() {
// TODO what is a good thread count for the non-collective thread pool?
threads.emplace(std::piecewise_construct, std::tuple{0}, std::tuple{MPI_COMM_NULL, 4});
threads.emplace(std::piecewise_construct, std::tuple{0}, std::tuple{MPI_COMM_NULL, 4, id++});
}

void require_collective_group(collective_group_id cgid) {
if(threads.find(cgid) != threads.end()) return;
assert(cgid != 0);
MPI_Comm comm;
MPI_Comm_dup(MPI_COMM_WORLD, &comm);
threads.emplace(std::piecewise_construct, std::tuple{cgid}, std::tuple{comm, 1});
threads.emplace(std::piecewise_construct, std::tuple{cgid}, std::tuple{comm, 1, id++});
}

template <typename Fn>
Expand Down Expand Up @@ -160,15 +160,16 @@ namespace detail {
MPI_Comm comm;
ctpl::thread_pool thread;

comm_thread(MPI_Comm comm, size_t n_threads) : comm(comm), thread(n_threads) {
comm_thread(MPI_Comm comm, size_t n_threads, size_t id) : comm(comm), thread(n_threads) {
for(size_t i = 0; i < n_threads; ++i) {
auto& worker = thread.get_thread(i);
set_thread_name(worker.native_handle(), "worker" + std::to_string(i));
set_thread_name(worker.native_handle(), fmt::format("cy-worker-{}.{}", id, i));
}
}
};

std::unordered_map<collective_group_id, comm_thread> threads;
size_t id = 0;
};

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion src/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace detail {

void executor::startup() {
exec_thrd = std::thread(&executor::run, this);
set_thread_name(exec_thrd.native_handle(), "executor");
set_thread_name(exec_thrd.native_handle(), "cy-executor");
}

void executor::shutdown() {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace detail {
is_active = true;
if(is_master_node()) { schdlr->startup(); }
exec->startup();
set_thread_name(get_current_thread_handle(), "main");
set_thread_name(get_current_thread_handle(), "cy-main");
}

void runtime::shutdown() noexcept {
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace detail {

void scheduler::startup() {
worker_thread = std::thread(&scheduler::schedule, this);
set_thread_name(worker_thread.native_handle(), "scheduler");
set_thread_name(worker_thread.native_handle(), "cy-scheduler");
}

void scheduler::shutdown() {
Expand Down
8 changes: 4 additions & 4 deletions test/runtime_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,18 +993,18 @@ namespace detail {

if(rt.is_master_node()) {
const auto scheduler_thread_name = get_thread_name(scheduler_testspy::get_worker_thread(schdlr).native_handle());
CHECK(scheduler_thread_name == "scheduler");
CHECK(scheduler_thread_name == "cy-scheduler");
}

const auto executor_thread_name = get_thread_name(executor_testspy::get_exec_thrd(exec).native_handle());
CHECK(executor_thread_name == "executor");
CHECK(executor_thread_name == "cy-executor");

const auto main_thread_name = get_thread_name(get_current_thread_handle());
CHECK(main_thread_name == "main");
CHECK(main_thread_name == "cy-main");

q.submit([](handler& cgh) {
cgh.host_task(experimental::collective, [&](experimental::collective_partition) {
const auto base_name = std::string("worker");
const auto base_name = std::string("cy-worker-");
const auto worker_thread_name = get_thread_name(get_current_thread_handle());
CHECK_THAT(worker_thread_name, Catch::Matchers::StartsWith(base_name));
});
Expand Down

0 comments on commit 6218de3

Please sign in to comment.