<div dir="ltr">Max,<div>Remarkable, thanks! I surely agree that in binary, doubling is fast. So you sort of bypass computing low powers, with an ancient method (?!) of computing high powers efficiently. Very cool. So, everything is parallelizable :-)<div>
Peter</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 21, 2013 at 3:22 PM, Max R. Dechantsreiter <span dir="ltr"><<a href="mailto:max@performancejones.com" target="_blank">max@performancejones.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Peter,<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
That's interesting, where can I read about "giant-stepping the generator"?<br>
The wiki article<br>
<a href="http://en.wikipedia.org/wiki/Linear_congruential_generator" target="_blank">http://en.wikipedia.org/wiki/<u></u>Linear_congruential_generator</a> doesn't<br>
mention distributed processing.<br>
</blockquote>
<br></div>
The term "giant-stepping" may not be in general use....<br>
The idea is to find an efficient way to compute an RNG state<br>
far ahead of the current one.<br>
<br>
For a multiplicative generator like that of the NPB:<br>
<br>
        x[k+1] = a * x[k] mod p<br>
<br>
(p not necessarily prime), observe that<br>
<br>
        x[k+2] = a * x[k+1] mod p = a**2 * x[k] mod p<br>
<br>
so<br>
<br>
        x[k+m] = (a**m mod p) * x[k] mod p<br>
<br>
a**m mod p may be efficiently computed by Russian Peasant:<br>
<br>
        <a href="http://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication#Russian_peasant_multiplication" target="_blank">http://en.wikipedia.org/wiki/<u></u>Ancient_Egyptian_<u></u>multiplication#Russian_<u></u>peasant_multiplication</a><br>

<br>
Then<br>
<br>
        x[k+2*m] = (a**m mod p) * x[k+m] mod p<br>
<br>
et cetera.  Single-threaded operations fill in the rest.<br>
<br>
For LFSR-based generators, the multiplier is a bit matrix,<br>
so powers of that matrix would need to be computed (also by<br>
Russian Peasant).<br>
<br>
The scheme would be particular to each generation algorithm.<br>
<br>
Surprisingly many RNG can be parallelized this way; the big<br>
advantage over (say) simply giving each computational thread<br>
private RNG parameters is that with care the results of a<br>
parallel computation could match those of a serial one.<br>
<br>
Regards,<br>
<br>
Max<br>
</blockquote></div><br></div>