#include <iostream>
#include <vector>
#include <thread>
#include <ctime>
#include <cstdlib>
void myInit(std::vector<int>& vect, int start, int end) {
for (int i = start; i < end; i++) {
vect[i] = rand() % 1001;
}
}
int main() {
system("chcp 1251 > nul");
srand(time(nullptr));
const int size = 1000000000;
std::vector<int> vect(size);
int threadCount = std::thread::hardware_concurrency();
std::cout << "Thread count: " << threadCount << std::endl;
int partSize = size / threadCount;
std::vector<std::thread> threads;
time_t start = clock();
for (unsigned int i = 0; i < threadCount; i++) {
int begin = i * partSize;
int end = begin + partSize;
if (i == threadCount - 1) {
end = size;
}
threads.emplace_back(myInit, std::ref(vect), begin, end);
}
for (int i = 0; i < threadCount; i++) {
threads[i].join();
}
time_t end = clock();
double time_diff = (end - start) / 1000.0;
std::cout << time_diff << " sec\n";
}