You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpp_thread_safety_common.h 1.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. inline void pauser(){
  2. /// a portable way to pause a program
  3. std::string dummy;
  4. std::cout << "Press enter to continue...";
  5. std::getline(std::cin, dummy);
  6. }
  7. void FillMatrices(std::vector<std::vector<double>>& matBlock, std::mt19937_64& PRNG, std::uniform_real_distribution<double>& rngdist, const blasint randomMatSize, const uint32_t numConcurrentThreads){
  8. for(uint32_t i=0; i<3; i++){
  9. for(uint32_t j=0; j<(randomMatSize*randomMatSize); j++){
  10. matBlock[i][j] = rngdist(PRNG);
  11. }
  12. }
  13. for(uint32_t i=3; i<(numConcurrentThreads*3); i+=3){
  14. matBlock[i] = matBlock[0];
  15. matBlock[i+1] = matBlock[1];
  16. matBlock[i+2] = matBlock[2];
  17. }
  18. }
  19. std::mt19937_64 InitPRNG(){
  20. std::random_device rd;
  21. std::mt19937_64 PRNG(rd()); //seed PRNG using /dev/urandom or similar OS provided RNG
  22. std::uniform_real_distribution<double> rngdist{-1.0, 1.0};
  23. //make sure the internal state of the PRNG is properly mixed by generating 10M random numbers
  24. //PRNGs often have unreliable distribution uniformity and other statistical properties before their internal state is sufficiently mixed
  25. for (uint32_t i=0;i<10000000;i++) rngdist(PRNG);
  26. return PRNG;
  27. }
  28. void PrintMatrices(const std::vector<std::vector<double>>& matBlock, const blasint randomMatSize, const uint32_t numConcurrentThreads){
  29. for (uint32_t i=0;i<numConcurrentThreads*3;i++){
  30. std::cout<<i<<std::endl;
  31. for (uint32_t j=0;j<randomMatSize;j++){
  32. for (uint32_t k=0;k<randomMatSize;k++){
  33. std::cout<<matBlock[i][j*randomMatSize + k]<<" ";
  34. }
  35. std::cout<<std::endl;
  36. }
  37. std::cout<<std::endl;
  38. }
  39. }