Вот это пример того, что я пытаюсь сделать.
Код: Выделить всё
#include
#include
#include
#include
int main()
{
auto start = std::chrono::high_resolution_clock::now();
//processor supports 24 threads
//#pragma omp parallel for
for (int i = 0; i < 24; ++i) {
for (int j = 0; j < 100; ++j) {
for (int k = 0; k < 100; ++k) {
for (int l = 0; l < 100; ++l) {
int result = i + j + k + l;
std::vector resultsOver200 = {};
if (result > 200) {
resultsOver200.push_back(result);
}
//do something else with result
}
}
}
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration duration = end - start;
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79345152/why-does-creating-a-c-vector-in-an-openmp-parallel-for-loop-cause-it-to-slow-s[/url]
Мобильная версия