示例#1
0
	Waifu2xImpl()
		: m_impl()
		, m_num_steps(0)
		, m_num_threads(get_max_threads())
		, m_block_width(DEFAULT_BLOCK_WIDTH)
		, m_block_height(DEFAULT_BLOCK_HEIGHT)
	{ }
示例#2
0
	explicit Waifu2xImpl(const std::string &model_json)
		: m_impl()
		, m_num_steps(0)
		, m_num_threads(get_max_threads())
		, m_block_width(DEFAULT_BLOCK_WIDTH)
		, m_block_height(DEFAULT_BLOCK_HEIGHT)
	{
		load_model(model_json);
	}
示例#3
0
void submit_job(JOB_CRUNCHER f, void *data)
{
set_concurrency(get_max_threads());

thread_mutex_lock(&jobs_mutex);
if(jobs_free>=jobs_size)expand_jobs();
jobs_submitted++;
job[jobs_free].data=data;
job[jobs_free].job=f;
jobs_free++;
thread_cond_broadcast(&wait_for_more_jobs_condition);
thread_mutex_unlock(&jobs_mutex);
}
示例#4
0
文件: TASReso.cpp 项目: t-weber/takin
/**
 * generates MC neutrons using available threads
 */
Ellipsoid4d<t_real> TASReso::GenerateMC(std::size_t iNum, std::vector<t_vec>& vecNeutrons) const
{
	// use deferred version if threading is disabled
	//if(!m_bEnableThreads)
	//	return GenerateMC_deferred(iNum, vecNeutrons);


	// number of iterations over random sample positions
	std::size_t iIter = m_res.size();
	if(vecNeutrons.size() != iNum*iIter)
		vecNeutrons.resize(iNum*iIter);

	Ellipsoid4d<t_real> ell4dret;
	for(std::size_t iCurIter = 0; iCurIter<iIter; ++iCurIter)
	{
		const ResoResults& resores = m_res[iCurIter];

		Ellipsoid4d<t_real> ell4d = calc_res_ellipsoid4d<t_real>(
			resores.reso, resores.reso_v, resores.reso_s, resores.Q_avg);

		unsigned int iNumThreads = get_max_threads();
		std::size_t iNumPerThread = iNum / iNumThreads;
		std::size_t iRemaining = iNum % iNumThreads;

		tl::ThreadPool<void()> tp(iNumThreads);
		for(unsigned iThread=0; iThread<iNumThreads; ++iThread)
		{
			std::vector<t_vec>::iterator iterBegin = vecNeutrons.begin() + iNumPerThread*iThread + iCurIter*iNum;
			std::size_t iNumNeutr = iNumPerThread;
			if(iThread == iNumThreads-1)
				iNumNeutr = iNumPerThread + iRemaining;

			tp.AddTask([iterBegin, iNumNeutr, this, &ell4d]()
				{ mc_neutrons<t_vec>(ell4d, iNumNeutr, this->m_opts, iterBegin); });
		}

		tp.StartTasks();

		auto& lstFut = tp.GetFutures();
		for(auto& fut : lstFut)
			fut.get();

		if(iCurIter == 0)
			ell4dret = ell4d;
	}

	//mc_neutrons<t_vec>(ell4d, iNum, m_opts, vecNeutrons.begin());
	return ell4dret;
}
示例#5
0
/* blocks until scan is finished, even if scan is multi-threaded */
void a6o_on_demand_run(struct a6o_on_demand *on_demand)
{
	struct os_file_stat stat_buf;
	int stat_errno;

	a6o_log(ARMADITO_LOG_LIB, ARMADITO_LOG_LEVEL_INFO, "starting %sthreaded scan of %s",
		on_demand->flags & ARMADITO_SCAN_THREADED ? "" : "non-",
		on_demand->root_path);

	/* create the thread pool now */
	if (on_demand->flags & ARMADITO_SCAN_THREADED)
		on_demand->thread_pool = g_thread_pool_new(scan_entry_thread_fun, on_demand, get_max_threads(), FALSE, NULL);

	/* what is scan root_path? a file or a directory? */
	os_file_stat(on_demand->root_path, &stat_buf, &stat_errno);

	/* it is a file, scan it, in a thread if scan is threaded */
	/* otherwise, walk through the directory and apply 'scan_entry' function to each entry (either file or directory) */
	if (stat_buf.flags & FILE_FLAG_IS_PLAIN_FILE) {
		on_demand->scan->to_scan_count = 1;
		if (on_demand->flags & ARMADITO_SCAN_THREADED)
			g_thread_pool_push(on_demand->thread_pool, (gpointer)os_strdup(on_demand->root_path), NULL);
		else
			scan_file(on_demand, on_demand->root_path);
	} else if (stat_buf.flags & FILE_FLAG_IS_DIRECTORY) {
		int recurse = on_demand->flags & ARMADITO_SCAN_RECURSE;

		count_to_scan(on_demand);
		os_dir_map(on_demand->root_path, recurse, scan_entry, on_demand);
	}

	/* if threaded, free the thread_pool */
	/* this has a side effect to wait for completion of *all* the scans queue'd in the thread pool */
	if (on_demand->flags & ARMADITO_SCAN_THREADED)
		g_thread_pool_free(on_demand->thread_pool, FALSE, TRUE);

	/* send the final progress (100%) */
	final_progress(on_demand->scan);

	if (on_demand->count_thread != NULL)
		g_thread_join(on_demand->count_thread);
}
示例#6
0
void AudioIn::getFFTdata()
{
    if(this->data.frameIndex == 0)
        this->getAudioData();
    fftwpp::fftw::maxthreads=get_max_threads();
    unsigned int n=pow(2,17);
    unsigned int np=n/2+1;
    size_t align=sizeof(Complex);
    qDebug() << "Now aquiring the FFTW, building up the arrays for " << numSamples << " data!";
    Array::array1<Complex> F(np,align);
    Array::array1<double> f(n,align);               // For out-of-place transforms
    //  array1<double> f(2*np,(double *) F()); // For in-place transforms

    fftwpp::rcfft1d Forward(n,f,F);
    fftwpp::crfft1d Backward(n,F,f);
    qDebug() << "Applying filtering";
    this->applyHanningWindow();

    QVector<double> Amplitude;

    qDebug() << "Putting " << numSamples << " into an array!";
    for(unsigned int i = 0; i < n; i++)
        f[i] = this->data.recordedSamples[i];

    qDebug() << "input:\n" << f[0] << '\n';

    Forward.fft(f,F);

    qDebug() << "output:\n" << F[0].real() << ", " << F[0].imag() << '\n';

    for(unsigned int i = 0; i < np; i++)
        Amplitude.append(F[i].real()*F[i].real()+F[i].imag()*F[i].imag());
    emit this->currentSound(Amplitude);
    if(this->data.recordedSamples != NULL)
        memset(this->data.recordedSamples, 0, this->numBytes);
    this->data.frameIndex = 0;
}