diff --git a/benchmarks/Benchmark_dwf.cc b/benchmarks/Benchmark_dwf.cc index 1d9de772..a7362e35 100644 --- a/benchmarks/Benchmark_dwf.cc +++ b/benchmarks/Benchmark_dwf.cc @@ -76,9 +76,9 @@ int main (int argc, char ** argv) std::vector seeds5({5,6,7,8}); std::cout << GridLogMessage << "Initialising 4d RNG" << std::endl; - GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); + GridParallelRNG RNG4(UGrid); RNG4.SeedUniqueString(std::string("The 4D RNG")); std::cout << GridLogMessage << "Initialising 5d RNG" << std::endl; - GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5); + GridParallelRNG RNG5(FGrid); RNG5.SeedUniqueString(std::string("The 5D RNG")); std::cout << GridLogMessage << "Initialised RNGs" << std::endl; LatticeFermion src (FGrid); random(RNG5,src); diff --git a/lib/GridCore.h b/lib/GridCore.h index 55396a37..3f31701a 100644 --- a/lib/GridCore.h +++ b/lib/GridCore.h @@ -48,6 +48,7 @@ Author: paboyle #include #include #include +#include #include #include #include diff --git a/lib/lattice/Lattice_rng.h b/lib/lattice/Lattice_rng.h index 654c5dd5..1c6dab01 100644 --- a/lib/lattice/Lattice_rng.h +++ b/lib/lattice/Lattice_rng.h @@ -251,7 +251,7 @@ namespace Grid { dist[0].reset(); for(int idx=0;idx seeds; + seeds = GridChecksum::sha256_seeds(s); + std::cout << GridLogMessage << "Intialising Serial RNG with unique string " < seeds; + seeds = GridChecksum::sha256_seeds(s); + std::cout << GridLogMessage << "Intialising Parallel RNG with unique string " < &seeds){ // Everyone generates the same seed_seq based on input seeds diff --git a/lib/util/Sha.h b/lib/util/Sha.h new file mode 100644 index 00000000..6cfbe0bd --- /dev/null +++ b/lib/util/Sha.h @@ -0,0 +1,70 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/util/Sha.h + + Copyright (C) 2018 + + Author: Peter Boyle + + 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 */ +extern "C" { +#include +} + +#pragma once + +class GridChecksum +{ +public: + static inline uint32_t crc32(void *data,size_t bytes) + { + return ::crc32(0L,(unsigned char *)data,bytes); + } + static inline std::vector sha256(void *data,size_t bytes) + { + std::vector hash(SHA256_DIGEST_LENGTH); + SHA256_CTX sha256; + SHA256_Init (&sha256); + SHA256_Update(&sha256, data,bytes); + SHA256_Final (&hash[0], &sha256); + return hash; + } + static inline std::vector sha256_seeds(const std::string &s) + { + std::vector seeds; + std::vector uchars = sha256((void *)s.c_str(),s.size()); + for(int i=0;i