| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include <iostream> | ||
| 8 | #include <string> | ||
| 9 | #include <chrono> | ||
| 10 | #include <thread> | ||
| 11 | #include <sstream> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "phoenix_assert.h" | ||
| 15 | #include "PMultiThreadProgress.h" | ||
| 16 | |||
| 17 | ///Fake data computing | ||
| 18 | /** @param progress : multiple progress bar | ||
| 19 | * @param vecComputeData : vector of compute data | ||
| 20 | * @param threadIndex : index of the thread | ||
| 21 | */ | ||
| 22 | 1 | void fake_compute_data(PMultiThreadProgress & progress, const std::vector<int> & vecComputeData, size_t threadIndex){ | |
| 23 | //Simulate computation which depends on input data | ||
| 24 |
2/2✓ Branch 0 (33→3) taken 3 times.
✓ Branch 1 (33→34) taken 1 times.
|
8 | for(std::vector<int>::const_iterator it(vecComputeData.begin()); it != vecComputeData.end(); ++it){ |
| 25 | 3 | size_t computeData(*it); | |
| 26 |
1/1✓ Branch 0 (5→6) taken 3 times.
|
3 | std::stringstream name; |
| 27 |
4/4✓ Branch 0 (6→7) taken 3 times.
✓ Branch 2 (7→8) taken 3 times.
✓ Branch 4 (8→9) taken 3 times.
✓ Branch 6 (9→10) taken 3 times.
|
3 | name << "Some computing of thread index " << threadIndex << " compute data " << computeData; |
| 28 | //Start the progress bar | ||
| 29 |
3/3✓ Branch 0 (10→11) taken 3 times.
✓ Branch 2 (11→12) taken 3 times.
✓ Branch 4 (12→13) taken 3 times.
|
3 | size_t indexProgressBar = progress.addProgressBar(name.str(), computeData); |
| 30 | |||
| 31 |
2/2✓ Branch 0 (20→16) taken 12 times.
✓ Branch 1 (20→21) taken 3 times.
|
15 | for(size_t i(0lu); i < computeData; ++i){ //Simulate some avancement |
| 32 |
1/1✓ Branch 0 (16→17) taken 12 times.
|
12 | progress.incrementProgress(indexProgressBar); //Update the progress bar |
| 33 |
1/1✓ Branch 0 (18→19) taken 12 times.
|
12 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); //Simulate computation |
| 34 | } | ||
| 35 | //Say the computation is finished | ||
| 36 |
1/1✓ Branch 0 (21→22) taken 3 times.
|
3 | progress.incrementProgress(indexProgressBar); |
| 37 | 3 | } | |
| 38 | 1 | } | |
| 39 | |||
| 40 | 1 | int main(){ | |
| 41 | 1 | size_t nbValuePerThread(3lu), nbThread(1lu); | |
| 42 | 1 | size_t nbValue(nbValuePerThread*nbThread); | |
| 43 | 1 | std::vector<std::vector<int> > vecComputeData; | |
| 44 |
2/2✓ Branch 0 (12→4) taken 1 times.
✓ Branch 1 (12→13) taken 1 times.
|
2 | for(size_t i(0lu); i < nbThread; ++i){ |
| 45 | 1 | std::vector<int> vecDataPerThread; | |
| 46 |
2/2✓ Branch 0 (8→6) taken 3 times.
✓ Branch 1 (8→9) taken 1 times.
|
4 | for(size_t j(0lu); j < nbValuePerThread; ++j){ |
| 47 | 3 | size_t index(i*nbValuePerThread + j); | |
| 48 |
1/1✓ Branch 0 (6→7) taken 3 times.
|
3 | vecDataPerThread.push_back(3lu + ((index*11lu)%5lu)); |
| 49 | } | ||
| 50 |
1/1✓ Branch 0 (9→10) taken 1 times.
|
1 | vecComputeData.push_back(vecDataPerThread); |
| 51 | 1 | } | |
| 52 |
2/2✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
|
1 | std::cout << "Start computation" << std::endl; |
| 53 | |||
| 54 |
1/1✓ Branch 0 (15→16) taken 1 times.
|
1 | PMultiThreadProgress progress(nbValue); |
| 55 | |||
| 56 | 1 | std::vector<std::thread> vecThread; | |
| 57 |
1/1✓ Branch 0 (17→18) taken 1 times.
|
1 | vecThread.resize(nbThread); |
| 58 | |||
| 59 |
1/1✓ Branch 0 (19→20) taken 1 times.
|
1 | std::thread threadProgress(phoenix_print_parallel_progress, std::ref(progress), 1); |
| 60 |
2/2✓ Branch 0 (28→21) taken 1 times.
✓ Branch 1 (28→29) taken 1 times.
|
2 | for(size_t i(0lu); i < nbThread; ++i){ |
| 61 |
1/1✓ Branch 0 (23→24) taken 1 times.
|
1 | vecThread[i] = std::thread(fake_compute_data, std::ref(progress), vecComputeData[i], i); |
| 62 | } | ||
| 63 |
1/1✓ Branch 0 (29→30) taken 1 times.
|
1 | threadProgress.join(); |
| 64 |
2/2✓ Branch 0 (34→31) taken 1 times.
✓ Branch 1 (34→35) taken 1 times.
|
2 | for(size_t i(0lu); i < nbThread; ++i){ |
| 65 |
1/1✓ Branch 0 (32→33) taken 1 times.
|
1 | vecThread[i].join(); |
| 66 | } | ||
| 67 |
2/2✓ Branch 0 (35→36) taken 1 times.
✓ Branch 2 (36→37) taken 1 times.
|
1 | std::cout << "Done" << std::endl; |
| 68 | 1 | return 0; | |
| 69 | 1 | } | |
| 70 | |||
| 71 | |||
| 72 |