void MPIComm::ThreadFunc(int device){ #ifndef CPU_ONLY //LOG(ERROR)<<"device_id is "<<device; CUDA_CHECK(cudaSetDevice(device)); #endif started_.store(true); MPIJob job; while (true){ mutex::scoped_lock lock(queue_mutex_); while( task_queue_.empty() && IsRunning()){ DLOG(INFO)<<"no job running, waiting on cond"; cond_work_.wait(lock); } lock.unlock(); DLOG(INFO)<<"Cond fulfilled, dispatching job"; if (IsRunning()){ job = task_queue_.front(); DLOG(INFO)<<task_queue_.size(); DispatchJob(job); mutex::scoped_lock pop_lock(queue_mutex_); task_queue_.pop(); pop_lock.unlock(); cond_finish_.notify_one(); DLOG(INFO)<<"job finished, poped taskqueue"; }else{ break; } } // finish remaining jobs while (!task_queue_.empty()){ boost::lock_guard<mutex> lock(queue_mutex_); job = task_queue_.front(); task_queue_.pop(); DispatchJob(job); } }
void LeaveCritical() { pop_lock(); }