16 QObject* parent ) : QObject( parent ), dsets( dsets )
18 bdata = &dsets[ 0 ]->run_data;
56 double kll,
double kul,
int nks,
57 int ngr,
int nthr,
int noif )
59 DbgLv(1) <<
"2P(2dsaProc): start_fit()";
71 errMsg = tr(
"NO ERROR: start" );
86 int kk = qMax( 1,
nksteps ) - 1;
125 DbgLv(1) <<
"MENISC: mm_iter meniscus bmeniscus"
154 int kgrefsq =
sq( kgref );
156 - ( kgref + kgrefsq ) * ( nsubp_s + nsubp_k ) + kgrefsq;
157 DbgLv(1) <<
"2P: kgref kgrefsq kksubg" << kgref << kgrefsq << kksubg;
161 int nnstep = ( noisflag > 0 ? (
sq( ktcsol ) / 10 + 2 ) : 2 ) *
nsubgrid;
172 DbgLv(1) <<
"2P: nsubgrid nctotal nthreads maxtsols"
179 QList< QVector< US_Solute > > solute_list;
180 double ssllim =
slolim * 1.0e-13;
181 double ssulim =
suplim * 1.0e-13;
183 double vbar20 =
dsets[ 0 ]->vbar20;
192 for (
int ii = 0; ii <
orig_sols.count(); ii++ )
193 for (
int jj = 0; jj <
orig_sols[ ii ].count(); jj++ )
197 else if ( jgrefine == (-1) )
199 QVector< US_Solute > solvec;
203 for (
int ii = 0; ii <
nsubgrid; ii++ )
207 for (
int jj = ii; jj < ncomps; jj +=
nsubgrid )
214 DbgLv(1) <<
"ii" << ii <<
"soli" << soli.
s << soli.
k << soli.
c << soli.
v;
224 for (
int ii = 0; ii < ncomps; ii++ )
231 DbgLv(1) <<
"ii" << ii <<
"soli" << soli.
s << soli.
k << soli.
c;
239 else if ( jgrefine == (-2) )
241 QVector< US_Solute > solvec;
243 for (
int ii = 0; ii < ncomps; ii++ )
250 DbgLv(1) <<
"ii" << ii <<
"soli" << soli.
s << soli.
k << soli.
c;
258 for (
int ktask = 0; ktask <
nsubgrid; ktask++ )
266 maxtsols = qMax( maxtsols, wtask.
isolutes.size() );
273 for (
int ii = 0; ii <
nthreads; ii++ )
288 tr(
"Starting computations of %1 subgrids\n using %2 threads ..." )
289 .arg( nsubgrid ).arg( nthreads ),
false );
296 double vtoler,
double menrng,
double cff0,
300 mmtype = ( mciter > 1 ) ? 2 : ( ( mniter > 1 ) ? 1 : 0 );
316 dsets[ 0 ]->solute_type = stype;
325 for (
int ii = 0; ii <
wthreads.size(); ii++ )
327 DbgLv(1) <<
"StopFit test Thread" << ii + 1;
334 if ( wthr->isRunning() )
337 DbgLv(1) <<
" STOPTHR: thread aborted";
342 DbgLv(1) <<
" STOPTHR: thread deleted";
356 tr(
"All computations have been aborted." ),
false );
410 for (
int ii = 0; ii <
c_solutes[ depth ].size(); ii++ )
428 wtask.
thrn = thrx + 1;
433 connect( wthr, SIGNAL( work_progress(
int ) ),
453 c_solutes << QVector< US_Solute >();
456 int nsolutes = c_solutes[
maxdepth ].size();
458 QVector< double > tinvec(
npoints, 0.0 );
459 QVector< double > rinvec(
nscans, 0.0 );
470 for (
int rr = 0; rr <
npoints; rr++ )
473 tinvec [ rr ] = wresult.
ti_noise[ rr ];
482 for (
int ss = 0; ss <
nscans; ss++ )
485 rinvec [ ss ] = wresult.
ri_noise[ ss ];
491 double sfactor = 1.0 / dset->s20w_correction;
492 double dfactor = 1.0 / dset->D20w_correction;
493 double vbar20 = dset->vbar20;
494 DbgLv(1) <<
"FIN_FIN: s20w,D20w_corr" << dset->s20w_correction
495 << dset->D20w_correction <<
"sfac dfac" << sfactor << dfactor;
504 if ( dset->solute_type == 0 )
506 for (
int cc = 0; cc < nsolutes; cc++ )
523 DbgLv(1) <<
" Bcc comp D" << mcomp.
D;
528 DbgLv(1) <<
" Bcc 20w comp D" << mcomp.
D;
534 else if ( dset->solute_type == 1 )
540 double avtemp = dset->temperature;
542 for (
int cc = 0; cc < nsolutes; cc++ )
557 DbgLv(1) <<
" Bcc comp D" << mcomp.
D;
566 DbgLv(1) <<
" Bcc 20w comp D" << mcomp.
D;
578 double avtemp = dset->temperature;
580 for (
int cc = 0; cc < nsolutes; cc++ )
595 DbgLv(1) <<
" Bcc comp D" << mcomp.
D;
604 DbgLv(1) <<
" Bcc 20w comp D" << mcomp.
D;
611 << c_solutes[
maxdepth][qMax(0,nsolutes-1)].c <<
" nsols" << nsolutes;
615 DbgLv(1) <<
"FIN_FIN: vari" << vari;
622 for (
int ss = 0; ss <
nscans; ss++ )
624 for (
int rr = 0; rr <
npoints; rr++ )
644 DbgLv(1) <<
"FIN_FIN: vari riter miter menisc" << rscan0->
delta_r
648 int ktimes = (
timer.elapsed() + 500 ) / 1000;
649 int ktimeh = ktimes / 3600;
650 int ktimem = ( ktimes - ktimeh * 3600 ) / 60;
651 double bvol =
dsets[0]->simparams.band_volume;
652 bvol=
dsets[0]->simparams.band_forming?bvol:0.0;
653 DbgLv(1) <<
"done: vari bvol" << vari << bvol
656 ktimes = ktimes - ktimeh * 3600 - ktimem * 60;
660 tr(
"The Solution has converged...\n"
662 "Threads: %2 ; Subgrids: %3\n"
663 "Grid points (s x f/f0): %4 x %5\n"
669 pmsg += tr(
"%1 hr., %2 min., %3 sec.\n" )
670 .arg( ktimeh ).arg( ktimem ).arg( ktimes );
673 pmsg += tr(
"%1 min., %2 sec.\n" )
674 .arg( ktimem ).arg( ktimes );
677 double memmb = (double)
maxrss / 1024.0;
679 pmsg += tr(
"Maximum memory used: " )
680 + QString::number( qRound( memmb ) ) +
" MB";
684 int thrx = wresult.
thrn - 1;
686 DbgLv(1) <<
"FIN_FIN: Run Time: hr min sec" << ktimeh << ktimem << ktimes;
691 bool neediter =
false;
706 double dvari = fabs( pvari - vari );
711 if ( nccsol == npcsol )
714 for (
int jj = 0; jj < nccsol; jj++ )
725 neediter = ( sdiffs && dvari >
varitol );
726 DbgLv(1) <<
"FIN_FIN: neediter" << neediter <<
" sdiffs" << sdiffs
727 <<
" dvari varitol" << dvari <<
varitol <<
" iter" <<
r_iter;
739 if ( dset->solute_type == 0 )
741 for (
int cc = 0; cc < nsolutes; cc++ )
754 double avtemp = dset->temperature;
756 for (
int cc = 0; cc < nsolutes; cc++ )
794 if (
abort )
return false;
800 if ( (
noisflag & 1 ) != 0 && da_tin != 0 )
803 if ( (
noisflag & 2 ) != 0 && da_rin != 0 )
815 wtask.
thrn = thrx + 1;
827 connect( wthr, SIGNAL( work_progress(
int ) ),
829 DbgLv(1) <<
"SUBMIT_JOB taskx" << wtask.
taskx <<
"depth" << wtask.
depth;
843 int thrn = wresult.
thrn;
845 int taskx = wresult.
taskx;
846 int depth = wresult.
depth;
848 DbgLv(1) <<
"PROCESS_JOB thrn" << thrn <<
"taskx" << taskx
849 <<
"depth" << wresult.
depth;
850 int nrcso = wresult.
csolutes.size();
852 if ( taskx < 9 || taskx > (
nsubgrid-4) )
853 DbgLv(1) <<
"PJ: taskx csolutes size tot" << taskx << nrcso <<
ntcsols
854 << QDateTime::currentDateTime().toMSecsSinceEpoch();
857 if ( wresult.
csolutes[mm].c > 100.0 ) {
859 <<
" s,ff0" << wresult.
csolutes[mm].s*1.0e+13
869 for (
int ii=0; ii<
nscans; ii++ )
870 for (
int jj=0; jj<
npoints; jj++ )
872 for (
int jj=0; jj<nnoi; jj++ )
874 DbgLv(1) <<
"PJ:DA DTOT" << dtot <<
"thr,tsk,ncso" << thrn << taskx << nrcso
875 <<
"edata" <<
edata <<
"nti,NTOT" << nnoi << ntot;
890 while(
c_solutes.size() < ( depth + 1 ) )
891 c_solutes << QVector< US_Solute >();
894 int wr_size = wresult.
csolutes.size();
895 int nextc = cs_size + wr_size;
897 int depthn = depth + 1;
899 if ( depthn > 4 && nextc >
maxtsols &&
900 ( ( cs_size / wr_size ) == 1 || ( wr_size / cs_size ) == 1 ) )
915 DbgLv(1) <<
"THR_FIN: depth" << wtask.
depth <<
" #solutes"
917 <<
"wres#sols" << wresult.
csolutes.size();;
923 DbgLv(1) <<
"THR_FIN: thrn" << thrn <<
" taskx" << taskx
927 tr(
"Computations for %1 of %2 subgrids are complete" )
941 <<
" nsol ntodo" << nsolest << todoest;
945 <<
" nsol ntodo" << nsolact << todoact;
951 tr(
"Computing depth 1 solutions and beyond ..." ),
false );
957 if ( nextc <=
maxtsols && maxdepsv < 1 )
969 for (
int dd = 0; dd < depth; dd++ )
976 DbgLv(1) <<
"THR_FIN: QT: taskx depth solsz" << taskx << depth <<
c_solutes[dd].size();
986 DbgLv(1) <<
"THR_FIN: nowk dep mxdp cssz wrsz" << no_working << depth
998 DbgLv(1) <<
"THR_FIN: jqempty" <<
job_queue.isEmpty() <<
"ReadyWorkerNdx"
1010 if ( wtask.
depth > 1 &&
1013 QString pmsg = tr(
"Computing depth %1 solutions..." )
1014 .arg( wtask.
depth );
1032 DbgLv(1) <<
"THR_FIN: QT: /NONEW/taskx depth solsz" << taskx << depth
1043 DbgLv(1) <<
"THR_FIN: QT: /NONEW/ thrx" << thrx;
1053 int taskx,
int depth,
int noisf, QVector< US_Solute > isolutes )
1056 wtask.
taskx = taskx;
1057 wtask.
noisf = noisf;
1060 wtask.
depth = depth;
1073 int nrisols = isolutes.size();
1075 if ( taskx < 9 || taskx > (
nsubgrid-4) )
1076 DbgLv(1) <<
"QT: taskx" << taskx <<
" isolutes size tot" << nrisols <<
ntisols;
1082 if (
tkdepths.count( depth ) == 1 )
1084 emit
message_update( tr(
"Submitting first depth %1 calculations..." )
1085 .arg( depth ),
true );
1086 DbgLv(1) <<
"Submit 1st calcs, depth" << depth;
1098 QVector< US_Solute > isolutes;
1100 int ncsol = csolutes.size();
1106 DbgLv(1) <<
"ITER: r-iter0 ncto ncsol" <<
nctotal << ncsol;
1109 int kstep = (
r_iter == 1 ) ? ( ncsol + 8 ) : 4;
1110 int knois = ktask * ( ( kstep * ktisol +
sq( kstep ) ) / 10 );
1111 DbgLv(1) <<
"ITER: nsubg ktask kstep knois" <<
nsubgrid << ktask << kstep << knois;
1112 int kadd = ( ktask * kstep ) + ( (
noisflag == 0 ) ? 0 : knois );
1114 DbgLv(1) <<
"ITER: r-iter1 ncto (diff)" <<
nctotal << kadd;
1129 for(
int jj=0; jj<ncsol; jj++ )
1130 DbgLv(1) <<
"ITER: csol" << jj <<
" s k c"
1131 << csolutes[jj].s*1.e13 << csolutes[jj].k << csolutes[jj].c;
1136 for ( ktask = 0; ktask <
nsubgrid; ktask++ )
1142 for (
int cc = 0; cc < ncsol; cc++ )
1144 if ( ! isolutes.contains( csolutes[ cc ] ) )
1145 isolutes << csolutes[ cc ];
1149 int kasz=isolutes.size();
1151 ktadd += (ncsol-kadd);
1153 DbgLv(1) <<
"ITER: kt" << ktask <<
"iterate nisol o a c +"
1154 << kosz << kasz << ncsol << kadd <<
"ktadd" << ktadd <<
"nsubg" <<
nsubgrid;
1157 double llss = isolutes[ 0 ].s;
1158 double llsk = isolutes[ 0 ].k;
1161 queue_task( wtask, llss, llsk, ktask, jdpth, jnois, isolutes );
1168 for(
int cc=0;cc<
orig_sols[kt].size();cc++)
1169 DbgLv(1) <<
"ITER kt cc" << kt << cc <<
" s k c"
1175 for (
int ii = 0; ii <
c_solutes.size(); ii++ )
1181 for (
int ii = 0; ii <
nthreads; ii++ )
1191 tr(
"Starting iteration %1 computations of %2 subgrids\n"
1192 " using %3 threads ..." )
1193 .arg(
r_iter + 1 ).arg( nsubgrid ).arg( nthreads ),
true );
1221 int ktcsol = ktisol / 8 + 1;
1222 int ktstep = ktisol + ( (
noisflag > 0 ) ? (
sq( ktisol ) / 10 + 2 ) : 2 );
1223 DbgLv(1) <<
"ES: ncsol ktisol ktcsol ktstep" << ncsol << ktisol
1224 << ktcsol << ktstep;
1227 int n1task = ( ncsol + ktisol / 2 ) / ktisol + 1;
1228 int ntasks = n1task + 1;
1229 int n1csol = n1task * ktcsol;
1230 DbgLv(1) <<
"ES: D1 n1task n1csol" << n1task << n1csol;
1233 n1task = ( n1csol + ktisol / 2 ) / ktisol + 1;
1235 n1csol = n1task * ktcsol;
1236 DbgLv(1) <<
"ES: D2 n1task n1csol" << n1task << n1csol;
1238 while ( n1task > 1 )
1240 n1task = ( n1csol + ktisol / 2 ) / ktisol + 1;
1242 n1csol = n1task * ktcsol;
1243 DbgLv(1) <<
"ES: D3ff n1task n1csol" << n1task << n1csol;
1247 DbgLv(1) <<
"ES: returned nsteps ntasks" << (ntasks*ktstep) << ntasks;
1249 int szrdng =
sizeof(QVector<double>);
1251 int nscns =
dsets[0]->run_data.scanData.size();
1252 int nrpts =
dsets[0]->run_data.xvalues.size();
1257 szwrkp = szwrkp + szsols*100 + szsimu + szdset;
1258 DbgLv(1) <<
"ES: nscns nrpts ktisol" << nscns << nrpts << ktisol;
1259 DbgLv(1) <<
"ES: szscnd szrdng szsols" << szscnd << szrdng << szsols;
1260 DbgLv(1) <<
"ES: szdata szdset szsimu" << szdata << szdset << szsimu;
1261 DbgLv(1) <<
"ES: szwrkp" << szwrkp;
1263 return ( ntasks * ktstep );
1271 for (
int ii = 0; ii <
job_queue.size(); ii++ )
1285 for (
int ii = 0; ii <
nthreads; ii++ )
1308 double smeniscus = bmeniscus -
menrange * 0.5;
1334 for (
int ss = 0; ss <
nscans; ss++ )
1336 for (
int rr = 0; rr <
npoints; rr++ )
1344 DbgLv(1) <<
"MCARLO: mm_iter" <<
mm_iter <<
" sigma0 c0 v0 cn vn"
1362 for (
int ktask = 0; ktask <
nsubgrid; ktask++ )
1364 double llss =
orig_sols[ ktask ][ 0 ].s;
1365 double llsk =
orig_sols[ ktask ][ 0 ].k;
1367 QVector< US_Solute > isolutes =
orig_sols[ ktask ];
1369 queue_task( wtask, llss, llsk, ktask, jdpth, jnois, isolutes );
1373 for (
int ii = 0; ii <
c_solutes.size(); ii++ )
1377 for (
int ii = 0; ii <
nthreads; ii++ )
1391 tr(
"Starting iteration %1 computations of %2 subgrids\n"
1392 " using %3 threads ..." )
1393 .arg(
r_iter + 1 ).arg( nsubgrid ).arg( nthreads ),
true );
1404 for (
int ss = 0; ss <
nscans; ss++ )
1405 for (
int rr = 0; rr <
npoints; rr++ )
1415 for (
int ss = 0; ss <
nscans; ss++ )
1417 QVector< double > vv( npoints );
1419 for (
int rr = 0; rr <
npoints; rr++ )
1422 rmsdr +=
sq( rval );
1423 vv[ rr ] = qAbs( rval );
1426 if ( ss < 2 )
DbgLv(1) <<
"MCARLO:setgau:gausmoo vv9" << vv[9] <<
"ss" << ss;
1429 if ( ss < 2 )
DbgLv(1) <<
"MCARLO:setgau: smoothd vv9" << vv[9];
1435 for (
int rr = 0; rr < ntpoints; rr++ )
1438 rmsdr = sqrt( rmsdr / (
double)ntpoints );
1439 rmsds = sqrt( rmsds / (
double)ntpoints );
1440 double sigscl = rmsdr / rmsds;
1442 for (
int rr = 0; rr < ntpoints; rr++ )
1449 return tr(
"Model %1, Iteration %2:\n" )
1457 if (
job_queue.size() == 0 )
return wtask;
1461 int depth = wtask.
depth;
1466 for (
int ii = 0; ii <
job_queue.size(); ii++ )
1471 depth = wtask.
depth;
1477 DbgLv(1) <<
"NEXTJ: jobx depth depth0 taskx taskx0"
1480 DbgLv(1) <<
"NEXTJ: jobx depth taskx" << jobx << depth << wtask.
taskx; }
1483 job_queue.removeAt( jobx );
1490 bool stopfit =
false;
1491 int memava, memtot, memuse;
1493 DbgLv(1) <<
"MCk:MEM: AvailPercent" << mempav;
1498 DbgLv(0) <<
"MCk:MEM: *** AvailPercent < 10 ***";
1500 QMessageBox::warning( (QWidget*)
parentw, tr(
"High Memory Usage" ),
1501 tr(
"The available memory percent of\n"
1502 "the total memory has fallen below 10%.\n"
1503 "Total memory is %1 MB;\n"
1504 "Used memory is %2 MB;\n"
1505 "Available memory is %3 MB.\n\n"
1506 "Re-parameterize the fit with adjusted\n"
1507 "Grid Refinements and/or Thread Count." )
1508 .arg( memtot ).arg( memuse ).arg( memava ) );