// source: https://os.inf.tu-dresden.de/repo/gitbox/andre.berthold/Query-driven_Prefetching/src/branch/intel_xeon_max/code/src/utils/array_utils.h // author: Andre Berthold #pragma once #include #include #include #include #include #include #include /// @brief Fills a given array with random generated integers. /// @tparam base_t Datatype of the array /// @param dest Pointer to the array /// @param size Size of the array /// @param min Minumum value of the generated integers /// @param max Maximum value of the generated integers template void fill(base_t * dest, uint64_t size, base_t min, base_t max) { std::srand(std::time(nullptr)); for(uint64_t i = 0; i < size/sizeof(base_t); ++i) { dest[i] = (std::rand() % (max - min)) + min; } } /// @brief Fills a given array with random generated integers using the mersenne twister engine (type std::mt19937). /// @tparam base_t Datatype of the array /// @param dest Pointer to the array /// @param size Size of the array /// @param min Minumum value of the generated integers /// @param max Maximum value of the generated integers template void fill_mt(T* array, uint64_t size, T min, T max, uint64_t int_seed = 0) { static_assert(std::is_integral::value, "Data type is not integral."); size = size / sizeof(T); std::mt19937::result_type seed; if (int_seed == 0) { std::random_device rd; seed = rd() ^ ( (std::mt19937::result_type) std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count() + (std::mt19937::result_type) std::chrono::duration_cast( std::chrono::high_resolution_clock::now().time_since_epoch()).count()); } else seed = int_seed; std::mt19937 gen(seed); std::uniform_int_distribution distrib(min, max); for (uint64_t j = 0; j < size; ++j) { array[j] = distrib(gen); } } /** * @brief Checks if two arrays of the integral type *T* contain the same values * * @tparam T Integral type of *array0* and *array1* * @param array0 Array 0 to check * @param array1 Array 1 to check * @param size_b Size of the two arrays in byte * @param verbose Decides if outputs are verbose of not (print every not matching numbers with their index) * @return bool Weathor or not the content is equal or not */ template typename std::enable_if::value, bool>::type check_same(T* array0, T* array1, size_t size_b, bool verbose) { for(uint64_t i = 0; i <= size_b / sizeof(T); i += 64 / sizeof(T)) { __m512i vec0 = _mm512_stream_load_si512(array0 + i); __m512i vec1 = _mm512_stream_load_si512(array1 + i); __mmask8 res = _mm512_cmpeq_epi64_mask(vec0, vec1); } //TODO complete function return false; }