The following commit has been merged in the master branch:
commit 9422b1e7fb7b7d150160736194cd56ce1c1d0990
Author: andrei zavada <[email protected]>
Date:   Sun Oct 21 03:22:20 2012 +0300

    WIP

diff --git a/data/main.glade b/data/main.glade
index ccc085b..9745216 100644
--- a/data/main.glade
+++ b/data/main.glade
@@ -349,7 +349,6 @@
     <property name="page_increment">0.5</property>
   </object>
   <object class="GtkAdjustment" id="jMsmtOpFreqFrom">
-    <property name="lower">0.25</property>
     <property name="upper">60</property>
     <property name="value">2</property>
     <property name="step_increment">0.25</property>
@@ -374,6 +373,11 @@
     <property name="step_increment">1</property>
     <property name="page_increment">5</property>
   </object>
+  <object class="GtkAdjustment" id="jSMPMaxThreads">
+    <property name="upper">16</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkAdjustment" id="jUltradianCycleDetectionAccuracy">
     <property name="lower">0.5</property>
     <property name="upper">20</property>
@@ -693,7 +697,6 @@ rm */*/*/.*.{psd,mc}</property>
                                                     <property 
name="can_focus">False</property>
                                                     <child>
                                                       <object 
class="GtkMenuItem" id="iMontageSetDefaults">
-                                                        <property 
name="visible">True</property>
                                                         <property 
name="can_focus">False</property>
                                                         <property name="label" 
translatable="yes">Set _defaults...</property>
                                                         <property 
name="use_underline">True</property>
@@ -1601,9 +1604,6 @@ rm */*/*/.*.{psd,mc}</property>
                           <placeholder/>
                         </child>
                         <child>
-                          <placeholder/>
-                        </child>
-                        <child>
                           <object class="GtkFrame" 
id="fFreqConventionalRanges">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
@@ -2376,6 +2376,80 @@ rm */*/*/.*.{psd,mc}</property>
                             <property name="bottom_attach">2</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkFrame" id="fSMP">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="halign">start</property>
+                            <property name="valign">start</property>
+                            <property name="border_width">5</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <object class="GtkTable" id="table29">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="border_width">10</property>
+                                <property name="n_columns">3</property>
+                                <property name="column_spacing">10</property>
+                                <property name="row_spacing">10</property>
+                                <child>
+                                  <object class="GtkLabel" id="label6">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="xalign">1</property>
+                                    <property name="label" 
translatable="yes">_Max threads to use: </property>
+                                    <property 
name="use_underline">True</property>
+                                    <property 
name="mnemonic_widget">eArtifDampenFactor</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkSpinButton" 
id="eSMPMaxThreads">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="has_frame">False</property>
+                                    <property 
name="invisible_char">•</property>
+                                    <property name="xalign">1</property>
+                                    <property 
name="shadow_type">none</property>
+                                    <property 
name="invisible_char_set">True</property>
+                                    <property 
name="adjustment">jSMPMaxThreads</property>
+                                    <property name="numeric">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label5">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" 
translatable="yes">(0 = all available)</property>
+                                    <attributes>
+                                      <attribute name="scale" 
value="0.90000000000000002"/>
+                                    </attributes>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">2</property>
+                                    <property name="right_attach">3</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label7">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" 
translatable="yes">&lt;b&gt;&lt;big&gt;SMP&lt;/big&gt;&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="left_attach">2</property>
+                            <property name="right_attach">3</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                     <child type="tab">
@@ -6692,6 +6766,12 @@ EEG microcontinuity algorithm. Read more &lt;a 
href="http://johnhommer.com/acade
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </object>
                         </child>
                         <child>
diff --git a/src/common/globals.hh b/src/common/globals.hh
index d6de34c..37148b2 100644
--- a/src/common/globals.hh
+++ b/src/common/globals.hh
@@ -27,6 +27,7 @@ namespace global {
 extern gsl_rng *rng;
 void init_rng();
 
+extern int num_procs;
 
 // typedef std::valarray<TFloat> VAF;
 
diff --git a/src/common/libcommon.cc b/src/common/libcommon.cc
index 3f2ca43..b7a1bed 100644
--- a/src/common/libcommon.cc
+++ b/src/common/libcommon.cc
@@ -210,4 +210,9 @@ init_rng()
        rng = gsl_rng_alloc( T);
 }
 
