Skip to content

Commit

Permalink
Now process all deltas in a single OnTimer call to avoid wasting time…
Browse files Browse the repository at this point in the history
… idle. See #452.
  • Loading branch information
azonenberg committed Jul 7, 2022
1 parent 136bb12 commit ee763ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
30 changes: 6 additions & 24 deletions src/glscopeclient/ScopeSyncWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* glscopeclient *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* Copyright (c) 2012-2022 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
Expand Down Expand Up @@ -187,7 +187,6 @@ ScopeSyncWizard::ScopeSyncWizard(OscilloscopeWindow* parent)
, m_bestCorrelation(0)
, m_primaryWaveform(0)
, m_secondaryWaveform(0)
, m_delta(0)
, m_maxSkewSamples(0)
, m_numAverages(10)
, m_shuttingDown(false)
Expand Down Expand Up @@ -409,8 +408,6 @@ void ScopeSyncWizard::OnWaveformDataReady()
m_maxSkewSamples = static_cast<int64_t>(pw->m_offsets.size() / 2);
m_maxSkewSamples = min(m_maxSkewSamples, static_cast<int64_t>(10000LL));

m_delta = - m_maxSkewSamples;

//Set the timer
Glib::signal_timeout().connect(sigc::mem_fun(*this, &ScopeSyncWizard::OnTimer), 10);
}
Expand All @@ -421,26 +418,16 @@ bool ScopeSyncWizard::OnTimer()
int64_t len = m_primaryWaveform->m_offsets.size();
size_t slen = m_secondaryWaveform->m_offsets.size();

int64_t samplesPerBlock = 5000;
int64_t blockEnd = min(m_delta + samplesPerBlock, len/2);
blockEnd = min(blockEnd, m_maxSkewSamples);

//Update the progress bar
float blockfrac = m_averageSkews.size() * 1.0f / m_numAverages;
int64_t blockpos = m_delta + m_maxSkewSamples;
float infrac = blockpos * 1.0f / (2*m_maxSkewSamples);
float frac = blockfrac + infrac/m_numAverages;
float progress = (frac * 0.9) + 0.1;
m_activeSecondaryPage->m_progressBar.set_text("Cross-correlate skew reference waveform");
m_activeSecondaryPage->m_progressBar.set_fraction(progress);

std::mutex cmutex;

//Optimized path (if both waveforms are dense packed)
if(m_primaryWaveform->m_densePacked && m_secondaryWaveform->m_densePacked)
{
//TODO: Loop over samples first, then offsets inside that
//for better cache locality

#pragma omp parallel for
for(int64_t d = m_delta; d < blockEnd; d ++)
for(int64_t d = -m_maxSkewSamples; d < m_maxSkewSamples; d ++)
{
//Convert delta from samples of the primary waveform to femtoseconds
int64_t deltaFs = m_primaryWaveform->m_timescale * d;
Expand Down Expand Up @@ -501,7 +488,7 @@ bool ScopeSyncWizard::OnTimer()
else
{
#pragma omp parallel for
for(int64_t d = m_delta; d < blockEnd; d ++)
for(int64_t d = -m_maxSkewSamples; d < m_maxSkewSamples; d ++)
{
//Convert delta from samples of the primary waveform to femtoseconds
int64_t deltaFs = m_primaryWaveform->m_timescale * d;
Expand Down Expand Up @@ -557,11 +544,6 @@ bool ScopeSyncWizard::OnTimer()
}
}
}
m_delta = blockEnd;

//Need more data to go on
if(m_delta < m_maxSkewSamples)
return true;

//Collect the skew from this round
auto scope = m_activeSecondaryPage->GetScope();
Expand Down
3 changes: 1 addition & 2 deletions src/glscopeclient/ScopeSyncWizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* *
* glscopeclient *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* Copyright (c) 2012-2022 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
Expand Down Expand Up @@ -136,7 +136,6 @@ class ScopeSyncWizard : public Gtk::Assistant
double m_bestCorrelation;
AnalogWaveform* m_primaryWaveform;
AnalogWaveform* m_secondaryWaveform;
int64_t m_delta;
int64_t m_maxSkewSamples;
std::vector<int64_t> m_averageSkews;
size_t m_numAverages;
Expand Down

0 comments on commit ee763ad

Please sign in to comment.