2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: ./lib/lattice/Lattice_rng.h
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
2016-12-06 16:31:13 +00:00
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
2016-01-02 14:51:32 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2015-04-18 20:44:19 +01:00
|
|
|
#ifndef GRID_LATTICE_RNG_H
|
|
|
|
#define GRID_LATTICE_RNG_H
|
|
|
|
|
2015-04-19 14:55:58 +01:00
|
|
|
#include <random>
|
2017-01-25 12:47:22 +00:00
|
|
|
#include <Grid/sitmo_rng/sitmo_prng_engine.hpp>
|
2015-04-19 14:55:58 +01:00
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
namespace Grid {
|
|
|
|
|
2015-08-19 10:26:07 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
// Allow the RNG state to be less dense than the fine grid
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
inline int RNGfillable(GridBase *coarse,GridBase *fine)
|
|
|
|
{
|
|
|
|
|
|
|
|
int rngdims = coarse->_ndimension;
|
|
|
|
|
|
|
|
// trivially extended in higher dims, with locality guaranteeing RNG state is local to node
|
|
|
|
int lowerdims = fine->_ndimension - coarse->_ndimension;
|
|
|
|
assert(lowerdims >= 0);
|
|
|
|
for(int d=0;d<lowerdims;d++){
|
|
|
|
assert(fine->_simd_layout[d]==1);
|
|
|
|
assert(fine->_processors[d]==1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int multiplicity=1;
|
2015-12-22 08:54:40 +00:00
|
|
|
for(int d=0;d<lowerdims;d++){
|
|
|
|
multiplicity=multiplicity*fine->_rdimensions[d];
|
|
|
|
}
|
|
|
|
// local and global volumes subdivide cleanly after SIMDization
|
2015-08-19 10:26:07 +01:00
|
|
|
for(int d=0;d<rngdims;d++){
|
|
|
|
int fd= d+lowerdims;
|
|
|
|
assert(coarse->_processors[d] == fine->_processors[fd]);
|
|
|
|
assert(coarse->_simd_layout[d] == fine->_simd_layout[fd]);
|
2015-12-22 08:54:40 +00:00
|
|
|
assert(((fine->_rdimensions[fd] / coarse->_rdimensions[d])* coarse->_rdimensions[d])==fine->_rdimensions[fd]);
|
2015-08-19 10:26:07 +01:00
|
|
|
|
|
|
|
multiplicity = multiplicity *fine->_rdimensions[fd] / coarse->_rdimensions[d];
|
|
|
|
}
|
|
|
|
|
|
|
|
return multiplicity;
|
|
|
|
}
|
|
|
|
|
2016-12-06 16:31:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
inline int RNGfillable_general(GridBase *coarse,GridBase *fine)
|
|
|
|
{
|
|
|
|
int rngdims = coarse->_ndimension;
|
|
|
|
|
|
|
|
// trivially extended in higher dims, with locality guaranteeing RNG state is local to node
|
|
|
|
int lowerdims = fine->_ndimension - coarse->_ndimension; assert(lowerdims >= 0);
|
|
|
|
// assumes that the higher dimensions are not using more processors
|
|
|
|
// all further divisions are local
|
|
|
|
for(int d=0;d<lowerdims;d++) assert(fine->_processors[d]==1);
|
|
|
|
for(int d=0;d<rngdims;d++) assert(coarse->_processors[d] == fine->_processors[d+lowerdims]);
|
|
|
|
|
|
|
|
|
|
|
|
// then divide the number of local sites
|
|
|
|
// check that the total number of sims agree, meanse the iSites are the same
|
|
|
|
assert(fine->Nsimd() == coarse->Nsimd());
|
|
|
|
|
|
|
|
// check that the two grids divide cleanly
|
|
|
|
assert( (fine->lSites() / coarse->lSites() ) * coarse->lSites() == fine->lSites() );
|
|
|
|
|
|
|
|
return fine->lSites() / coarse->lSites();
|
|
|
|
}
|
|
|
|
|
2015-04-19 14:55:58 +01:00
|
|
|
// Wrap seed_seq to give common interface with random_device
|
|
|
|
class fixedSeed {
|
|
|
|
public:
|
|
|
|
typedef std::seed_seq::result_type result_type;
|
|
|
|
std::seed_seq src;
|
2015-04-18 20:44:19 +01:00
|
|
|
|
2016-04-30 08:14:13 +01:00
|
|
|
fixedSeed(const std::vector<int> &seeds) : src(seeds.begin(),seeds.end()) {};
|
2015-04-19 14:55:58 +01:00
|
|
|
|
|
|
|
result_type operator () (void){
|
|
|
|
std::vector<result_type> list(1);
|
|
|
|
src.generate(list.begin(),list.end());
|
|
|
|
return list[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2015-04-26 15:51:09 +01:00
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
// real scalars are one component
|
|
|
|
template<class scalar,class distribution,class generator> void fillScalar(scalar &s,distribution &dist,generator & gen)
|
|
|
|
{
|
|
|
|
s=dist(gen);
|
|
|
|
}
|
|
|
|
template<class distribution,class generator> void fillScalar(ComplexF &s,distribution &dist, generator &gen)
|
|
|
|
{
|
|
|
|
s=ComplexF(dist(gen),dist(gen));
|
|
|
|
}
|
|
|
|
template<class distribution,class generator> void fillScalar(ComplexD &s,distribution &dist,generator &gen)
|
|
|
|
{
|
|
|
|
s=ComplexD(dist(gen),dist(gen));
|
|
|
|
}
|
|
|
|
|
2015-04-24 20:21:40 +01:00
|
|
|
class GridRNGbase {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
int _seeded;
|
|
|
|
// One generator per site.
|
|
|
|
// Uniform and Gaussian distributions from these generators.
|
2015-12-19 18:32:25 +00:00
|
|
|
#ifdef RNG_RANLUX
|
|
|
|
typedef uint64_t RngStateType;
|
|
|
|
typedef std::ranlux48 RngEngine;
|
|
|
|
static const int RngStateCount = 15;
|
2017-01-25 12:47:22 +00:00
|
|
|
#elif RNG_MT19937
|
2015-12-19 18:32:25 +00:00
|
|
|
typedef std::mt19937 RngEngine;
|
|
|
|
typedef uint32_t RngStateType;
|
|
|
|
static const int RngStateCount = std::mt19937::state_size;
|
2017-01-25 12:47:22 +00:00
|
|
|
#elif RNG_SITMO
|
|
|
|
typedef sitmo::prng_engine RngEngine;
|
|
|
|
typedef uint64_t RngStateType;
|
|
|
|
static const int RngStateCount = 4;
|
2015-12-19 18:32:25 +00:00
|
|
|
#endif
|
2016-04-30 08:14:13 +01:00
|
|
|
std::vector<RngEngine> _generators;
|
|
|
|
std::vector<std::uniform_real_distribution<RealD>> _uniform;
|
|
|
|
std::vector<std::normal_distribution<RealD>> _gaussian;
|
2016-04-30 11:48:28 +01:00
|
|
|
std::vector<std::discrete_distribution<int32_t>> _bernoulli;
|
2015-04-24 20:21:40 +01:00
|
|
|
|
2015-12-19 18:32:25 +00:00
|
|
|
void GetState(std::vector<RngStateType> & saved,int gen) {
|
|
|
|
saved.resize(RngStateCount);
|
|
|
|
std::stringstream ss;
|
|
|
|
ss<<_generators[gen];
|
|
|
|
ss.seekg(0,ss.beg);
|
|
|
|
for(int i=0;i<RngStateCount;i++){
|
2016-12-07 04:56:37 +00:00
|
|
|
ss>>saved[i];
|
2015-12-19 18:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void SetState(std::vector<RngStateType> & saved,int gen){
|
|
|
|
assert(saved.size()==RngStateCount);
|
|
|
|
std::stringstream ss;
|
|
|
|
for(int i=0;i<RngStateCount;i++){
|
2016-10-22 13:26:43 +01:00
|
|
|
ss<< saved[i]<<" ";
|
2015-12-19 18:32:25 +00:00
|
|
|
}
|
|
|
|
ss.seekg(0,ss.beg);
|
|
|
|
ss>>_generators[gen];
|
|
|
|
}
|
2015-04-24 20:21:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class GridSerialRNG : public GridRNGbase {
|
|
|
|
public:
|
|
|
|
|
|
|
|
// FIXME ... do we require lockstep draws of randoms
|
|
|
|
// from all nodes keeping seeds consistent.
|
|
|
|
// place a barrier/broadcast in the fill routine
|
|
|
|
template<class source> void Seed(source &src)
|
|
|
|
{
|
|
|
|
typename source::result_type init = src();
|
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&init,sizeof(init));
|
2015-12-19 18:32:25 +00:00
|
|
|
_generators[0] = RngEngine(init);
|
2015-04-24 20:21:40 +01:00
|
|
|
_seeded=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GridSerialRNG() : GridRNGbase() {
|
|
|
|
_generators.resize(1);
|
2015-12-22 08:54:40 +00:00
|
|
|
_uniform.resize(1,std::uniform_real_distribution<RealD>{0,1});
|
|
|
|
_gaussian.resize(1,std::normal_distribution<RealD>(0.0,1.0) );
|
2016-04-30 11:48:28 +01:00
|
|
|
_bernoulli.resize(1,std::discrete_distribution<int32_t>{1,1});
|
2015-04-24 20:21:40 +01:00
|
|
|
_seeded=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-26 15:51:09 +01:00
|
|
|
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class sobj,class distribution> inline void fill(sobj &l,std::vector<distribution> &dist){
|
2015-04-24 20:21:40 +01:00
|
|
|
|
|
|
|
typedef typename sobj::scalar_type scalar_type;
|
|
|
|
|
|
|
|
int words = sizeof(sobj)/sizeof(scalar_type);
|
|
|
|
|
|
|
|
scalar_type *buf = (scalar_type *) & l;
|
|
|
|
|
2015-12-22 08:54:40 +00:00
|
|
|
dist[0].reset();
|
2015-04-24 20:21:40 +01:00
|
|
|
for(int idx=0;idx<words;idx++){
|
2016-10-19 17:26:25 +01:00
|
|
|
fillScalar(buf[idx],dist[0],_generators[0]);
|
2015-04-24 20:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(ComplexF &l,std::vector<distribution> &dist){
|
|
|
|
dist[0].reset();
|
|
|
|
fillScalar(l,dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(ComplexD &l,std::vector<distribution> &dist){
|
|
|
|
dist[0].reset();
|
|
|
|
fillScalar(l,dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(RealF &l,std::vector<distribution> &dist){
|
|
|
|
dist[0].reset();
|
|
|
|
fillScalar(l,dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(RealD &l,std::vector<distribution> &dist){
|
|
|
|
dist[0].reset();
|
|
|
|
fillScalar(l,dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
|
|
|
// vector fill
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(vComplexF &l,std::vector<distribution> &dist){
|
2015-04-26 15:51:09 +01:00
|
|
|
RealF *pointer=(RealF *)&l;
|
2015-12-22 08:54:40 +00:00
|
|
|
dist[0].reset();
|
2015-04-26 15:51:09 +01:00
|
|
|
for(int i=0;i<2*vComplexF::Nsimd();i++){
|
2016-10-19 17:26:25 +01:00
|
|
|
fillScalar(pointer[i],dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(vComplexD &l,std::vector<distribution> &dist){
|
2015-04-26 15:51:09 +01:00
|
|
|
RealD *pointer=(RealD *)&l;
|
2015-12-22 08:54:40 +00:00
|
|
|
dist[0].reset();
|
2015-04-26 15:51:09 +01:00
|
|
|
for(int i=0;i<2*vComplexD::Nsimd();i++){
|
2016-10-19 17:26:25 +01:00
|
|
|
fillScalar(pointer[i],dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(vRealF &l,std::vector<distribution> &dist){
|
2015-04-26 15:51:09 +01:00
|
|
|
RealF *pointer=(RealF *)&l;
|
2015-12-22 08:54:40 +00:00
|
|
|
dist[0].reset();
|
2015-04-26 15:51:09 +01:00
|
|
|
for(int i=0;i<vRealF::Nsimd();i++){
|
2016-10-19 17:26:25 +01:00
|
|
|
fillScalar(pointer[i],dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
2015-12-22 08:54:40 +00:00
|
|
|
template <class distribution> inline void fill(vRealD &l,std::vector<distribution> &dist){
|
2015-04-26 15:51:09 +01:00
|
|
|
RealD *pointer=(RealD *)&l;
|
2015-12-22 08:54:40 +00:00
|
|
|
dist[0].reset();
|
2015-04-26 15:51:09 +01:00
|
|
|
for(int i=0;i<vRealD::Nsimd();i++){
|
2016-10-19 17:26:25 +01:00
|
|
|
fillScalar(pointer[i],dist[0],_generators[0]);
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
|
|
|
CartesianCommunicator::BroadcastWorld(0,(void *)&l,sizeof(l));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-24 20:21:40 +01:00
|
|
|
void SeedRandomDevice(void){
|
|
|
|
std::random_device rd;
|
|
|
|
Seed(rd);
|
|
|
|
}
|
2016-04-30 08:14:13 +01:00
|
|
|
void SeedFixedIntegers(const std::vector<int> &seeds){
|
2015-04-24 20:21:40 +01:00
|
|
|
fixedSeed src(seeds);
|
|
|
|
Seed(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class GridParallelRNG : public GridRNGbase {
|
2016-12-06 16:31:13 +00:00
|
|
|
|
|
|
|
double _time_counter;
|
|
|
|
|
2015-04-19 14:55:58 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
GridBase *_grid;
|
2016-12-06 16:31:13 +00:00
|
|
|
unsigned int _vol;
|
2015-04-19 14:55:58 +01:00
|
|
|
|
2017-01-19 10:00:02 +00:00
|
|
|
int generator_idx(int os,int is) {
|
2015-04-19 14:55:58 +01:00
|
|
|
return is*_grid->oSites()+os;
|
|
|
|
}
|
|
|
|
|
2015-04-24 20:21:40 +01:00
|
|
|
GridParallelRNG(GridBase *grid) : GridRNGbase() {
|
2016-12-06 16:31:13 +00:00
|
|
|
_grid = grid;
|
|
|
|
_vol =_grid->iSites()*_grid->oSites();
|
2015-12-22 08:54:40 +00:00
|
|
|
|
2015-04-19 14:55:58 +01:00
|
|
|
_generators.resize(_vol);
|
2015-12-22 08:54:40 +00:00
|
|
|
_uniform.resize(_vol,std::uniform_real_distribution<RealD>{0,1});
|
|
|
|
_gaussian.resize(_vol,std::normal_distribution<RealD>(0.0,1.0) );
|
2016-04-30 11:48:28 +01:00
|
|
|
_bernoulli.resize(_vol,std::discrete_distribution<int32_t>{1,1});
|
2016-12-06 16:31:13 +00:00
|
|
|
_seeded = 0;
|
|
|
|
|
|
|
|
_time_counter = 0.0;
|
|
|
|
|
2015-04-19 14:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This loop could be made faster to avoid the Ahmdahl by
|
|
|
|
// i) seed generators on each timeslice, for x=y=z=0;
|
|
|
|
// ii) seed generators on each z for x=y=0
|
|
|
|
// iii)seed generators on each y,z for x=0
|
|
|
|
// iv) seed generators on each y,z,x
|
|
|
|
// made possible by physical indexing.
|
|
|
|
template<class source> void Seed(source &src)
|
|
|
|
{
|
|
|
|
std::vector<int> gcoor;
|
|
|
|
|
2015-04-28 08:11:59 +01:00
|
|
|
int gsites = _grid->_gsites;
|
|
|
|
|
|
|
|
typename source::result_type init = src();
|
2015-12-19 18:32:25 +00:00
|
|
|
RngEngine pseeder(init);
|
2015-04-28 08:11:59 +01:00
|
|
|
std::uniform_int_distribution<uint64_t> ui;
|
|
|
|
|
|
|
|
for(int gidx=0;gidx<gsites;gidx++){
|
|
|
|
|
2016-12-07 04:56:37 +00:00
|
|
|
int rank,o_idx,i_idx;
|
|
|
|
_grid->GlobalIndexToGlobalCoor(gidx,gcoor);
|
|
|
|
_grid->GlobalCoorToRankIndex(rank,o_idx,i_idx,gcoor);
|
2016-10-26 18:44:47 +01:00
|
|
|
|
2016-12-07 04:56:37 +00:00
|
|
|
int l_idx=generator_idx(o_idx,i_idx);
|
2016-10-25 01:05:52 +01:00
|
|
|
|
2016-12-07 04:56:37 +00:00
|
|
|
const int num_rand_seed=16;
|
|
|
|
std::vector<int> site_seeds(num_rand_seed);
|
|
|
|
for(int i=0;i<site_seeds.size();i++){
|
|
|
|
site_seeds[i]= ui(pseeder);
|
|
|
|
}
|
2015-04-19 14:55:58 +01:00
|
|
|
|
2016-10-24 11:02:14 +01:00
|
|
|
|
2016-12-07 04:56:37 +00:00
|
|
|
_grid->Broadcast(0,(void *)&site_seeds[0],sizeof(int)*site_seeds.size());
|
2016-10-24 11:02:14 +01:00
|
|
|
|
2016-12-07 04:56:37 +00:00
|
|
|
if( rank == _grid->ThisRank() ){
|
2016-10-24 11:02:14 +01:00
|
|
|
fixedSeed ssrc(site_seeds);
|
|
|
|
typename source::result_type sinit = ssrc();
|
|
|
|
_generators[l_idx] = RngEngine(sinit);
|
2016-12-07 04:56:37 +00:00
|
|
|
}
|
2015-04-19 14:55:58 +01:00
|
|
|
}
|
2015-04-24 20:21:40 +01:00
|
|
|
_seeded=1;
|
2015-04-19 14:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME implement generic IO and create state save/restore
|
|
|
|
//void SaveState(const std::string<char> &file);
|
|
|
|
//void LoadState(const std::string<char> &file);
|
|
|
|
|
2016-10-19 17:26:25 +01:00
|
|
|
template <class vobj, class distribution>
|
|
|
|
inline void fill(Lattice<vobj> &l, std::vector<distribution> &dist) {
|
2015-04-28 08:11:59 +01:00
|
|
|
typedef typename vobj::scalar_object scalar_object;
|
2015-04-19 14:55:58 +01:00
|
|
|
typedef typename vobj::scalar_type scalar_type;
|
|
|
|
typedef typename vobj::vector_type vector_type;
|
|
|
|
|
2016-12-06 16:31:13 +00:00
|
|
|
double inner_time_counter = usecond();
|
2015-04-19 14:55:58 +01:00
|
|
|
|
2016-12-06 16:31:13 +00:00
|
|
|
int multiplicity = RNGfillable_general(_grid, l._grid); // l has finer or same grid
|
|
|
|
|
|
|
|
int Nsimd = _grid->Nsimd();// guaranteed to be the same for l._grid too
|
|
|
|
int osites = _grid->oSites();// guaranteed to be <= l._grid->oSites() by a factor multiplicity
|
2016-10-19 17:26:25 +01:00
|
|
|
int words = sizeof(scalar_object) / sizeof(scalar_type);
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2016-10-19 17:26:25 +01:00
|
|
|
PARALLEL_FOR_LOOP
|
|
|
|
for (int ss = 0; ss < osites; ss++) {
|
2015-04-19 14:55:58 +01:00
|
|
|
|
2016-10-19 17:26:25 +01:00
|
|
|
std::vector<scalar_object> buf(Nsimd);
|
2016-12-06 16:31:13 +00:00
|
|
|
for (int m = 0; m < multiplicity; m++) { // Draw from same generator multiplicity times
|
2015-08-19 10:26:07 +01:00
|
|
|
|
2016-12-06 16:31:13 +00:00
|
|
|
int sm = multiplicity * ss + m; // Maps the generator site to the fine site
|
2015-08-19 10:26:07 +01:00
|
|
|
|
2016-10-19 17:26:25 +01:00
|
|
|
for (int si = 0; si < Nsimd; si++) {
|
|
|
|
|
|
|
|
int gdx = generator_idx(ss, si); // index of generator state
|
|
|
|
scalar_type *pointer = (scalar_type *)&buf[si];
|
|
|
|
dist[gdx].reset();
|
2016-12-06 16:31:13 +00:00
|
|
|
for (int idx = 0; idx < words; idx++)
|
2016-10-19 17:26:25 +01:00
|
|
|
fillScalar(pointer[idx], dist[gdx], _generators[gdx]);
|
|
|
|
}
|
2016-12-07 04:56:37 +00:00
|
|
|
// merge into SIMD lanes, FIXME suboptimal implementation
|
2016-10-19 17:26:25 +01:00
|
|
|
merge(l._odata[sm], buf);
|
|
|
|
}
|
2015-04-19 14:55:58 +01:00
|
|
|
}
|
2016-12-06 16:31:13 +00:00
|
|
|
|
|
|
|
_time_counter += usecond()- inner_time_counter;
|
2015-04-18 20:44:19 +01:00
|
|
|
};
|
2015-04-24 20:21:40 +01:00
|
|
|
|
2016-10-19 17:26:25 +01:00
|
|
|
void SeedRandomDevice(void) {
|
2015-04-24 20:21:40 +01:00
|
|
|
std::random_device rd;
|
|
|
|
Seed(rd);
|
|
|
|
}
|
2016-10-19 17:26:25 +01:00
|
|
|
void SeedFixedIntegers(const std::vector<int> &seeds) {
|
2015-04-24 20:21:40 +01:00
|
|
|
fixedSeed src(seeds);
|
|
|
|
Seed(src);
|
|
|
|
}
|
2016-12-06 16:31:13 +00:00
|
|
|
|
|
|
|
void Report(){
|
|
|
|
std::cout << GridLogMessage << "Time spent in the fill() routine by GridParallelRNG: "<< _time_counter/1e3 << " ms" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-19 14:55:58 +01:00
|
|
|
};
|
|
|
|
|
2015-04-24 20:21:40 +01:00
|
|
|
template <class vobj> inline void random(GridParallelRNG &rng,Lattice<vobj> &l){
|
2015-04-19 14:55:58 +01:00
|
|
|
rng.fill(l,rng._uniform);
|
|
|
|
}
|
2015-04-18 20:44:19 +01:00
|
|
|
|
2015-04-24 20:21:40 +01:00
|
|
|
template <class vobj> inline void gaussian(GridParallelRNG &rng,Lattice<vobj> &l){
|
|
|
|
rng.fill(l,rng._gaussian);
|
|
|
|
}
|
2016-04-30 08:14:13 +01:00
|
|
|
|
2016-04-30 11:48:28 +01:00
|
|
|
template <class vobj> inline void bernoulli(GridParallelRNG &rng,Lattice<vobj> &l){
|
|
|
|
rng.fill(l,rng._bernoulli);
|
|
|
|
}
|
2015-04-24 20:21:40 +01:00
|
|
|
|
|
|
|
template <class sobj> inline void random(GridSerialRNG &rng,sobj &l){
|
|
|
|
rng.fill(l,rng._uniform);
|
|
|
|
}
|
2016-04-30 08:14:13 +01:00
|
|
|
|
2015-04-24 20:21:40 +01:00
|
|
|
template <class sobj> inline void gaussian(GridSerialRNG &rng,sobj &l){
|
2015-04-19 14:55:58 +01:00
|
|
|
rng.fill(l,rng._gaussian);
|
|
|
|
}
|
2016-04-30 08:14:13 +01:00
|
|
|
|
2016-04-30 11:48:28 +01:00
|
|
|
template <class sobj> inline void bernoulli(GridSerialRNG &rng,sobj &l){
|
|
|
|
rng.fill(l,rng._bernoulli);
|
|
|
|
}
|
2015-04-24 20:21:40 +01:00
|
|
|
|
2015-04-18 20:44:19 +01:00
|
|
|
}
|
|
|
|
#endif
|