Mercurial > hg > silvet
changeset 312:796d403dc83b
Replace OpenMP usage with (hopefully more portable) C++11 async. Define MAX_EM_THREADS=1 if you don't want to use it.
author | Chris Cannam |
---|---|
date | Tue, 28 Apr 2015 10:02:36 +0100 |
parents | 99af9557dfc1 |
children | fa2ffbb786df |
files | Makefile.linux src/Silvet.cpp |
diffstat | 2 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.linux Tue Apr 28 09:41:40 2015 +0100 +++ b/Makefile.linux Tue Apr 28 10:02:36 2015 +0100 @@ -1,12 +1,12 @@ -CFLAGS := -Wall -O3 -ffast-math -msse -msse2 -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/ -DUSE_PTHREADS +CFLAGS := -Wall -O3 -ffast-math -msse -msse2 -mfpmath=sse -ftree-vectorize -fPIC -I../vamp-plugin-sdk/ #CFLAGS := -g -fPIC -I../vamp-plugin-sdk CXXFLAGS := $(CFLAGS) -std=c++11 VAMPSDK_DIR := ../vamp-plugin-sdk -PLUGIN_LDFLAGS := -shared -Wl,-Bsymbolic -Wl,-z,defs -Wl,--version-script=vamp-plugin.map -lpthread +PLUGIN_LDFLAGS := -shared -Wl,-Bsymbolic -Wl,-z,defs -Wl,--version-script=vamp-plugin.map PLUGIN_EXT := .so
--- a/src/Silvet.cpp Tue Apr 28 09:41:40 2015 +0100 +++ b/src/Silvet.cpp Tue Apr 28 10:02:36 2015 +0100 @@ -23,6 +23,7 @@ #include "flattendynamics-ladspa.h" #include <vector> +#include <future> #include <cstdio> @@ -31,6 +32,8 @@ using std::cerr; using std::endl; using std::pair; +using std::future; +using std::async; using Vamp::RealTime; static int processingSampleRate = 44100; @@ -555,12 +558,36 @@ localBestShifts = vector<vector<int> >(width); } +#ifndef MAX_EM_THREADS +#define MAX_EM_THREADS 8 +#endif + +#if (defined(MAX_EM_THREADS) && (MAX_EM_THREADS > 1)) + for (int i = 0; i < width; ) { + typedef future<pair<vector<double>, vector<int>>> EMFuture; + vector<EMFuture> results; + for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { + results.push_back + (async(std::launch::async, + [&](int index) { + return applyEM(pack, filtered.at(index), wantShifts); + }, i + j)); + } + for (int j = 0; j < MAX_EM_THREADS && i + j < width; ++j) { + auto out = results[j].get(); + localPitches[i+j] = out.first; + if (wantShifts) localBestShifts[i+j] = out.second; + } + i += MAX_EM_THREADS; + } +#else for (int i = 0; i < width; ++i) { auto out = applyEM(pack, filtered.at(i), wantShifts); localPitches[i] = out.first; if (wantShifts) localBestShifts[i] = out.second; } - +#endif + for (int i = 0; i < width; ++i) { // This returns a filtered column, and pushes the