r2737 - in trunk: programs/us_2dsa utils
Author: gegorbet Date: 2019-04-23 17:05:18 +0000 (Tue, 23 Apr 2019) New Revision: 2737 Modified: trunk/programs/us_2dsa/us_analysis_control_2d.cpp trunk/utils/us_math2.cpp Log: 2dsa mods to grid_point,grid_repetitions logic for greater responsiveness to user-given parameters Modified: trunk/programs/us_2dsa/us_analysis_control_2d.cpp =================================================================== --- trunk/programs/us_2dsa/us_analysis_control_2d.cpp 2019-04-22 18:10:33 UTC (rev 2736) +++ trunk/programs/us_2dsa/us_analysis_control_2d.cpp 2019-04-23 17:05:18 UTC (rev 2737) @@ -771,20 +771,41 @@ // Reset memory estimate when grid steps, threads or repetitions changes void US_AnalysisControl2D::grid_change() { - int nsteps = (int)ct_nstepss ->value(); // # steps s - int nstepk = (int)ct_nstepsk ->value(); // # steps k - int nthrd = (int)ct_thrdcnt ->value(); // # threads - int nscan = edata->scanCount(); // # scans - int nconc = edata->pointCount(); // # concentrations - int ntconc = nconc * nscan; // # total readings + static int ksteps = 0; + static int kstepk = 0; + int nsteps = (int)ct_nstepss ->value(); // # steps s + int nstepk = (int)ct_nstepsk ->value(); // # steps k + int nthrd = (int)ct_thrdcnt ->value(); // # threads + int nscan = edata->scanCount(); // # scans + int nconc = edata->pointCount(); // # concentrations + int ntconc = nconc * nscan; // # total readings double megas = sq( 1024.0 ); + ksteps = ( ksteps == 0 ) ? nsteps : ksteps; + kstepk = ( kstepk == 0 ) ? nstepk : kstepk; +// int jsteps = nsteps; +// int jstepk = nstepk; - int ngrrep = US_Math2::best_grid_reps( nsteps, nstepk ); +DbgLv(1) << "GC: 1) nss nsk" << nsteps << nstepk; + int ngrrep = US_Math2::best_grid_reps( nsteps, nstepk ); +DbgLv(1) << "GC: 2)ngrrep" << ngrrep << "nss nsk" << nsteps << nstepk; + if ( nsteps != ksteps ) + { // S grid points just changed: adjust K points + nstepk = ( nstepk / ngrrep ) * ngrrep; + ngrrep = US_Math2::best_grid_reps( nsteps, nstepk ); +DbgLv(1) << "GC: 3)ngrrep" << ngrrep << "nss nsk" << nsteps << nstepk; + } + else if ( nstepk != kstepk ) + { // K grid points just changed: adjust S points + nsteps = ( nsteps / ngrrep ) * ngrrep; + ngrrep = US_Math2::best_grid_reps( nsteps, nstepk ); +DbgLv(1) << "GC: 4)ngrrep" << ngrrep << "nss nsk" << nsteps << nstepk; + } + // Adjust grid points to be multiples of grid repetitions - nsteps = ( ( nsteps + ngrrep - 1 ) / ngrrep ) * ngrrep; - nstepk = ( ( nstepk + ngrrep - 1 ) / ngrrep ) * ngrrep; -DbgLv(1) << "GC: ngrrep" << ngrrep << "nss nks" << nsteps << nstepk; + nsteps = ( ( nsteps + ngrrep / 2 ) / ngrrep ) * ngrrep; + nstepk = ( ( nstepk + ngrrep / 2 ) / ngrrep ) * ngrrep; +DbgLv(1) << "GC: 5)ngrrep" << ngrrep << "nss nks" << nsteps << nstepk; ct_nstepss->disconnect(); ct_nstepss->setValue( nsteps ); @@ -811,10 +832,10 @@ const double x_fact = 17.20; const double y_fact = 2.28; const int nxdata = 4; - int nsstep = ( nsteps / ngrrep ) * ( nstepk / ngrrep ); + int nsbpts = ( nsteps / ngrrep ) * ( nstepk / ngrrep ); int noif = ( ck_tinoise->isChecked() ? 1 : 0 ) + ( ck_rinoise->isChecked() ? 2 : 0 ); - int ndatas = nsstep + nxdata + noif; + int ndatas = nsbpts + nxdata + noif; double mdata = ( (double)ntconc * ndatas * sizeof( double ) ) / megas; double tdata = x_fact + mdata * y_fact; memneed = baserss + qRound( tdata * (double)nthrd ); @@ -843,6 +864,10 @@ te_status ->setText( gmsg ); le_gridreps->setText( tr( "%1 -> %2 %3-point subgrids" ) .arg( ngrrep ).arg( nsubg ).arg( nspts ) ); + + // Save grid points to detect any further user resets + ksteps = nsteps; + kstepk = nstepk; } // Adjust s-limit ranges when s-limit value changes Modified: trunk/utils/us_math2.cpp =================================================================== --- trunk/utils/us_math2.cpp 2019-04-22 18:10:33 UTC (rev 2736) +++ trunk/utils/us_math2.cpp 2019-04-23 17:05:18 UTC (rev 2737) @@ -1460,15 +1460,64 @@ const int min_reps = 1; // Repetitions at least 1 const int max_reps = 160; // Repetitions at most 160 +qDebug() << "BGR: IN"; // Insure grid points are within reasonable limits ngrid_s = qMin( max_grid, qMax( min_grid, ngrid_s ) ); ngrid_k = qMin( max_grid, qMax( min_grid, ngrid_k ) ); int ngrid_s_i = ngrid_s; int ngrid_k_i = ngrid_k; +qDebug() << "BGR: ngrid_s_i" << ngrid_s_i << "ngrid_k_i" << ngrid_k_i; - // Compute the initial best grid-repetitions value - int nreps_g = qRound( pow( (double)( ngrid_s * ngrid_k ), 0.25 ) ); + // Build the list of repetition values that divide into s grid points + QList< int > reps; + + for ( int jreps = min_reps; jreps <= max_reps; jreps++ ) + { + int jgrid_s = ( ngrid_s / jreps ) * jreps; + + if ( jgrid_s == ngrid_s ) + { // Save a repetition that divides evenly into S grid points + reps << jreps; +qDebug() << "BGR: jgrid_s" << jgrid_s << "jreps" << jreps; + } + } + + // Find the repetitions and k grid points that work best + int kdiff = 99999; + int kreps = reps[ 0 ]; + int kgrid_k = ngrid_k; + + for ( int ii = 0; ii < reps.count(); ii++ ) + { + int jreps = reps[ ii ]; + int dim_s = ngrid_s / jreps; + int dim_k = ngrid_k / jreps; + int jgrid_k = dim_k * jreps; + int nsubgs = jreps * jreps; + int subgsz = dim_s * dim_k; + int jdiff = qAbs( nsubgs - subgsz ); +qDebug() << "BGR: ii" << ii << "jreps" << jreps << "jgrid_k" << jgrid_k; + + if ( jdiff < kdiff ) + { // Count and size of subgrid closely matched + kdiff = jdiff; + kreps = jreps; + kgrid_k = jgrid_k; +qDebug() << "BGR: ii" << ii << "kdiff" << kdiff; + } + } + + ngrid_k = kgrid_k; + int nreps_g = kreps; + int nsubg_s = ngrid_s / nreps_g; + int nsubg_k = ngrid_k / nreps_g; +qDebug() << "BGR: ngrid_s" << ngrid_s << "ngrid_k ngrid_k_i" << ngrid_k << ngrid_k_i; +qDebug() << "BGR: nsubgs" << (nreps_g*nreps_g) << "subgsz" << (nsubg_s*nsubg_k) + << "totgsz" << (ngrid_s*ngrid_k) << "nreps_g" << nreps_g; + +#if 0 double grfact = 1.0; +qDebug() << "BGR: nreps_g" << nreps_g; // If debug text modifies grid-rep factor, apply it QStringList tgrfact = US_Settings::debug_text(); @@ -1478,26 +1527,23 @@ grfact = QString( tgrfact[ ii ]) .section( "=", 1, 1 ).toDouble(); } nreps_g = qRound( grfact * nreps_g ); +qDebug() << "BGR: grfact" << grfact << "nreps_g" << nreps_g; +#endif - // Compute the initial sub-grid point counts in each dimension, - // insuring the next highest integers are used. - int nsubg_s = ( ngrid_s + nreps_g - 1 ) / nreps_g; - int nsubg_k = ( ngrid_k + nreps_g - 1 ) / nreps_g; - // Adjust values until the product yields no more than 200 sub-grid points - while ( ( nsubg_s * nsubg_k ) > max_subg && nreps_g < max_reps ) + while ( ( nsubg_s * nsubg_k ) > max_subg || nreps_g < min_reps ) { // Increase grid-reps and recompute sub-grid points nreps_g++; - nsubg_s = ( ngrid_s + nreps_g - 1 ) / nreps_g; - nsubg_k = ( ngrid_k + nreps_g - 1 ) / nreps_g; + nsubg_s = ngrid_s / nreps_g; + nsubg_k = ngrid_k / nreps_g; } // Adjust values until the product yields no less than 40 sub-grid points - while ( ( nsubg_s * nsubg_k ) < min_subg && nreps_g > min_reps ) + while ( ( nsubg_s * nsubg_k ) < min_subg || nreps_g > max_reps ) { // Decrease grid-reps and recompute sub-grid points nreps_g--; - nsubg_s = ( ngrid_s + nreps_g - 1 ) / nreps_g; - nsubg_k = ( ngrid_k + nreps_g - 1 ) / nreps_g; + nsubg_s = ngrid_s / nreps_g; + nsubg_k = ngrid_k / nreps_g; } // Recalculate the total grid points in each dimension @@ -1505,16 +1551,6 @@ ngrid_s = nsubg_s * nreps_g; ngrid_k = nsubg_k * nreps_g; - if ( ngrid_s < ngrid_s_i ) - { // If S grid points less than user-given, bump by grid reps - ngrid_s += nreps_g; - } - - if ( ngrid_k < ngrid_k_i ) - { // If K grid points less than user-given, bump by grid reps - ngrid_k += nreps_g; - } - // Return the computed number of grid repetitions return nreps_g; }
participants (1)
-
svn@svn.aucsolutions.com