Ejemplo n.º 1
0
/// Runs the benchmark minimizer
/// This simply runs n_iterations iterations as fast as possible, timing the result
/// and reporting it to the user.
void CBenchmark::run()
{
	// setup locals
	mIsRunning = true;
	int n_iterations = 1000;
	double chi2r = 0;
	double time = 0;

	int start = GetMilliCount();

	int iterations;
	for(iterations = 0; iterations < n_iterations && mRun; iterations++)
	{
		mWorkerThread->GetChi(&mChis[0], mChis.size());
		chi2r = ComputeChi2r(mChis, mNParams);

		if(iterations % 100 == 0)
			printf("Iteration %i Chi2r: %f\n", iterations, chi2r);
	}

	// Calculate the time, print out a nice message.
	time = double(GetMilliSpan(start)) / 1000;
	cout << "Benchmark Test completed!" << endl;
	cout << "Completed " << iterations << " iterations in " << time << " seconds." << endl;
	cout << "Throughput: " << iterations/time << " iterations/second." << endl;

	mIsRunning = false;
}
Ejemplo n.º 2
0
double CNLopt::ErrorFunc(unsigned int nParams, const double* params, double* grad, void * misc)
{
	// Get the "this" pointer
        CNLopt * minimizer = reinterpret_cast<CNLopt*>(misc);
	minimizer->mEvals++;
	// See if we have been requested to exit
	if(!minimizer->mRun)
	{
	  nlopt_force_stop(minimizer->mOpt);
	}

	// Set the free parameters to the current nominal values determined by the minimizer
	CModelListPtr model_list = minimizer->mWorkerThread->GetModelList();
	model_list->SetFreeParameters(params, nParams, false);

	minimizer->mWorkerThread->GetChi(&minimizer->mChis[0], minimizer->mChis.size());
	return ComputeChi2r(minimizer->mChis, minimizer->mNParams);
}