Mercurial > hg > silvet
comparison src/Silvet.cpp @ 352:a3fc6e1f2d4e
Restore threads stuff -- the host needs to be compiled with threading
author | Chris Cannam |
---|---|
date | Thu, 03 Sep 2015 12:06:31 +0100 |
parents | 071fd5e7b168 |
children | 7dcff010d9cd |
comparison
equal
deleted
inserted
replaced
351:34357aeab3ad | 352:a3fc6e1f2d4e |
---|---|
725 vector<vector<int> > localBestShifts; | 725 vector<vector<int> > localBestShifts; |
726 if (wantShifts) { | 726 if (wantShifts) { |
727 localBestShifts = vector<vector<int> >(width); | 727 localBestShifts = vector<vector<int> >(width); |
728 } | 728 } |
729 | 729 |
730 #ifndef MAX_EM_THREADS | |
731 #define MAX_EM_THREADS 8 | |
732 #endif | |
733 | |
734 int emThreadCount = MAX_EM_THREADS; | 730 int emThreadCount = MAX_EM_THREADS; |
731 if (emThreadCount > int(std::thread::hardware_concurrency())) { | |
732 emThreadCount = std::thread::hardware_concurrency(); | |
733 } | |
735 if (m_mode == LiveMode && pack.templates.size() == 1) { | 734 if (m_mode == LiveMode && pack.templates.size() == 1) { |
736 // The EM step is probably not slow enough to merit it | 735 // The EM step is probably not slow enough to merit it |
737 emThreadCount = 1; | 736 emThreadCount = 1; |
738 } | 737 } |
739 | 738 |
741 if (emThreadCount > 1) { | 740 if (emThreadCount > 1) { |
742 for (int i = 0; i < width; ) { | 741 for (int i = 0; i < width; ) { |
743 typedef future<pair<vector<double>, vector<int>>> EMFuture; | 742 typedef future<pair<vector<double>, vector<int>>> EMFuture; |
744 vector<EMFuture> results; | 743 vector<EMFuture> results; |
745 for (int j = 0; j < emThreadCount && i + j < width; ++j) { | 744 for (int j = 0; j < emThreadCount && i + j < width; ++j) { |
746 cerr << "creating future " << j << " (i = " << i << ", width = " << width << ")" << endl; | 745 const vector<double> &column = filtered.at(i + j); |
747 results.push_back | 746 results.push_back |
748 (async(std::launch::async, | 747 (async(std::launch::async, |
749 [&](int index) { | 748 [&]() { return applyEM(pack, column); })); |
750 return applyEM(pack, filtered.at(index)); | |
751 }, i + j)); | |
752 } | 749 } |
753 for (int j = 0; j < emThreadCount && i + j < width; ++j) { | 750 for (int j = 0; j < emThreadCount && i + j < width; ++j) { |
754 cerr << "reaping future " << j << " (i = " << i << ", width = " << width << ")" << endl; | |
755 auto out = results[j].get(); | 751 auto out = results[j].get(); |
756 localPitches[i+j] = out.first; | 752 localPitches[i+j] = out.first; |
757 if (wantShifts) localBestShifts[i+j] = out.second; | 753 if (wantShifts) localBestShifts[i+j] = out.second; |
758 } | 754 } |
759 i += emThreadCount; | 755 i += emThreadCount; |