Skip to content

Replace random number generation module by Xoshiro#169

Merged
thomas3494 merged 12 commits intoSacBase:masterfrom
thomas3494:xoshiro-random
Apr 30, 2025
Merged

Replace random number generation module by Xoshiro#169
thomas3494 merged 12 commits intoSacBase:masterfrom
thomas3494:xoshiro-random

Conversation

@thomas3494
Copy link
Copy Markdown
Contributor

@thomas3494 thomas3494 commented Apr 29, 2025

See title. Example program of usage

use Array: all;
use StdIO: all;
use Benchmarking: all;
use Xoshiro: all;

inline
double[n], struct State256 add_normal(double[n] x, struct State256 state)
{
   for (i = 0; i + 1 < n; i += 2) {
     u1, state = xoshiro256p(state);
     u2, state = xoshiro256p(state);
     N1, N2 = to_normal(u1, u2, 0d, 1d);
     x[i]     = N1;
     x[i + 1] = N2;
   }
   if (n % 2 != 0) {
     u1, state = xoshiro256p(state);
     u2, state = xoshiro256p(state);
     N1, N2 = to_normal(u1, u2, 0d, 1d);
     x[n - 1] = N1;
   }
   return (x, state);
}

int main()
{
  n = 1000000000;
  p = 8; // number of processors you have
  states = seed_arrl(p, srand256());

  x = {iv -> 0d | iv < [p, n / p]};

	itime = getInterval("uniform", 1);
  start(itime);
  x, states = {[t] -> add_normal(x[t], _sel_VxA_([t], states))};
  end(itime);

	time, unit = returnResultUnit(itime);
  printf("Created %lf GB of N(0, 1) variables at %lf GB/s\n",
         8d * tod(n) / 1e9, 8d * tod(n) / 1e9 * 2d / time);

  return toi(sum(x));
}

Closes #113

Copy link
Copy Markdown
Member

@sbscholz sbscholz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine

@thomas3494 thomas3494 merged commit fda1199 into SacBase:master Apr 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Too many random number generation modules

3 participants