Skip to content

Commit

Permalink
Switch from openmp tasks to std::async
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoehrle committed Aug 8, 2016
1 parent 544f371 commit 1e4432c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions libs/tex/generate_texture_atlases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <set>
#include <list>
#include <future>
#include <iostream>
#include <fstream>

Expand Down Expand Up @@ -110,10 +111,7 @@ generate_texture_atlases(std::vector<TexturePatch::Ptr> * 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<std::future<void> > futures;

while (!texture_patches.empty()) {
unsigned int texture_size = calculate_texture_size(texture_patches);
Expand Down Expand Up @@ -142,21 +140,19 @@ generate_texture_atlases(std::vector<TexturePatch::Ptr> * 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<void> & future : futures) {
future.wait();
}
std::cout << "done. (Took: " << timer.get_elapsed_sec() << "s)" << std::endl;
}

TEX_NAMESPACE_END

1 comment on commit 1e4432c

@hushanming
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.This gave me a lot of help

Please sign in to comment.