# HG changeset patch # User Chris Cannam # Date 1430211756 -3600 # Node ID 796d403dc83b76d65d115a9dd0bc8482a3b7898f # Parent 99af9557dfc11f043b5bc8870981858f007d5150 Replace OpenMP usage with (hopefully more portable) C++11 async. Define MAX_EM_THREADS=1 if you don't want to use it. diff -r 99af9557dfc1 -r 796d403dc83b Makefile.linux --- 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 diff -r 99af9557dfc1 -r 796d403dc83b src/Silvet.cpp --- 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 +#include #include @@ -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 >(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, vector>> EMFuture; + vector 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