Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Should VSL Leap Frog work with Wichmann Hill?

$
0
0

I tried vslLeapfrogStream and compared the numbers produced with a simple block of randoms.

This worked for the congruential generators MCG31 and 59, but it did not put the numbers in the right places with WH.

If it is not supported, I expected a non-zero status from calling the vslLeapfrogStream method, but it was zero.

My guess is that WH shouldn't be supported and the status is wrong.

This is what I did...

the assert(fabs(a - b) < 1e-12); fails, suggesting inconsistent values.

It works if I change the gen to an MCG near the top.

This is with compiler version 16.0 x64 in VS2015 / Windows 10.

int main()
{
	constexpr int nFrogs = 7;
	constexpr int nSims = 101;
	VSLStreamStatePtr streams[nFrogs];

	int gen = VSL_BRNG_WH;
	int seed = 1234567890;

	// Creating first stream
	int status = vslNewStream(&streams[0], gen, seed);
	assert(status == 0);

	// Copy first stream to others
	for (int i = 1; i < nFrogs; ++i)
	{
		status = vslCopyStream(&streams[i], streams[0]);
		assert(status == 0);
	}

	// Leapfrogging the streams
	for (int i = 0; i < nFrogs; ++i)
	{
		status = vslLeapfrogStream(streams[i], i, nFrogs);
		assert(status == 0); // Unacceptable generator gives status -1002
	}

	// Generating base case random numbers without leap frog for comparison
	// Same generator and seed
	VSLStreamStatePtr baseStream;
	status = vslNewStream(&baseStream, gen, seed);
	assert(status == 0);
	double y[nSims*nFrogs];
	status = vdRngUniform(VSL_RNG_METHOD_UNIFORM_STD, baseStream, nSims*nFrogs, y, 0.0, 1.0);
	assert(status == 0);

	// Generate randoms for each of the leapfrog streams and compare output
	double x[nSims];
	for (int i = 1; i < nFrogs; ++i)
	{
		status = vdRngUniform(VSL_RNG_METHOD_UNIFORM_STD, streams[i], nSims, x, 0.0, 1.0);
		assert(status == 0);
		for (int j = 0; j < nSims; ++j)
		{
			double a = x[j];
			double b = y[j*nFrogs + i];
			assert(fabs(a - b) < 1e-12);
		}

	}

	// Deleting the streams
	for (int i = 1; i < nFrogs; ++i)
	{
		status = vslDeleteStream(&streams[i]);
		assert(status == 0);
	}

	vslDeleteStream(&baseStream);
}

 

 

Thread Topic: 

Bug Report

Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>