40 #endif // ASAGI_NONUMA
51 if (pthread_key_create(&m_ptkey, 0L) != 0)
58 pthread_key_delete(m_ptkey);
76 masterThread = m_masterThreads[threadId()];
81 int cpu = sched_getcpu();
87 int domain = numa_node_of_cpu(cpu);
90 #endif // ASAGI_NONUMA
93 if (!m_syncThreads.startBarrier())
97 unsigned int threadId = m_syncThreads.waiting();
104 if (!detectNumaDomains)
108 if (m_masterThreads.size() <= threadId)
109 m_masterThreads.resize(threadId+1);
112 unsigned int domainId;
113 std::map<int, unsigned int>::const_iterator domIt
114 = m_domains.find(domain);
115 if (domIt == m_domains.end()) {
117 domainId = m_domains.size();
118 m_domains[domain] = domainId;
121 m_masterThreads[threadId] = masterThread =
true;
123 domainId = domIt->second;
126 masterThread =
false;
130 if (m_syncThreads.waiting() >= m_totalThreads-1)
131 m_initialized =
true;
134 if (!m_syncThreads.waitBarrier(m_totalThreads))
136 if (!m_syncThreads.endBarrier())
144 uintptr_t ids = (
static_cast<uintptr_t
>(threadId) <<
sizeof(
id_t)*8) | domainId;
146 if (pthread_setspecific(m_ptkey, reinterpret_cast<void*>(ids)) != 0)
161 unsigned int current = domainId();
166 if (!m_syncDomains.broadcast(comm, totalDomains(), current))
NumaComm * createComm() const
asagi::Grid::Error registerThread(bool &masterThread, bool detectNumaDomains=true)
Registers a thread and detects the NUMA domain for this thread.