mirror of
https://github.com/cosmo-sims/MUSIC.git
synced 2024-09-19 17:03:46 +02:00
updated N-GenIC RNG to multithreading
This commit is contained in:
parent
75587bbf26
commit
b6cef8dd01
1 changed files with 59 additions and 52 deletions
|
@ -48,26 +48,31 @@ void music_wnoise_generator<T>:: gen_topgrid_NGenIC(size_t res, long baseseed) {
|
|||
for (j = 0; j < i + 1; j++)
|
||||
seedtable[(res - 1 - j) * res + (res - 1 - i)] = 0x7fffffff * gsl_rng_uniform(random_generator);
|
||||
}
|
||||
gsl_rng_free( random_generator );
|
||||
|
||||
real_t *rnoise = new real_t[res * res * (res + 2)];
|
||||
complex_t *knoise = reinterpret_cast<complex_t *>(rnoise);
|
||||
|
||||
double fnorm = pow((double)res, -1.5);
|
||||
|
||||
// /#warning need to check for race conditions below
|
||||
//#pragma omp parallel for
|
||||
// launch threads with indendent RNGs
|
||||
#pragma omp parallel
|
||||
{
|
||||
gsl_rng *thread_rng = gsl_rng_alloc(gsl_rng_ranlxd1);
|
||||
|
||||
#pragma omp for
|
||||
for (size_t i = 0; i < res; i++) {
|
||||
int ii = (int)res - (int)i;
|
||||
if (ii == (int)res)
|
||||
ii = 0;
|
||||
|
||||
for (size_t j = 0; j < res; j++) {
|
||||
gsl_rng_set(random_generator, seedtable[i * res + j]);
|
||||
gsl_rng_set(thread_rng, seedtable[i * res + j]);
|
||||
for (size_t k = 0; k < res / 2; k++) {
|
||||
double phase = gsl_rng_uniform(random_generator) * 2 * M_PI;
|
||||
double phase = gsl_rng_uniform(thread_rng) * 2 * M_PI;
|
||||
double ampl;
|
||||
do {
|
||||
ampl = gsl_rng_uniform(random_generator);
|
||||
ampl = gsl_rng_uniform(thread_rng);
|
||||
} while (ampl == 0);
|
||||
|
||||
if (i == res / 2 || j == res / 2 || k == res / 2)
|
||||
|
@ -120,6 +125,8 @@ void music_wnoise_generator<T>:: gen_topgrid_NGenIC(size_t res, long baseseed) {
|
|||
}
|
||||
}
|
||||
}
|
||||
gsl_rng_free( thread_rng );
|
||||
}
|
||||
|
||||
delete[] seedtable;
|
||||
|
||||
|
|
Loading…
Reference in a new issue