1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 17:25:37 +01:00

Merge branch 'master' into hadrons

This commit is contained in:
Antonin Portelli 2016-04-30 00:16:06 -07:00
commit 405b175665
6 changed files with 88 additions and 12 deletions

3
.gitignore vendored
View File

@ -94,8 +94,7 @@ Thumbs.db
# build directory # # build directory #
################### ###################
build/* build*/*
build_debug/*
# IDE related files # # IDE related files #
##################### #####################

View File

@ -65,8 +65,11 @@ inline uint64_t cyclecount(void){
return tmp; return tmp;
} }
#elif defined __x86_64__ #elif defined __x86_64__
#include <immintrin.h>
#ifndef __INTEL_COMPILER
#include <x86intrin.h> #include <x86intrin.h>
inline uint64_t cyclecount(void){ #endif
inline uint64_t cyclecount(void){
return __rdtsc(); return __rdtsc();
} }
#else #else

View File

@ -75,7 +75,7 @@ namespace Grid {
std::seed_seq src; std::seed_seq src;
fixedSeed(std::vector<int> &seeds) : src(seeds.begin(),seeds.end()) {}; fixedSeed(const std::vector<int> &seeds) : src(seeds.begin(),seeds.end()) {};
result_type operator () (void){ result_type operator () (void){
@ -119,9 +119,10 @@ namespace Grid {
typedef uint32_t RngStateType; typedef uint32_t RngStateType;
static const int RngStateCount = std::mt19937::state_size; static const int RngStateCount = std::mt19937::state_size;
#endif #endif
std::vector<RngEngine> _generators; std::vector<RngEngine> _generators;
std::vector<std::uniform_real_distribution<RealD> > _uniform; std::vector<std::uniform_real_distribution<RealD>> _uniform;
std::vector<std::normal_distribution<RealD> > _gaussian; std::vector<std::normal_distribution<RealD>> _gaussian;
std::vector<std::discrete_distribution<RealD>> _bernoulli;
void GetState(std::vector<RngStateType> & saved,int gen) { void GetState(std::vector<RngStateType> & saved,int gen) {
saved.resize(RngStateCount); saved.resize(RngStateCount);
@ -161,6 +162,7 @@ namespace Grid {
_generators.resize(1); _generators.resize(1);
_uniform.resize(1,std::uniform_real_distribution<RealD>{0,1}); _uniform.resize(1,std::uniform_real_distribution<RealD>{0,1});
_gaussian.resize(1,std::normal_distribution<RealD>(0.0,1.0) ); _gaussian.resize(1,std::normal_distribution<RealD>(0.0,1.0) );
_bernoulli.resize(1,std::discrete_distribution<RealD>{1,1});
_seeded=0; _seeded=0;
} }
@ -242,7 +244,7 @@ namespace Grid {
std::random_device rd; std::random_device rd;
Seed(rd); Seed(rd);
} }
void SeedFixedIntegers(std::vector<int> &seeds){ void SeedFixedIntegers(const std::vector<int> &seeds){
fixedSeed src(seeds); fixedSeed src(seeds);
Seed(src); Seed(src);
} }
@ -266,6 +268,7 @@ namespace Grid {
_generators.resize(_vol); _generators.resize(_vol);
_uniform.resize(_vol,std::uniform_real_distribution<RealD>{0,1}); _uniform.resize(_vol,std::uniform_real_distribution<RealD>{0,1});
_gaussian.resize(_vol,std::normal_distribution<RealD>(0.0,1.0) ); _gaussian.resize(_vol,std::normal_distribution<RealD>(0.0,1.0) );
_bernoulli.resize(_vol,std::discrete_distribution<RealD>{1,1});
_seeded=0; _seeded=0;
} }
@ -354,7 +357,7 @@ PARALLEL_FOR_LOOP
std::random_device rd; std::random_device rd;
Seed(rd); Seed(rd);
} }
void SeedFixedIntegers(std::vector<int> &seeds){ void SeedFixedIntegers(const std::vector<int> &seeds){
fixedSeed src(seeds); fixedSeed src(seeds);
Seed(src); Seed(src);
} }
@ -368,14 +371,22 @@ PARALLEL_FOR_LOOP
template <class vobj> inline void gaussian(GridParallelRNG &rng,Lattice<vobj> &l){ template <class vobj> inline void gaussian(GridParallelRNG &rng,Lattice<vobj> &l){
rng.fill(l,rng._gaussian); rng.fill(l,rng._gaussian);
} }
template <class vobj> inline void bernoulli(GridParallelRNG &rng,Lattice<vobj> &l){
rng.fill(l,rng._bernoulli);
}
template <class sobj> inline void random(GridSerialRNG &rng,sobj &l){ template <class sobj> inline void random(GridSerialRNG &rng,sobj &l){
rng.fill(l,rng._uniform); rng.fill(l,rng._uniform);
} }
template <class sobj> inline void gaussian(GridSerialRNG &rng,sobj &l){ template <class sobj> inline void gaussian(GridSerialRNG &rng,sobj &l){
rng.fill(l,rng._gaussian); rng.fill(l,rng._gaussian);
} }
template <class sobj> inline void bernoulli(GridSerialRNG &rng,sobj &l){
rng.fill(l,rng._bernoulli);
}
} }
#endif #endif

View File

@ -383,7 +383,6 @@ namespace QCD {
////////////////////////////////////////////// //////////////////////////////////////////////
// Poke scalars // Poke scalars
////////////////////////////////////////////// //////////////////////////////////////////////
template<class vobj> void pokeSpin(vobj &lhs,const decltype(peekIndex<SpinIndex>(lhs,0)) & rhs,int i) template<class vobj> void pokeSpin(vobj &lhs,const decltype(peekIndex<SpinIndex>(lhs,0)) & rhs,int i)
{ {
pokeIndex<SpinIndex>(lhs,rhs,i); pokeIndex<SpinIndex>(lhs,rhs,i);
@ -407,7 +406,41 @@ namespace QCD {
pokeIndex<LorentzIndex>(lhs,rhs,i); pokeIndex<LorentzIndex>(lhs,rhs,i);
} }
//////////////////////////////////////////////
// Fermion <-> propagator assignements
//////////////////////////////////////////////
template <class Prop, class Ferm>
void FermToProp(Prop &p, const Ferm &f, const int s, const int c)
{
for(int j = 0; j < Ns; ++j)
{
auto pjs = peekSpin(p, j, s);
auto fj = peekSpin(f, j);
for(int i = 0; i < Nc; ++i)
{
pokeColour(pjs, peekColour(fj, i), i, c);
}
pokeSpin(p, pjs, j, s);
}
}
template <class Prop, class Ferm>
void PropToFerm(Ferm &f, const Prop &p, const int s, const int c)
{
for(int j = 0; j < Ns; ++j)
{
auto pjs = peekSpin(p, j, s);
auto fj = peekSpin(f, j);
for(int i = 0; i < Nc; ++i)
{
pokeColour(fj, peekColour(pjs, i, c), i);
}
pokeSpin(f, fj, j);
}
}
////////////////////////////////////////////// //////////////////////////////////////////////
// transpose array and scalar // transpose array and scalar
////////////////////////////////////////////// //////////////////////////////////////////////

View File

@ -32,6 +32,22 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
#include <type_traits> #include <type_traits>
namespace Grid { namespace Grid {
// helper function to read space-separated values
template <typename T>
std::vector<T> strToVec(const std::string s)
{
std::istringstream sstr(s);
T buf;
std::vector<T> v;
while(!sstr.eof())
{
sstr >> buf;
v.push_back(buf);
}
return v;
}
class Serializable {}; class Serializable {};

View File

@ -140,4 +140,18 @@ int main(int argc,char **argv)
std::cout << "Loaded (txt) -----------------" << std::endl; std::cout << "Loaded (txt) -----------------" << std::endl;
std::cout << copy3 << std::endl << veccopy3 << std::endl; std::cout << copy3 << std::endl << veccopy3 << std::endl;
} }
std::vector<int> iv = strToVec<int>("1 2 2 4");
std::vector<std::string> sv = strToVec<std::string>("bli bla blu");
for (auto &e: iv)
{
std::cout << e << " ";
}
std::cout << std::endl;
for (auto &e: sv)
{
std::cout << e << " ";
}
std::cout << std::endl;
} }