KnotVector splineknots::CurveDeboorKnotsGenerator::
GenerateKnots(const SurfaceDimension& dimension, double* calculation_time)
{
	StopWatch sw;
	
	KnotVector knots(dimension.knot_count);
	InitializeKnots(dimension, knots);
	auto dfirst = function_.Dx()(dimension.min, 0);
	auto dlast = function_.Dx()(dimension.max, 0);
	KnotVector result(knots.size());

	sw.Start();
	RightSide(knots, abs(dimension.max - dimension.min)
		/ (dimension.knot_count - 1), dfirst, dlast);
	
	auto& rhs = tridiagonal_.Solve(dimension.knot_count-2);
	result[0] = dfirst;
	result[result.size() - 1] = dlast;
	memcpy(&result.front() + 1, &rhs.front(), rhs.size());
	sw.Stop();
	
	if (calculation_time != nullptr)
	{
		*calculation_time = sw.EllapsedTime();
	}
	return result;
}
Ejemplo n.º 2
0
void MulVsDiv::Loop()
{
	StopWatch sw;

	const int length = 256;
	const int loops = 1e7;
	std::cout << "Simple loop:\n---" << std::endl;
	double a[length], b[length], c[length];
	auto ignoreit = 0.0;

	ResetArrays(length, a, b, ignoreit);
	sw.Start();
	for (size_t l = 0; l < loops; l++)
	{
		// MSVC cannot vectorize this loop (message 1300).
		// However, if this loop will not be nested in, autovectorization will happen.
		// Same condition apply for mul/div/rcp loops

		// ICL does not have this issue, but to provide both vectorized and nonvectorized comparison 
		// i specifically disabled vectorization in this method
#pragma novector
#pragma loop( no_vector )
		for (int i = 0; i < length; ++i)
		{
			c[i] = a[i] + b[i];
		}
	}
	sw.Stop();
	auto add_time = sw.EllapsedTime();
	std::cout << "Addition: " << add_time << std::endl;
	ignoreit -= c[(rand() % static_cast<int>(length))];
	ResetArrays(length, a, b, ignoreit);

	sw.Start();
	for (size_t l = 0; l < loops; l++)
	{
#pragma novector
#pragma loop( no_vector )
		for (int i = 0; i < length; ++i)
		{
			c[i] = a[i] * b[i];
		}
	}
	sw.Stop();
	auto mul_time = sw.EllapsedTime();
	std::cout << "Multiplication: " << mul_time << std::endl;
	ignoreit -= c[(rand() % static_cast<int>(length))];
	ResetArrays(length, a, b, ignoreit);

	sw.Start();
	for (size_t l = 0; l < loops; l++)
	{
#pragma novector
#pragma loop( no_vector )
		for (int i = 0; i < length; ++i)
		{
			c[i] = a[i] / b[i];
		}
	}
	sw.Stop();
	auto div_time = sw.EllapsedTime();
	ignoreit -= c[(rand() % static_cast<int>(length))];
	ignoreit += a[(rand() % static_cast<int>(length))] + b[(rand() % static_cast<int>(length))];
	std::cout << "Division: " << div_time << std::endl;
	std::cout << "Addition faster than multiplication: " << static_cast<double>(mul_time) / static_cast<double>(add_time) << std::endl;
	std::cout << "Multiplication faster than division: " << static_cast<double>(div_time) / static_cast<double>(mul_time) << std::endl;
	std::cout << "Just ignore it: " << ignoreit << std::endl << std::endl;
}