Skip to content

Commit

Permalink
timeMultiThreading in Praat_test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidweenink committed Nov 7, 2024
1 parent 22985b2 commit fd6860d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
3 changes: 1 addition & 2 deletions LPC/Sound_to_Formant_mt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this work. If not, see <http://www.gnu.org/licenses/>.
*/

#include <thread>
#include "Sound_to_Formant_mt.h"
#include "SoundToFormantWorkspace.h"
#include "Sound_extensions.h"
Expand Down Expand Up @@ -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 */
51 changes: 50 additions & 1 deletion dwtools/SampledToSampledWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "Preferences.h"
#include "SampledToSampledWorkspace.h"
#include "Sound_and_LPC.h"
#include "Sound_extensions.h"
#include <thread>
#include <atomic>
Expand Down Expand Up @@ -45,7 +46,8 @@

Thing_implement (SampledToSampledWorkspace, Daata, 0);

static struct {

static struct ThreadingPreferences {
bool useMultiThreading = true;
integer numberOfConcurrentThreadsAvailable = 20;
integer numberOfConcurrentThreadsToUse = 20;
Expand Down Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions dwtools/SampledToSampledWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

7 changes: 7 additions & 0 deletions fon/Praat_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/* 5 June 2015: char32 */

#include "FileInMemory.h"
#include "SampledToSampledWorkspace.h"
#include "Praat_tests.h"

#include "Graphics.h"
Expand Down Expand Up @@ -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 ();
Expand Down
3 changes: 2 additions & 1 deletion fon/Praat_tests_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit fd6860d

Please sign in to comment.