diff --git a/LPC/Sound_to_Formant_mt.cpp b/LPC/Sound_to_Formant_mt.cpp index 5b16cc500..0885c5d07 100644 --- a/LPC/Sound_to_Formant_mt.cpp +++ b/LPC/Sound_to_Formant_mt.cpp @@ -16,6 +16,7 @@ * along with this work. If not, see . */ +#include #include "Sound_to_Formant_mt.h" #include "SoundToFormantWorkspace.h" #include "Sound_extensions.h" @@ -120,6 +121,4 @@ autoFormant Sound_to_Formant_robust_mt (constSound me, double dt_in, double numb } } - - /* End of file Sound_to_Formant_mt.cpp */ diff --git a/dwtools/SampledToSampledWorkspace.cpp b/dwtools/SampledToSampledWorkspace.cpp index 170445c31..d4636403e 100644 --- a/dwtools/SampledToSampledWorkspace.cpp +++ b/dwtools/SampledToSampledWorkspace.cpp @@ -18,6 +18,7 @@ #include "Preferences.h" #include "SampledToSampledWorkspace.h" +#include "Sound_and_LPC.h" #include "Sound_extensions.h" #include #include @@ -45,7 +46,8 @@ Thing_implement (SampledToSampledWorkspace, Daata, 0); -static struct { + +static struct ThreadingPreferences { bool useMultiThreading = true; integer numberOfConcurrentThreadsAvailable = 20; integer numberOfConcurrentThreadsToUse = 20; @@ -247,4 +249,51 @@ void SampledToSampledWorkspace_analyseThreaded (mutableSampledToSampledWorkspace } } +void timeMultiThreading (double soundDuration) { + try { + Melder_require (preferences.numberOfConcurrentThreadsAvailable > 1, + U"No multi-threading possible."); + /* + Save current situation + */ + struct ThreadingPreferences savedPreferences = preferences; + autoVEC framesPerThread {50, 100, 200, 400, 800, 1600, 3200}; + const integer maximumNumberOfThreads = std::thread::hardware_concurrency (); + autoSound me = Sound_createSimple (1_integer, soundDuration, 5500.0); + for (integer i = 1; i <= my nx; i++) { + const double time = my x1 + (i - 1) * my dx; + my z[1][i] = sin(2.0 * NUMpi * 377 * time) + NUMrandomGauss (0.0, 0.1); + } + preferences.useMultiThreading = true; + const int predictionOrder = 10; + const double effectiveAnalysisWidth = 0.025, dt = 0.05, preEmphasisFrequency = 50; + autoMelderProgress progress (U"Test multi-threading times..."); + Melder_clearInfo (); + MelderInfo_writeLine (U"duration(s) nThread frames/thread toLPC(s)"); + integer numberOfThreads = maximumNumberOfThreads; + for (integer nThread = 1; nThread <= maximumNumberOfThreads; nThread ++) { + preferences.numberOfConcurrentThreadsToUse = nThread; + for (integer index = 1; index <= framesPerThread.size; index ++) { + const integer numberOfFramesPerThread = framesPerThread [index]; + preferences.maximumNumberOfFramesPerThread = numberOfFramesPerThread; + preferences.minimumNumberOfFramesPerThread = numberOfFramesPerThread; + Melder_stopwatch (); + autoLPC lpc = Sound_to_LPC_burg (me.get(), predictionOrder, effectiveAnalysisWidth, dt, preEmphasisFrequency); + double t = Melder_stopwatch (); + MelderInfo_writeLine (soundDuration, U" ", nThread, U" ", numberOfFramesPerThread, U" ", t); + } + MelderInfo_drain (); + try { + Melder_progress (((double) nThread) / maximumNumberOfThreads, U"Number of threads: ", nThread); + } catch (MelderError) { + numberOfThreads = nThread; + Melder_clearError (); + break; + } + } + MelderInfo_close (); + } catch (MelderError) { + Melder_throw (U"Could not perform timing."); + } +} /* End of file SampledToSampledWorkspace.cpp */ diff --git a/dwtools/SampledToSampledWorkspace.h b/dwtools/SampledToSampledWorkspace.h index 49b4195d6..074286677 100644 --- a/dwtools/SampledToSampledWorkspace.h +++ b/dwtools/SampledToSampledWorkspace.h @@ -95,5 +95,7 @@ void SampledToSampledWorkspace_setMinimumNumberOfFramesPerThread (integer minimu void SampledToSampledWorkspace_getThreadingInfo (constSampledToSampledWorkspace me, integer *out_numberOfThreadsNeeded, integer *out_numberOfFramesPerThread); +void timeMultiThreading (double soundDuration); + #endif /* _SampledToSampledWorkspace_h_ */ diff --git a/fon/Praat_tests.cpp b/fon/Praat_tests.cpp index 0bd0378a1..d79b4d629 100644 --- a/fon/Praat_tests.cpp +++ b/fon/Praat_tests.cpp @@ -23,6 +23,7 @@ /* 5 June 2015: char32 */ #include "FileInMemory.h" +#include "SampledToSampledWorkspace.h" #include "Praat_tests.h" #include "Graphics.h" @@ -663,6 +664,12 @@ int Praat_tests (kPraatTests itest, conststring32 arg1, conststring32 arg2, cons //Melder_throw (U"Cannot test FileInMemoryManager directly from Praat."); test_FileInMemory_io (); } break; + case kPraatTests::TIME_MULTI_THREADING: { + const double durationOfSound = ( n < 0 ? 5.0 : 100.0 ); + timeMultiThreading (durationOfSound); + // Gflops is --undefined-- + } break; + } MelderInfo_writeLine (Melder_single (n / t * 1e-9), U" Gflop/s"); MelderInfo_close (); diff --git a/fon/Praat_tests_enums.h b/fon/Praat_tests_enums.h index 9cbe8d6ef..84010b658 100644 --- a/fon/Praat_tests_enums.h +++ b/fon/Praat_tests_enums.h @@ -62,6 +62,7 @@ enums_begin (kPraatTests, 0) enums_add (kPraatTests, 42, TIME_MATMUL, U"TimeMatMul") enums_add (kPraatTests, 43, THING_AUTO, U"ThingAuto") enums_add (kPraatTests, 44, FILEINMEMORY_IO, U"FileInMemory_io") -enums_end (kPraatTests, 44, CHECK_RANDOM_1009_2009) + enums_add (kPraatTests, 45, TIME_MULTI_THREADING, U"TimeMultiThreading") +enums_end (kPraatTests, 45, CHECK_RANDOM_1009_2009) /* End of file Praat_tests_enums.h */