예제 #1
0
void AbstractCoreBoundTaskQueue::launchThread(int core) {
    //get the number of cores on system
    int NUM_PROCS = getNumberOfCoresOnSystem();

    if (core < NUM_PROCS) {
        _thread = new std::thread(&AbstractTaskQueue::executeTask, this);
        hwloc_cpuset_t cpuset;
        hwloc_obj_t obj;
        hwloc_topology_t topology = getHWTopology();

        obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, core);
        // the bitmap to modify
        cpuset = hwloc_bitmap_dup(obj->cpuset);
        // remove hyperthreads
        hwloc_bitmap_singlify(cpuset);
        // bind
        if (hwloc_set_thread_cpubind(topology, _thread->native_handle(), cpuset, HWLOC_CPUBIND_STRICT | HWLOC_CPUBIND_NOMEMBIND)) {
            char *str;
            int error = errno;
            hwloc_bitmap_asprintf(&str, obj->cpuset);
            fprintf(stderr, "Couldn't bind to cpuset %s: %s\n", str, strerror(error));
            fprintf(stderr, "Continuing as normal, however, no guarantees\n");
            //throw std::runtime_error(strerror(error));
        }

        hwloc_bitmap_free(cpuset);

    } else {
        // this case should never happen, as TaskQueue is only initialized from SimpleTaskScheduler, which captures this case
        throw std::logic_error("CPU to run thread on is larger than number of total cores; seems that TaskQueue was initialized outside of SimpleTaskScheduler, which should not happen");
    }
}
예제 #2
0
// get number of cores on system and compare to sum of cores fopr each node
TEST_F(HwLocHelperTest, number_of_nodes){
  int cores = getNumberOfCoresOnSystem();
  int cores2 = 0;
  unsigned nodes = hwloc_get_nbobjs_by_type(getHWTopology(), HWLOC_OBJ_NODE);
  if (nodes) {
    for(unsigned i = 0; i < nodes; i++){
      cores2 += getCoresForNode(getHWTopology(), i).size();
    }
    EXPECT_EQ(cores2, cores);
  }
}
WSCoreBoundPriorityQueuesScheduler::WSCoreBoundPriorityQueuesScheduler(const int queues) : AbstractCoreBoundQueuesScheduler(){
  _status = START_UP;
  // set _queues to queues after new queues have been created to new tasks to be assigned to new queues
  // lock _queue mutex as queues are manipulated
  {
    std::lock_guard<lock_t> lk(_queuesMutex);
    if (queues <= getNumberOfCoresOnSystem()) {
      for (int i = 0; i < queues; ++i) {
        _taskQueues.push_back(createTaskQueue(i));
      }
      _queues = queues;
    } else {
      LOG4CXX_WARN(_logger, "number of queues exceeds available cores; set it to max available cores, which equals to " << std::to_string(getNumberOfCoresOnSystem()));
      for (int i = 0; i < getNumberOfCoresOnSystem(); ++i) {
        _taskQueues.push_back(createTaskQueue(i));
      }
      _queues = getNumberOfCoresOnSystem();
    }
  }
  for (unsigned i = 0; i < _taskQueues.size(); ++i) {
    static_cast<WSCoreBoundPriorityQueue *>(_taskQueues[i])->refreshQueues();
  }
  _status = RUN;
}