inline void executeThreadWork() { job_type* job = NULL; m_numthrs = omp_get_num_threads(); m_timers.change(TM_WORK); m_logger.start(); m_work_logger.start(); while (true) { while (m_queue.try_pop(job)) { m_logger << m_queue.unsafe_size(); if (job->run(m_cookie)) delete job; } DBG(debug_queue, "Queue" << m_id << " is empty"); // no more jobs -> switch to idle m_timers.change(TM_IDLE); ++m_idle_count; m_logger << m_queue.unsafe_size(); m_work_logger << (m_numthrs - m_idle_count); while (!m_queue.try_pop(job)) { DBG(debug_queue, "Idle thread - m_idle_count: " << m_idle_count); if ( //!m_group->assist(m_id) && m_idle_count == m_numthrs) { // assist other JobQueues before terminating. while (m_group->assist(m_id)) { } return; } } // got a new job -> not idle anymore m_timers.change(TM_WORK); --m_idle_count; m_logger << m_queue.unsafe_size(); m_work_logger << (m_numthrs - m_idle_count); if (job->run(m_cookie)) delete job; } }
//! try to run one jobs from the queue, returns false if queue is finished, //! true if ran jobs or queue not finished. bool try_run() { job_type* job = NULL; if (!m_queue.try_pop(job)) return (m_idle_count != m_numthrs); m_logger << m_queue.unsafe_size(); if (job->run(m_cookie)) delete job; return true; }
void numaLoop(int numaNode, int numberOfThreads) { m_timers.start(omp_get_max_threads()); #pragma omp parallel num_threads(numberOfThreads) { // tie thread to a NUMA node numa_run_on_node(numaNode); numa_set_preferred(numaNode); executeThreadWork(); } // end omp parallel m_timers.stop(); assert(m_queue.unsafe_size() == 0); }
void loop() { m_timers.start(omp_get_max_threads()); m_idle_count = 0; #pragma omp parallel { if (gopt_memory_type == "mmap_node0") { // tie thread to first NUMA node numa_run_on_node(0); numa_set_preferred(0); } executeThreadWork(); } // end omp parallel m_timers.stop(); assert(m_queue.unsafe_size() == 0); }
void enqueue(job_type* job) { m_queue.push(job); m_logger << m_queue.unsafe_size(); }