MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / set_thread_affinity

Function set_thread_affinity

src/thread_pool.cc:79–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77
78
79 static void set_thread_affinity(std::thread& thread, int index) {
80#if !defined(__linux__) || defined(_OPENMP)
81 (void)thread;
82 (void)index;
83 throw std::runtime_error("Setting thread affinity is only supported in Linux binaries built "
84 "with -DOPENMP_RUNTIME=NONE");
85#else
86 cpu_set_t cpuset;
87 CPU_ZERO(&cpuset);
88 CPU_SET(index, &cpuset);
89 const int status = pthread_setaffinity_np(thread.native_handle(), sizeof (cpu_set_t), &cpuset);
90 if (status != 0) {
91 throw std::runtime_error("Error calling pthread_setaffinity_np: "
92 + std::to_string(status));
93 }
94#endif
95 }
96
97 static thread_local Worker* local_worker = nullptr;
98

Callers 1

startMethod · 0.85

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected