Microsoft PPL parallel_for_each with boost filesystem directory_iterator
using Visual Studio 2010 SP1
so i have a std::for_each iterating on lots of files using the boost::filesystem library. since those iterations dont mess with each other i was trying to get multi threading working on it, so im trying to use VS 2010 library PPL.
old: for_each(directory_iterator(path), directory_iterator(), <lambda function>);
new: parallel_for_each(directory_iterator(path), directory_iterator(), <lambda function>);
thing is, the p开发者_运维技巧arallel_for_each one doesnt compile because it asks for a random access iterator or a forward access iterator which i assume directory_iterator is not. is there a way i can make directory_iterator work in this case? maybe with a diferent iterator that i dont know about or maybe some kind of cast?
tried searching for an answer on the web, but PPL with boost isnt really that much talked yet.
thanks in advance.
If most of your time is spent loading files, you're only slowing yourself down by trying to load multiple files. That said, if your work is processing-bound, you could do something like this:
for each file // serial
{
load file into memory
spawn task to process file // concurrent
}
wait until tasks to complete
For that, you'll want to use the tasks.
精彩评论