Beispiel #1
0
CmdOptions parseOptions(int argc, char* argv[])
{
  CmdOptions opts;
  vector<maxint_t> numbers;

  for (int i = 1; i < argc; i++)
  {
    Option opt = makeOption(argv[i]);

    switch (optionMap[opt.opt])
    {
      case OPTION_ALPHA:   set_alpha(stod(opt.val)); break;
      case OPTION_NUMBER:  numbers.push_back(opt.to<maxint_t>()); break;
      case OPTION_THREADS: set_num_threads(opt.to<int>()); break;
      case OPTION_PHI:     opts.a = opt.to<int64_t>(); opts.option = OPTION_PHI; break;
      case OPTION_HELP:    help(); break;
      case OPTION_STATUS:  optionStatus(opt, opts); break;
      case OPTION_TIME:    opts.time = true; break;
      case OPTION_TEST:    test(); break;
      case OPTION_VERSION: version(); break;
      default:             opts.option = optionMap[opt.opt];
    }
  }

  if (numbers.empty())
    throw primecount_error("missing x number");
  else
    opts.x = numbers[0];

  return opts;
}
Beispiel #2
0
//=============================================================================
void Multiplexer::close()
{
  // Wait for any outstanding jobs to finish, no more will be allocated as the
  // spin() loop has terminated.
  m_job_mutex.lock();
  while (!m_threads_busy.empty()) { 
    DEBUG_LOG("Waiting for " << m_threads_busy.size() << " job(s) to finish");
    m_job_condition.wait(m_job_mutex);
  }
  m_job_mutex.unlock();

  // Stop and remove all threads
  set_num_threads(0);
  DEBUG_ASSERT(m_threads_pool.empty(),"Thread pool is not empty");

  // Delete jobs
  JobList::iterator it;
  for (it = m_jobs.begin(); it != m_jobs.end(); ++it) {
    delete (*it);
  }
  m_jobs.clear();

  // Delete any new jobs
  for (it = m_jobs_new.begin(); it != m_jobs_new.end(); ++it) {
    delete (*it);
  }
  m_jobs_new.clear();
}
Beispiel #3
0
 ThreadPool::ThreadPool(size_t num):
 m_impl(new Impl)
 {
     set_num_threads(num);
 }
		void stop() { set_num_threads(0, true); }
Beispiel #5
0
W2X_EXPORT int w2x_set_num_threads(W2xHandle handle, int num_threads){
	if(!handle){ return -1; }
	auto ptr = reinterpret_cast<waifu2x::Waifu2xImpl *>(handle);
	ptr->set_num_threads(num_threads);
	return 0;
}