0

I have an application that is run in a for loop:

// initialization
for (std::vector< VerifObj >::const_iterator itVOV = verifObjVector.begin(); itVOV != verifObjVector.end(); itVOV++)
{
    // run my application for itVOV
    std::cout << "\b\b\b\b" << std::setw(3) << static_cast< int >(100.f * ++photoCntr / verifObjVecSz) << "%"
        << std::flush;
    std::this_thread::sleep_for(std::chrono::milliseconds(30));
}
std::cout << "\b\b\b\b" << std::setw(3) << "100%" << std::endl;

Because each iteration is taking some minutes, I thought to make it multi thread, so it can run faster. I am a beginner in multi threading so, I am asking how to do it?

Cœur
  • 37,241
  • 25
  • 195
  • 267
sop
  • 3,445
  • 8
  • 41
  • 84
  • 5
    Did you check openMP ? – willll Sep 16 '14 at 15:06
  • 1
    If you're wanting to go with basic, standard C++ threading, C++11 added std::thread that you might try looking into. Otherwise, OpenMP is another option. There are many options. – Serge Sep 16 '14 at 15:08
  • I think he's looking for a standard map-reduce algorithm – CashCow Sep 16 '14 at 15:10
  • I think that OpenMP is nice and good. How to install it and use it on Ubuntu? – sop Sep 16 '14 at 15:13
  • I have found it [here](http://stackoverflow.com/a/7916661/3062311) – sop Sep 16 '14 at 15:21
  • 1
    You can try cilk+, e.g.: `cilk_for(int i = 0; i < verifObjVector.size(); i++) ...;`. It is available in Intel compiler and in GCC 4.9. See also TBB for cross-platform, compiler-independent library – Anton Sep 16 '14 at 15:26
  • You do not install openMP. It is a part of the compiler. gcc supports it. – Totonga Sep 16 '14 at 16:01
  • I have seen it. But I have a problem: invalid controlling predicate because of vector::const_iterator maybe... any help? – sop Sep 16 '14 at 16:02
  • @sop : http://stackoverflow.com/a/17576247/420446 – willll Sep 16 '14 at 17:25

0 Answers0