+
+
+
+int agh::global::num_procs = 1;
+
 // eof
diff --git a/src/expdesign/primaries.cc b/src/expdesign/primaries.cc
index d5cc114..ceb43f9 100644
--- a/src/expdesign/primaries.cc
+++ b/src/expdesign/primaries.cc
@@ -16,7 +16,11 @@
 #include <string>
 #include <fstream>
 
-//#include "../common/lang.hh"
+#ifdef _OPENMP
+#include <omp.h>
+#endif
+
+#include "../common/globals.hh"
 #include "../common/config-validate.hh"
 #include "primaries.hh"
 
@@ -29,7 +33,8 @@ using namespace agh;
 agh::CExpDesign::
 CExpDesign (const string& session_dir_,
            TMsmtCollectProgressIndicatorFun progress_fun)
-      : af_dampen_window_type (sigfile::SFFTParamSet::TWinType::welch),
+      : num_threads (0),
+       af_dampen_window_type (sigfile::SFFTParamSet::TWinType::welch),
        af_dampen_factor (.95),
        tunables0 (tstep, tlo, thi),
        _id_pool (0),
@@ -48,6 +53,7 @@ CExpDesign (const string& session_dir_,
                confval::SValidator<double>("mcparam.iir_backpolate",   
&mc_params.iir_backpolate,                      
confval::SValidator<double>::SVFRangeIn( 0., 1.)),
        }),
        config_keys_d ({
+               confval::SValidator<int>("smp.num_threads",             
&num_threads,                                   
confval::SValidator<int>::SVFRangeIn( 0, 20)),
                confval::SValidator<int>("fftparam.WelchWindowType",    
(int*)&fft_params.welch_window_type,            
confval::SValidator<int>::SVFRangeIn( 0, 
(int)sigfile::SFFTParamSet::TWinType::_total - 1)),
                confval::SValidator<int>("artifacts.DampenWindowType",  
(int*)&af_dampen_window_type,                   
confval::SValidator<int>::SVFRangeIn( 0, 
(int)sigfile::SFFTParamSet::TWinType::_total - 1)),
                confval::SValidator<int>("ctlparam.ItersFixedT",        
&ctl_params0.siman_params.iters_fixed_T,        
confval::SValidator<int>::SVFRangeIn( 1, 1000000)),
@@ -89,6 +95,10 @@ CExpDesign (const string& session_dir_,
 
        mc_params.scope = fft_params.pagesize;
 
+#ifdef _OPENMP
+       omp_set_num_threads( (num_threads == 0) ? agh::global::num_procs : 
num_threads);
+       printf( "SMP enabled with %d threads\n", omp_get_max_threads());
+#endif
        scan_tree( progress_fun);
 }
 
@@ -126,16 +136,22 @@ for_all_subjects( const TSubjectOpFun& F, const 
TSubjectReportFun& report, const
                        if ( filter(J) )
                                v.emplace_back( make_tuple(&G.second, &J));
        size_t global_i = 0;
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
        for ( size_t i = 0; i < v.size(); ++i ) {
+#ifdef _OPENMP
 #pragma omp critical
+#endif
                {
                        report( *get<0>(v[i]), *get<1>(v[i]),
                                ++global_i, v.size());
                }
                F( *get<1>(v[i]));
        }
+#ifdef _OPENMP
 #pragma omp barrier
+#endif
 }
 
 
@@ -154,16 +170,22 @@ for_all_episodes( const TEpisodeOpFun& F, const 
TEpisodeReportFun& report, const
                                        if ( filter(E) )
                                                v.emplace_back( 
make_tuple(&G.second, &J, &M.first, &E));
        size_t global_i = 0;
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
        for ( size_t i = 0; i < v.size(); ++i ) {
+#ifdef _OPENMP
 #pragma omp critical
+#endif
                {
                        report( *get<0>(v[i]), *get<1>(v[i]), *get<2>(v[i]), 
*get<3>(v[i]),
                                ++global_i, v.size());
                }
                F( *get<3>(v[i]));
        }
+#ifdef _OPENMP
 #pragma omp barrier
+#endif
 }
 
 
@@ -187,16 +209,22 @@ for_all_recordings( const TRecordingOpFun& F, const 
TRecordingReportFun& report,
                                                                            &E,
                                                                            
&R.second));
        size_t global_i = 0;
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
        for ( size_t i = 0; i < v.size(); ++i ) {
+#ifdef _OPENMP
 #pragma omp critical
+#endif
                {
                        report( *get<0>(v[i]), *get<1>(v[i]), *get<2>(v[i]), 
*get<3>(v[i]), *get<4>(v[i]),
                                ++global_i, v.size());
                }
                F( *get<4>(v[i]));
        }
+#ifdef _OPENMP
 #pragma omp barrier
+#endif
 }
 
 void
