Performance Issue
James Swaine
james.swaine at gmail.com
Tue Feb 24 12:20:36 EST 2009
i'm implementing a benchmark which includes a detailed specification for a
random number generator. for any of the kernels outlined in the benchmark,
i might have to generate a set of random numbers R, which has a length n,
using the following formulas:
R[k] = ((2^-46)(X[k])) mod 2^46, where
X[k] = (a^k)s
where the values of a and s are constant and defined below.
many of the kernels in the benchmark require a large number of randoms to be
generated (in the tens of millions). when i invoke the following getRandAt
function that many times to build up a list, evaluation of the list takes
forever (somewhere between 5 and 10 minutes). i've tried optimizing this
several different ways, with no luck. i though i might post my code here
and see if anyone notices anything i'm doing wrong that might be causing
such a large bottleneck:
--constants
a :: Int64
a = 5^13
divisor :: Int64
divisor = 2^46
multiplier :: Float
multiplier = 2**(-46)
--gets r[k], which is the value at the kth
--position in the overall sequence of
--pseudorandom numbers
getRandAt :: Int64 -> Int64 -> Float
getRandAt 0 seed = multiplier * (fromIntegral seed)
getRandAt k seed = multiplier * (fromIntegral x_next)
where
x_prev = (a^k * seed) `mod` divisor
x_next = (a * x_prev) `mod` divisor
thanks all in advance for your help!
-james
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20090224/3b80fbc5/attachment-0001.htm
More information about the Glasgow-haskell-users
mailing list