From 1e4432ca5fbb7de99e2ce015983699e2b1da6d2d Mon Sep 17 00:00:00 2001 From: Nils Moehrle Date: Mon, 8 Aug 2016 09:37:04 +0200 Subject: [PATCH] Switch from openmp tasks to std::async --- libs/tex/generate_texture_atlases.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/libs/tex/generate_texture_atlases.cpp b/libs/tex/generate_texture_atlases.cpp index 78bbc72a..d3be8dfd 100644 --- a/libs/tex/generate_texture_atlases.cpp +++ b/libs/tex/generate_texture_atlases.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -110,10 +111,7 @@ generate_texture_atlases(std::vector * orig_texture_patches, std::size_t remaining_patches = texture_patches.size(); std::ofstream tty("/dev/tty", std::ios_base::out); - #pragma omp parallel - { - #pragma omp single - { + std::vector > futures; while (!texture_patches.empty()) { unsigned int texture_size = calculate_texture_size(texture_patches); @@ -142,21 +140,19 @@ generate_texture_atlases(std::vector * orig_texture_patches, } } - #pragma omp task - texture_atlas->finalize(); + futures.push_back(std::async(std::launch::async, [texture_atlas] { + texture_atlas->finalize(); + })); } std::cout << "\r\tWorking on atlas " << texture_atlases->size() << " 100%... done." << std::endl; util::WallTimer timer; std::cout << "\tFinalizing texture atlases... " << std::flush; - #pragma omp taskwait - std::cout << "done. (Took: " << timer.get_elapsed_sec() << "s)" << std::endl; - - /* End of single region */ - } - /* End of parallel region. */ + for (std::future & future : futures) { + future.wait(); } + std::cout << "done. (Took: " << timer.get_elapsed_sec() << "s)" << std::endl; } TEX_NAMESPACE_END