@@ -225,16 +253,22 @@ for_all_modruns( const TModelRunOpFun& F, const 
TModelRunReportFun& report, cons
                                                                                
&Q.first,
                                                                                
&Q.second));
        size_t global_i = 0;
+#ifdef _OPENMP
 #pragma omp parallel for
+#endif
        for ( size_t i = 0; i < v.size(); ++i ) {
+#ifdef _OPENMP
 #pragma omp critical
+#endif
                {
                        report( *get<0>(v[i]), *get<1>(v[i]), *get<2>(v[i]), 
*get<3>(v[i]), *get<4>(v[i]), *get<5>(v[i]), *get<6>(v[i]),
                                ++global_i, v.size());
                }
                F( *get<6>(v[i]));
        }
+#ifdef _OPENMP
 #pragma omp barrier
+#endif
 }
 
 
diff --git a/src/expdesign/primaries.hh b/src/expdesign/primaries.hh
index 51437bb..c1a81b1 100644
--- a/src/expdesign/primaries.hh
+++ b/src/expdesign/primaries.hh
@@ -427,6 +427,7 @@ class CExpDesign {
        for_all_modruns( const TModelRunOpFun&, const TModelRunReportFun&, 
const TModelRunFilterFun&);
 
       // inventory
+       int     num_threads;
        sigfile::SFFTParamSet
                fft_params;
        sigfile::SMCParamSet
diff --git a/src/main.cc b/src/main.cc
index 3b287cd..daa41d0 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -12,6 +12,9 @@
 
 
 
+#ifdef _OPENMP
+#include <omp.h>
+#endif
 
 #include <gtk/gtk.h>
 #include <unique/unique.h>
@@ -84,6 +87,9 @@ main( int argc, char **argv)
                                  NULL);
 
                agh::global::init_rng();
+#ifdef _OPENMP
+               agh::global::num_procs = omp_get_max_threads();
+#endif
                if ( aghui::prepare_for_expdesign() ) {
                        aghui::pop_ok_message( NULL, "UI failed to initialize", 
"Your install is broken.");
                        return 2;
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 025eccc..fc31bd8 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -1,7 +1,8 @@
 AM_CXXFLAGS = \
        -std=c++0x -Wdeprecated-declarations \
        $(GTK_CFLAGS) $(LIBCONFIGXX_CFLAGS) \
-       -DPACKAGE_DATADIR=\"$(datadir)\"
+       -DPACKAGE_DATADIR=\"$(datadir)\" \
+       $(OPENMP_CXXFLAGS)
 
 noinst_LIBRARIES = libaghui.a
 
diff --git a/src/ui/ed-construct.cc b/src/ui/ed-construct.cc
index 583849f..80f8f8b 100644
--- a/src/ui/ed-construct.cc
+++ b/src/ui/ed-construct.cc
@@ -387,7 +387,7 @@ SExpDesignUIWidgets ()
             !AGH_GBGETOBJ (GtkLabel, lSimulationsSession) )
                throw runtime_error ("Failed to construct widgets");
 
-    // ======= statusbar
+      // ------- statusbar
        if ( !AGH_GBGETOBJ (GtkStatusbar,       sbMainStatusBar) )
                throw runtime_error ("Failed to construct widgets");
 
@@ -401,11 +401,12 @@ SExpDesignUIWidgets ()
        // free? unref? leak some?
 
       // ****************** settings
-      // ------------- fFFTParams
-       if ( !AGH_GBGETOBJ (GtkSpinButton,      
eUltradianCycleDetectionAccuracy) )
+       if ( !AGH_GBGETOBJ (GtkSpinButton,      eSMPMaxThreads) )
                throw runtime_error ("Failed to construct widgets");
 
