13 int main(
int argc,
char* argv[] )
15 MPI_Init( &argc, &argv );
16 QCoreApplication application( argc, argv );
20 for (
int jj = 0; jj < argc; jj++ )
21 cmdargs << argv[ jj ];
30 const QString wallkey (
"-walltime" );
31 const QString pmgckey (
"-mgroupcount" );
33 const QString wallkey2(
"-WallTimeLimit" );
34 const QString pmgckey2(
"-MGroupCount" );
35 const QString wallkey3(
"-wallTimeLimit" );
36 const QString pmgckey3(
"-pmgc" );
39 MPI_Comm_rank( MPI_COMM_WORLD, &
my_rank );
52 for (
int jj = 1; jj < nargs; jj++ )
54 QString cmdarg = cmdargs[ jj ];
56 DbgLv(0) <<
"CmdArg: jj" << jj <<
"cmdarg" << cmdarg;
58 if ( cmdarg.startsWith(
"-" ) )
61 int valx = cmdarg.indexOf(
"=" );
65 cmdval = cmdarg.mid( valx + 1 ).simplified();
68 else if ( ( jj + 1 ) < nargs )
70 cmdval = cmdargs[ ++jj ];
73 if ( cmdarg.contains( wallkey ) ||
74 cmdarg.contains( wallkey2 ) ||
75 cmdarg.contains( wallkey3 ) )
80 else if ( cmdarg.contains( pmgckey ) ||
81 cmdarg.contains( pmgckey2 ) ||
82 cmdarg.contains( pmgckey3 ) )
87 DbgLv(0) <<
"CmdArg: valx" << valx <<
"cmdval" << cmdval;
90 else if ( tarfile.isEmpty() )
103 DbgLv(0) <<
"CmdArg: tarfile" << tarfile;
104 DbgLv(0) <<
"CmdArg: jxmlfili" << jxmlfili;
112 socket =
new QUdpSocket(
this );
115 QDir wkdir = QDir::current();
116 QString work_dir = QDir::currentPath();
117 QString output_dir = work_dir +
"/output";
118 QString input_dir = work_dir +
"/input";
127 int result = tar.
extract( tarfile );
129 if ( result !=
TAR_OK )
abort(
"Could not unpack " + tarfile );
133 wkdir.mkdir ( output_dir );
135 QDir odir( output_dir );
138 QStringList files = odir.entryList( ffilt, QDir::Files );
141 foreach( file, files ) odir.remove( file );
145 MPI_Barrier( MPI_COMM_WORLD );
148 startTime = QDateTime::currentDateTime();
163 QStringList files = wkdir.entryList( ffilt );
164 if ( files.size() == 0 )
166 files = QDir( input_dir ).entryList( ffilt );
167 if ( files.size() == 1 )
168 xmlfile = input_dir +
"/" + files[ 0 ];
171 xmlfile = files[ 0 ];
173 if ( files.size() != 1 )
abort(
"Could not find unique hpc input file." );
188 QString jxmlfile = jxmlfili;
191 if ( jxmlfile.isEmpty() )
194 ffilt <<
"*jobxmlfile.xml";
195 ffilt <<
"jobxmlfile.xml";
196 QStringList jfiles = QDir( input_dir ).entryList( ffilt, QDir::Files );
197 if(
my_rank==0)
DbgLv(0) <<
" jfiles size" << jfiles.size();
199 if ( jfiles.size() > 0 )
201 jxmlfile = input_dir +
"/" + jfiles[ 0 ];
207 jfiles = wkdir.entryList( ffilt, QDir::Files );
208 jxmlfile = jfiles.size() > 0 ? jfiles[ 0 ] :
"";
211 DbgLv(0) <<
" jfiles size" << jfiles.size() <<
"jxmlfile" << jxmlfile;
218 submitTime = QFileInfo( tarfile ).lastModified();
220 <<
" mgroupcount" <<
task_params[
"mgroupcount"].toInt()
223 printf(
"Us_Mpi_Analysis %s has started.\n",
REVISION );
228 QString msg_start = QString(
"Starting -- " ) + QString(
REVISION );
232 for (
int ii = 0; ii <
data_sets.size(); ii++ )
245 QString msg =
"Bad data file " + dset->
auc_file +
" "
247 DbgLv(0) <<
"BAD DATA. error" << error <<
"rank" <<
my_rank;
252 QString msg =
"Bad data file " + dset->
auc_file +
" "
260 for (
int jj = 0; jj < dset->
noise_files.size(); jj++ )
268 QString msg =
"Bad noise file " + dset->
noise_files[ jj ];
274 QString msg =
"Bad noise file " + dset->
noise_files[ jj ];
284 abort(
"The bottom is set to the invalid default value of 7.3" );
288 QDir::setCurrent( output_dir );
315 abort(
"Meniscus fit is not compatible with global fit" );
320 abort(
"Meniscus fit is not compatible with Monte Carlo analysis" );
323 bool noise =
parameters[
"tinoise_option" ].toInt() > 0 ||
329 abort(
"Monte Carlo iteration is not compatible with noise computation" );
334 abort(
"Global fit is not compatible with noise computation" );
341 double meniscus_start =
data_sets[ 0 ]->run_data.meniscus
353 double start_range =
data_sets[ 0 ]->run_data.radius( 0 );
356 if ( last_meniscus >= start_range )
360 qDebug() <<
"*ERROR* Meniscus value extends into data";
361 qDebug() <<
" data meniscus" <<
data_sets[0]->run_data.meniscus;
362 qDebug() <<
" meniscus_start" << meniscus_start;
365 qDebug() <<
" dm" << dm;
366 qDebug() <<
" last_meniscus" << last_meniscus;
367 qDebug() <<
" left_data" << start_range;
369 abort(
"Meniscus value extends into data" );
390 for (
int ee = 0; ee <
data_sets.size(); ee++ )
403 DbgLv(0) <<
"density/viscosity/comm vbar20/commvbar/compress"
411 DbgLv(0) <<
"s20w_correction/D20w_correction"
416 bool incl_speed = ( ds->
simparams.speed_step.count() < 1 );
417 ds->
simparams.initFromData( NULL, *edata, incl_speed );
429 total_points += npoints;
438 for (
int ss = 0; ss < edata->
scanCount(); ss++ )
439 for (
int rr = 0; rr < edata->
pointCount(); rr++ )
440 odmax = qMax( odmax, edata->
value( ss, rr ) );
442 odmax = qMin( odmax, odlim );
443 DbgLv(2) <<
"ee" << ee <<
"odlim odmax" << odlim << odmax;
448 double s_max =
parameters[
"s_max" ].toDouble() * 1.0e-13;
449 double x_max =
parameters[
"x_max" ].toDouble() * 1.0e-13;
450 s_max = ( s_max == 0.0 ) ? x_max : s_max;
451 double y_max = 1e-39;
457 abort(
"No buckets defined" );
459 QList< QRectF > bucket_rects;
463 for (
int i = 0; i <
buckets.size(); i++ )
467 bucket_rects << QRectF(
471 x_max = qMax( x_max,
buckets[ i ].x_max );
472 y_max = qMax( y_max,
buckets[ i ].y_max );
477 for (
int i = 0; i < bucket_rects.size() - 1; i++ )
479 for (
int j = i + 1; j < bucket_rects.size(); j++ )
481 if ( bucket_rects[ i ].intersects( bucket_rects[ j ] ) )
483 QRectF bukov = bucket_rects[i].intersected( bucket_rects[j] );
484 double sdif = bukov.width();
485 double fdif = bukov.height();
489 DbgLv(0) <<
"Bucket" << i <<
"overlaps bucket" << j;
490 DbgLv(0) <<
" Overlap: st w h" << bukov.topLeft()
492 DbgLv(0) <<
" Bucket i" << bucket_rects[i].topLeft()
493 << bucket_rects[i].bottomRight();
494 DbgLv(0) <<
" Bucket j" << bucket_rects[j].topLeft()
495 << bucket_rects[j].bottomRight();
496 DbgLv(0) <<
" Bucket i right "
497 << QString().sprintf(
"%22.18f", bucket_rects[i].right() );
498 DbgLv(0) <<
" Bucket j left "
499 << QString().sprintf(
"%22.18f", bucket_rects[j].left() );
500 DbgLv(0) <<
" Bucket i bottom"
501 << QString().sprintf(
"%22.18f", bucket_rects[i].bottom() );
502 DbgLv(0) <<
" Bucket j top "
503 << QString().sprintf(
"%22.18f", bucket_rects[j].top() );
506 if ( qMin( sdif, fdif ) < 1.e-6 )
509 DbgLv(0) <<
"Trivial overlap is ignored.";
513 abort(
"Buckets overlap" );
523 double zval =
parameters[
"bucket_fixed" ].toDouble();
530 s_max = y_max * 1.0e-13;
532 s_max = zval * 1.0e-13;
537 zval = ( zval == 0.0 ) ?
data_sets[ 0 ]->vbar20 : zval;
546 for (
int jj = 0; jj <
buckets.size(); jj++ )
548 double xval =
buckets[ jj ].x_max;
549 double yval =
buckets[ jj ].y_max;
555 if (
my_rank==0)
DbgLv(0) <<
"ckGrSz: buck" << jj <<
"xv yv zv"
556 << xval << yval << zval <<
"mc s k w v d f"
557 << mcomp.
s << mcomp.
f_f0 << mcomp.
mw << mcomp.
vbar20 << mcomp.
D << mcomp.
f;
558 s_max = qMax( s_max, mcomp.
s );
564 s_max = ( s_max == 0.0 ) ? 10e-13 : s_max;
565 if (
my_rank==0)
DbgLv(0) <<
"ckGrSz: s_max" << s_max <<
"attr_x,y,z"
572 abort(
"Implied Grid Size is Too Large!" );
579 if ( !
parameters.contains(
"mutate_sigma" ) )
601 if ( count_datasets < 2 || mgroup_count > (
count_datasets + 2 ) )
606 if ( mc_iterations < 2 || mgroup_count > (
mc_iterations + 2 ) )
675 QDateTime endTime = QDateTime::currentDateTime();
676 bool reduced_iter =
false;
680 int kc_iterations =
parameters[
"mc_iterations" ].toInt();
690 int walltime = qRound(
692 int cputime = qRound(
693 startTime .msecsTo( endTime ) / 1000.0 );
694 int maxrssmb = qRound( (
double)
maxrss / 1024.0 );
704 int wt_hr = walltime / 3600;
705 int wt_min = ( walltime - wt_hr * 3600 ) / 60;
706 int wt_sec = walltime - wt_hr * 3600 - wt_min * 60;
707 int ct_hr = cputime / 3600;
708 int ct_min = ( cputime - ct_hr * 3600 ) / 60;
709 int ct_sec = cputime - ct_hr * 3600 - ct_min * 60;
710 printf(
"Us_Mpi_Analysis has finished successfully"
711 " (Wall=%d:%02d:%02d Cpu=%d:%02d:%02d).\n"
712 , wt_hr, wt_min, wt_sec, ct_hr, ct_min, ct_sec );
717 send_udp(
"Finished: maxrss " + QString::number( maxrssmb )
718 +
" MB, total run seconds " + QString::number( cputime )
719 +
" (Reduced Datasets Count)" );
720 DbgLv(0) <<
"Finished: maxrss " << maxrssmb
721 <<
"MB, total run seconds " << cputime
722 <<
" (Reduced Datasets Count)";
725 else if ( reduced_iter )
727 send_udp(
"Finished: maxrss " + QString::number( maxrssmb )
728 +
" MB, total run seconds " + QString::number( cputime )
729 +
" (Reduced MC Iterations)" );
730 DbgLv(0) <<
"Finished: maxrss " << maxrssmb
731 <<
"MB, total run seconds " << cputime
732 <<
" (Reduced MC Iterations)";
738 send_udp(
"Finished: maxrss " + QString::number( maxrssmb )
739 +
" MB, total run seconds " + QString::number( cputime ) );
740 DbgLv(0) <<
"Finished: maxrss " << maxrssmb
741 <<
"MB, total run seconds " << cputime;
760 msg = QString( jobid + message ).toAscii();
767 QString gpfix = QString(
"(pmg %1) " ).arg(
my_group );
768 msg = QString( gpfix + message ).toAscii();
769 int size = msg.size();
778 MPI_Send( msg.data(),
797 printf(
"\n ***ABORTED***: %s\n\n", message.toAscii().data() );
802 MPI_Barrier( MPI_COMM_WORLD );
810 MPI_Abort( MPI_COMM_WORLD, error );
816 QDateTime submitTime, QDateTime startTime, QDateTime endTime )
818 QString fname =
"job_statistics.xml";
821 if ( ! file.open( QIODevice::WriteOnly | QIODevice::Text ) )
823 DbgLv(0) <<
"*WARNING* Unable to open job_statistics.xml file for write.";
827 QString sSubmitTime = submitTime.toString( Qt::ISODate ).replace(
"T",
" " );
828 QString sStartTime = startTime .toString( Qt::ISODate ).replace(
"T",
" " );
829 QString sEndTime = endTime .toString( Qt::ISODate ).replace(
"T",
" " );
831 QXmlStreamWriter xml( &file );
833 xml.setAutoFormatting(
true );
834 xml.writeStartDocument();
835 xml.writeDTD (
"<!DOCTYPE US_Statistics>" );
836 xml.writeStartElement (
"US_JobStatistics" );
837 xml.writeAttribute (
"version",
"1.0" );
838 xml.writeStartElement (
"statistics" );
839 xml.writeAttribute (
"walltime", QString::number( walltime ) );
840 xml.writeAttribute (
"cputime", QString::number( cputime ) );
841 xml.writeAttribute (
"cpucount", QString::number(
proc_count ) );
842 xml.writeAttribute (
"maxmemory", QString::number( maxrssmb ) );
843 xml.writeAttribute (
"cluster",
cluster );
845 xml.writeEndElement ();
847 xml.writeStartElement (
"id" );
849 xml.writeAttribute (
"dbname",
db_name );
850 xml.writeAttribute (
"requestid",
requestID );
851 xml.writeAttribute (
"submittime", sSubmitTime );
852 xml.writeAttribute (
"starttime", sStartTime );
853 xml.writeAttribute (
"endtime", sEndTime );
854 xml.writeAttribute (
"maxwalltime", QString::number(
max_walltime ) );
855 xml.writeAttribute (
"groupcount", QString::number(
mgroup_count ) );
856 xml.writeEndElement ();
857 xml.writeEndElement ();
858 xml.writeEndDocument ();
863 QFile f(
"analysis_files.txt" );
864 if ( ! f.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append ) )
866 abort(
"Could not open 'analysis_files.txt' for writing", -1 );
870 QTextStream out( &f );
871 out << fname <<
"\n";
879 if ( buk.
x_min > 0.0 )
886 double xinc = xmin / 1000.0;
891 else if ( buk.
x_max <= 0.0 )
918 QVector< double >& nnls_a, QVector< double >& nnls_b )
928 for (
int cc = 0; cc < nsolutes; cc++ )
930 for (
int pp = 0; pp < ndspts; pp++, kk++, jj++ )
941 for ( kk = 0; kk < ndspts; kk++, jj++ )