-       if ( !AGH_GBGETOBJ (GtkComboBox,        eFFTParamsBinSize) ||
+      // ------------- fFFTParams
+       if ( !AGH_GBGETOBJ (GtkSpinButton,      
eUltradianCycleDetectionAccuracy) ||
+            !AGH_GBGETOBJ (GtkComboBox,        eFFTParamsBinSize) ||
             !AGH_GBGETOBJ (GtkComboBox,        eFFTParamsPageSize) ||
             !AGH_GBGETOBJ (GtkComboBox,        eFFTParamsWindowType) )
                throw runtime_error ("Failed to construct widgets");
diff --git a/src/ui/ed-populate.cc b/src/ui/ed-populate.cc
index 0999358..c421b16 100644
--- a/src/ui/ed-populate.cc
+++ b/src/ui/ed-populate.cc
@@ -59,7 +59,7 @@ populate( bool do_load)
                printf( "* single common EEG samplerate: %zu\n", 
used_eeg_samplerates.front());
        else
                printf( "* multiple EEG samplerates (%zu)\n", 
used_eeg_samplerates.size());
-       printf( "* global AD profils: %zu\n", 
global_artifact_detection_profiles.size());
+       printf( "* global AD profiles: %zu\n", 
global_artifact_detection_profiles.size());
 
        if ( do_load ) {
                if ( load_settings() )
diff --git a/src/ui/ed-settings_cb.cc b/src/ui/ed-settings_cb.cc
index ec0c96c..9a856ef 100644
--- a/src/ui/ed-settings_cb.cc
+++ b/src/ui/ed-settings_cb.cc
@@ -11,6 +11,11 @@
  */
 
 
+#ifdef _OPENMP
+#include <omp.h>
+#endif
+
+#include "../common/globals.hh"
 #include "../common/string.hh"
 #include "misc.hh"
 #include "ed.hh"
@@ -55,6 +60,10 @@ tDesign_switch_page_cb( GtkNotebook*, gpointer, guint 
page_num, gpointer userdat
 
                ED.adjust_op_freq_spinbuttons();
 
+#ifdef _OPENMP
+               omp_set_num_threads( (ED.ED->num_threads == 0) ? 
agh::global::num_procs : ED.ED->num_threads);
+               printf( "SMP enabled with %d thread(s)\n", 
omp_get_max_threads());
+#endif
              // scan as necessary
                if ( ED.pagesize_item_saved                     != 
ED.pagesize_item ||
                     ED.binsize_item_saved                      != 
ED.binsize_item ||
diff --git a/src/ui/ed-widgets.hh b/src/ui/ed-widgets.hh
index aafff37..b2e217e 100644
--- a/src/ui/ed-widgets.hh
+++ b/src/ui/ed-widgets.hh
@@ -145,6 +145,8 @@ struct SExpDesignUIWidgets {
 
        // settings
        GtkSpinButton
+               *eSMPMaxThreads;
+       GtkSpinButton
                *eUltradianCycleDetectionAccuracy;
        GtkComboBox
                *eFFTParamsWindowType,
diff --git a/src/ui/ed.cc b/src/ui/ed.cc
index 9bbe43e..8d98457 100644
--- a/src/ui/ed.cc
+++ b/src/ui/ed.cc
@@ -20,6 +20,7 @@
 #include "../common/config-validate.hh"
 #include "../libsigfile/page-metrics-base.hh"
 #include "../expdesign/primaries.hh"
+#include "../libsigfile/artifacts.hh"
 #include "../model/beersma.hh"
 #include "misc.hh"
 #include "sf.hh"
@@ -193,17 +194,19 @@ SExpDesignUI (aghui::SSessionChooser *parent,
 
        // bind fields to widgets
        // tab 1
-       W_V1.reg( eUltradianCycleDetectionAccuracy, &uc_accuracy_factor);
+       W_V1.reg( eSMPMaxThreads, &ED->num_threads);
        W_V1.reg( eArtifDampenWindowType, (int*)&ED->af_dampen_window_type);
        W_V1.reg( eArtifDampenFactor, &ED->af_dampen_factor);
-       W_V1.reg( eFFTParamsPageSize, &pagesize_item);
-       W_V1.reg( eFFTParamsBinSize, &binsize_item);
        W_V1.reg( eFFTParamsWindowType, 
(int*)&ED->fft_params.welch_window_type);
-       for ( size_t i = 0; i < sigfile::SPage::TScore::_total; ++i )
-               W_V1.reg( eScoreCode[i], &ext_score_codes[i]);
        W_V1.reg( eMCParamIIRBackpolate, &ED->mc_params.iir_backpolate);
        W_V1.reg( eMCParamMCGain, &ED->mc_params.mc_gain);
        W_V1.reg( eMCParamBandWidth, &ED->mc_params.bandwidth);
+
+       W_V1.reg( eFFTParamsPageSize, &pagesize_item);
+       W_V1.reg( eFFTParamsBinSize, &binsize_item);
+       W_V1.reg( eUltradianCycleDetectionAccuracy, &uc_accuracy_factor);
+       for ( size_t i = 0; i < sigfile::SPage::TScore::_total; ++i )
+               W_V1.reg( eScoreCode[i], &ext_score_codes[i]);
        for ( size_t i = 0; i < sigfile::TBand::_total; ++i ) {
                W_V1.reg( eBand[i][0], &freq_bands[i][0]);
                W_V1.reg( eBand[i][1], &freq_bands[i][1]);
@@ -262,7 +265,7 @@ load_artifact_detection_profiles()
        FILE *domien = fopen( (ED->session_dir() + "/.AD_profiles").c_str(), 
"r");
        if ( domien ) {
                while ( !feof (domien) ) {
-                       SDetectArtifactsParamPack P;
+                       sigfile::SArtifactDetectionPP P;
                        DEF_UNIQUE_CHARP (_);
                        int int_estimate_E, int_use_range;
                        if ( 16 ==
diff --git a/src/ui/ed_cb.cc b/src/ui/ed_cb.cc
index d3bfd44..ba3ad51 100644
--- a/src/ui/ed_cb.cc
+++ b/src/ui/ed_cb.cc
@@ -180,7 +180,7 @@ iExpGloballyDetectArtifacts_activate_cb( GtkMenuItem*, 
gpointer userdata)
                        if ( not keep_existing )
                                af.clear_all();
                        auto    marked
-                               = sigfile::detect_artifacts( signal_original, 
sr, P);P
+                               = sigfile::detect_artifacts( signal_original, 
sr, P);
                        for ( size_t p = 0; p < marked.size(); ++p )
                                af.mark_artifact(
                                        marked[p] * P.scope * sr,
diff --git a/src/ui/sf-channel.cc b/src/ui/sf-channel.cc
index a007608..343f24a 100644
--- a/src/ui/sf-channel.cc
+++ b/src/ui/sf-channel.cc
@@ -340,38 +340,10 @@ calculate_dirty_percent()
 
 void
 aghui::SScoringFacility::SChannel::
-detect_artifacts( const aghui::SExpDesignUI::SDetectArtifactsParamPack& P)
+detect_artifacts( const sigfile::SArtifactDetectionPP& P)
 {
-       auto    sssu =
-               sigfile::CBinnedMC::do_sssu_reduction(
-                       signal_original,
-                       samplerate(), P.scope,
-                       P.mc_gain, P.iir_backpolate,
-                       P.f0, P.fc, P.bandwidth);
-       valarray<TFloat>
-               sssu_diff =
-               {sssu.first - sssu.second};
-
-       sigproc::smooth( sssu_diff, P.smooth_side);
-
-       double E;
-       if ( P.estimate_E )
-               E = P.use_range
-                       ? sigfile::CBinnedMC::estimate_E(
-                               sssu_diff,
-                               P.sssu_hist_size,
-                               P.dmin, P.dmax)
-                       : sigfile::CBinnedMC::estimate_E(
-                               sssu_diff,
-                               P.sssu_hist_size);
-       else
-               E = P.E;
-
        auto marked =
-               sigfile::CBinnedMC::detect_artifacts(
-                       sssu_diff,
-                       P.upper_thr, P.lower_thr,
-                       E);
+               sigfile::detect_artifacts( signal_original, samplerate(), P);
        for ( size_t p = 0; p < marked.size(); ++p )
                crecording.F().artifacts(_h).mark_artifact(
                        marked[p] * P.scope * samplerate(), (marked[p]+1) * 
P.scope * samplerate());

-- 
Sleep experiment manager

_______________________________________________
debian-med-commit mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit

Reply via email to