00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "QMCManager.h"
00032
00036 Random ran;
00037
00038 bool QMCManager::SIGNAL_SAYS_QUIT = false;
00039 bool QMCManager::REDUCE_ALL_NOW = false;
00040 bool QMCManager::INCREASE_TIME = false;
00041 bool QMCManager::PRINT_SIG_INFO = false;
00042
00043 QMCManager::QMCManager()
00044 {
00045 localTimers.getTotalTimeStopwatch()->start();
00046 }
00047
00048 QMCManager::~QMCManager()
00049 {
00050 finalizeOutputs();
00051 }
00052
00053 void QMCManager::initialize( int argc, char **argv )
00054 {
00055 initializeMPI();
00056 string runfile = sendAllProcessorsInputFileName( argv );
00057
00058 initializeOutputs();
00059
00060 if ( globalInput.flags.calculate_bf_density == 1 )
00061 {
00062 bool calcDensity = true;
00063 fwProperties_total.setCalcDensity( calcDensity,
00064 globalInput.WF.getNumberBasisFunctions() );
00065 }
00066
00067 if(globalInput.flags.nuclear_derivatives != "none")
00068 {
00069 if(globalInput.flags.nuclear_derivatives != "bin_force_density")
00070 {
00071 fwProperties_total.setCalcForces( true, globalInput.Molecule.getNumberAtoms(),3 );
00072 }
00073 else
00074 {
00075 fwProperties_total.setCalcForces( true, QMCNuclearForces::getNumBins(), 1 );
00076 }
00077 }
00078
00079 QMCnode.initialize( &globalInput );
00080
00081 done = false;
00082 iteration = 0;
00083
00084
00085 initializeCalculationState(globalInput.flags.iseed);
00086 }
00087
00088 void QMCManager::initializeMPI()
00089 {
00090 #ifdef PARALLEL
00091
00092
00093 if( MPI_Comm_size( MPI_COMM_WORLD, &globalInput.flags.nprocs ) )
00094 {
00095 cerr << "ERROR: MPI_Comm_size Error" << endl;
00096 exit( 1 );
00097 }
00098
00099
00100 if( MPI_Comm_rank( MPI_COMM_WORLD, &globalInput.flags.my_rank ) )
00101 {
00102 cerr << "ERROR: MPI_Comm_rank Error" << endl;
00103 exit( 1 );
00104 }
00105
00106 #else
00107 globalInput.flags.nprocs = 1;
00108
00109 globalInput.flags.my_rank = 0;
00110
00111 #endif
00112 }
00113
00114 void QMCManager::initializeOutputs()
00115 {
00116 globalInput.openConfigFile();
00117
00118 if( globalInput.flags.my_rank == 0 )
00119 {
00120 QMCCopyright copyright;
00121
00122
00123 qmcRslts = new ofstream( globalInput.flags.results_file_name.c_str() );
00124
00125 ( *qmcRslts ).setf( ios::fixed,ios::floatfield );
00126
00127 ( *qmcRslts ).precision( 10 );
00128
00129 if( !( *qmcRslts ) )
00130 {
00131 cerr << "ERROR opening " << globalInput.flags.results_file_name << endl;
00132 exit( 0 );
00133 }
00134
00135 *qmcRslts << copyright;
00136
00137
00138 qmcOut = new ofstream( globalInput.flags.output_file_name.c_str() );
00139
00140 ( *qmcOut ).setf( ios::fixed,ios::floatfield );
00141
00142 ( *qmcOut ).precision( 10 );
00143
00144 if( !( *qmcOut ) )
00145 {
00146 cerr << "ERROR opening " << globalInput.flags.output_file_name << endl;
00147 exit( 0 );
00148 }
00149
00150 *qmcOut << copyright;
00151
00152 cout.setf( ios::fixed,ios::floatfield );
00153
00154 cout.precision( 10 );
00155
00156 if( !true )
00157 cout << copyright;
00158 }
00159 else
00160 {
00161 qmcRslts = 0;
00162 qmcOut = 0;
00163 }
00164 }
00165
00166 void QMCManager::finalizeOutputs()
00167 {
00168 if( globalInput.flags.my_rank == 0 )
00169 {
00170
00171 ( *qmcRslts ).close();
00172 delete qmcRslts;
00173 qmcRslts = 0;
00174
00175
00176 ( *qmcOut ).close();
00177 delete qmcOut;
00178 qmcOut = 0;
00179 }
00180 }
00181
00182 void QMCManager::finalize()
00183 {
00184
00185 localTimers.stop();
00186
00187 if ( globalInput.flags.use_equilibration_array == 1 )
00188 {
00189 QMCnode.stopTimers();
00190 *localTimers.getPropagationStopwatch() =
00191 *QMCnode.getPropagationStopwatch();
00192 *localTimers.getEquilibrationStopwatch() =
00193 *localTimers.getEquilibrationStopwatch() +
00194 *QMCnode.getEquilibrationStopwatch();
00195 }
00196
00197 #ifdef PARALLEL
00198 MPI_Reduce( &localTimers,&globalTimers,1,QMCStopwatches::MPI_TYPE,
00199 QMCStopwatches::MPI_REDUCE,0,MPI_COMM_WORLD );
00200
00201 #else
00202 globalTimers = localTimers;
00203
00204 #endif
00205 }
00206
00207 void QMCManager::sendAllProcessorsACommand( int itag )
00208 {
00209 #ifdef PARALLEL
00210 localTimers.getSendCommandStopwatch()->start();
00211
00212 MPI_Request *request = new MPI_Request[ globalInput.flags.nprocs-1 ];
00213
00214
00215
00216 for( int i=1;i<globalInput.flags.nprocs;i++ )
00217 {
00218 MPI_Isend( &itag,1,MPI_INT,i,itag,MPI_COMM_WORLD,&request[ i-1 ] );
00219 }
00220
00221
00222 MPI_Status *status = new MPI_Status[ globalInput.flags.nprocs-1 ];
00223
00224 if( MPI_Waitall( globalInput.flags.nprocs-1, request, status ) )
00225 {
00226 cerr << "ERROR: MPI_Waitall Error (QMCManager::MPI_command_send)"
00227 << endl;
00228 }
00229
00230 delete [] request;
00231 delete [] status;
00232
00233 localTimers.getSendCommandStopwatch()->stop();
00234 #endif
00235 }
00236
00237 void QMCManager::gatherExtraProperties()
00238 {
00239 fwProperties_total.zeroOut();
00240 #ifdef PARALLEL
00241 localTimers.getGatherPropertiesStopwatch()->start();
00242
00243 int numCS = QMCnode.getFWProperties()->cs_Energies.dim1();
00244
00245 if(numCS > 1)
00246 MPI_Reduce( QMCnode.getFWProperties()->cs_Energies.array(),
00247 fwProperties_total.cs_Energies.array(),
00248 numCS,
00249 QMCProperty::MPI_TYPE,
00250 QMCProperty::MPI_REDUCE,
00251 0,MPI_COMM_WORLD );
00252
00253 int numAI = fwProperties_total.der.dim1();
00254 if(numAI > 0)
00255 {
00256 MPI_Reduce( &QMCnode.getFWProperties()->numDerHessSamples,
00257 &fwProperties_total.numDerHessSamples,
00258 1,
00259 MPI_INT,
00260 MPI_SUM,
00261 0,MPI_COMM_WORLD );
00262
00263 MPI_Reduce( QMCnode.getFWProperties()->der.array(),
00264 fwProperties_total.der.array(),
00265 numAI*fwProperties_total.der.dim2(),
00266 MPI_DOUBLE,
00267 MPI_SUM,
00268 0,MPI_COMM_WORLD );
00269
00270 for(int i=0; i<fwProperties_total.hess.dim1(); i++)
00271 MPI_Reduce( QMCnode.getFWProperties()->hess(i).array(),
00272 fwProperties_total.hess(i).array(),
00273 numAI * numAI,
00274 MPI_DOUBLE,
00275 MPI_SUM,
00276 0,MPI_COMM_WORLD );
00277 }
00278
00279 for(int i=0; i<fwProperties_total.props.dim1(); i++)
00280 {
00281 MPI_Reduce( QMCnode.getFWProperties()->props[i].array(),
00282 fwProperties_total.props[i].array(),
00283 fwProperties_total.props[i].dim1(),
00284 QMCProperty::MPI_TYPE, QMCProperty::MPI_REDUCE, 0, MPI_COMM_WORLD );
00285 }
00286
00287 localTimers.getGatherPropertiesStopwatch()->stop();
00288 #else
00289 fwProperties_total = *QMCnode.getFWProperties();
00290 #endif
00291
00292
00293
00294
00295
00296
00297 if(fwProperties_total.numDerHessSamples > 0)
00298 {
00299 fwProperties_total.der *= 1.0/fwProperties_total.numDerHessSamples;
00300 for(int i=0; i<fwProperties_total.hess.dim1(); i++)
00301 fwProperties_total.hess(i) *= 1.0/fwProperties_total.numDerHessSamples;
00302 }
00303 }
00304
00305 void QMCManager::gatherProperties()
00306 {
00307 synchronizationBarrier();
00308
00309 Properties_total.zeroOut();
00310 #ifdef PARALLEL
00311 localTimers.getGatherPropertiesStopwatch()->start();
00312
00313 MPI_Reduce( QMCnode.getProperties(), &Properties_total, 1,
00314 QMCProperties::MPI_TYPE, QMCProperties::MPI_REDUCE, 0, MPI_COMM_WORLD );
00315
00316 localTimers.getGatherPropertiesStopwatch()->stop();
00317 #else
00318 Properties_total = *QMCnode.getProperties();
00319 #endif
00320
00321 if( equilibrating )
00322 {
00323 QMCnode.zeroOut();
00324 }
00325 }
00326
00327 void QMCManager::synchronizeDMCEnsemble()
00328 {
00329 Properties_total.zeroOut();
00330 #ifdef PARALLEL
00331 localTimers.getCommunicationSynchronizationStopwatch()->start();
00332
00333
00334
00335 MPI_Allreduce( QMCnode.getProperties(), &Properties_total, 1,
00336 QMCProperties::MPI_TYPE, QMCProperties::MPI_REDUCE, MPI_COMM_WORLD );
00337
00338 localTimers.getCommunicationSynchronizationStopwatch()->stop();
00339 #else
00340 Properties_total = *QMCnode.getProperties();
00341 #endif
00342 }
00343
00344 void QMCManager::gatherDensities()
00345 {
00346 #ifdef PARALLEL
00347 localTimers.getGatherPropertiesStopwatch()->start();
00348
00349 Array1D<QMCProperty> localChiDensity = QMCnode.getFWProperties()->chiDensity;
00350
00351 MPI_Reduce( QMCnode.getFWProperties()->chiDensity.array(),
00352 fwProperties_total.chiDensity.array(),globalInput.WF.getNumberBasisFunctions(),
00353 QMCProperty::MPI_TYPE,QMCProperty::MPI_REDUCE,0,MPI_COMM_WORLD );
00354
00355 localTimers.getGatherPropertiesStopwatch()->stop();
00356 #else
00357
00358 for ( int i=0; i<globalInput.WF.getNumberBasisFunctions(); i++ )
00359 {
00360 fwProperties_total.chiDensity(i)=QMCnode.getFWProperties()->chiDensity( i );
00361 }
00362
00363 #endif
00364 }
00365
00366 void QMCManager::gatherForces()
00367 {
00368 #ifdef PARALLEL
00369 localTimers.getGatherPropertiesStopwatch()->start();
00370
00371 int numProps = QMCnode.getFWProperties()->nuclearForces(0).dim1() *
00372 QMCnode.getFWProperties()->nuclearForces(0).dim2();
00373
00374 for(int fw=0; fw<QMCnode.getFWProperties()->nuclearForces.dim1(); fw++)
00375 {
00376 MPI_Reduce( QMCnode.getFWProperties()->nuclearForces(fw).array(),
00377 fwProperties_total.nuclearForces(fw).array(),
00378 numProps,
00379 QMCProperty::MPI_TYPE,QMCProperty::MPI_REDUCE,0,MPI_COMM_WORLD );
00380 }
00381 localTimers.getGatherPropertiesStopwatch()->stop();
00382 #else
00383
00384 fwProperties_total.nuclearForces=QMCnode.getFWProperties()->nuclearForces;
00385
00386 #endif
00387 }
00388
00389 void QMCManager::gatherHistograms()
00390 {
00391 int nalpha = globalInput.WF.getNumberElectrons(true);
00392 int nbeta = globalInput.WF.getNumberElectrons(false);
00393 int nucleiTypes = globalInput.Molecule.NucleiTypes.dim1();
00394
00395 #ifdef PARALLEL
00396 localTimers.getGatherPropertiesStopwatch()->start();
00397
00398 if (nalpha > 1 || nbeta > 1)
00399 {
00400 pllSpinHistogram_total.allocate(5000);
00401 pllSpinHistogram_total = 0.0;
00402
00403 MPI_Reduce( QMCnode.getPllSpinHistogram()->array(),
00404 pllSpinHistogram_total.array(),5000,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
00405
00406 if (globalInput.flags.my_rank != 0)
00407 pllSpinHistogram_total.deallocate();
00408 }
00409
00410 if (nalpha > 0 && nbeta > 0)
00411 {
00412 oppSpinHistogram_total.allocate(5000);
00413 oppSpinHistogram_total = 0.0;
00414
00415 MPI_Reduce( QMCnode.getOppSpinHistogram()->array(),
00416 oppSpinHistogram_total.array(),5000,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD );
00417
00418 if (globalInput.flags.my_rank != 0)
00419 oppSpinHistogram_total.deallocate();
00420 }
00421
00422 if (nalpha > 0)
00423 {
00424 alphaHistograms_total.allocate(nucleiTypes);
00425 for (int k=0; k<nucleiTypes; k++)
00426 {
00427 alphaHistograms_total(k).allocate(5000);
00428 alphaHistograms_total(k) = 0.0;
00429 MPI_Reduce( (*QMCnode.getAlphaHistograms())(k).array(),
00430 alphaHistograms_total(k).array(),5000,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);
00431 if (globalInput.flags.my_rank != 0)
00432 alphaHistograms_total(k).deallocate();
00433 }
00434 if (globalInput.flags.my_rank != 0)
00435 alphaHistograms_total.deallocate();
00436 }
00437
00438 if (nbeta > 0)
00439 {
00440 betaHistograms_total.allocate(nucleiTypes);
00441 for (int k=0; k<nucleiTypes; k++)
00442 {
00443 betaHistograms_total(k).allocate(5000);
00444 betaHistograms_total(k) = 0.0;
00445 MPI_Reduce( (*QMCnode.getBetaHistograms())(k).array(),
00446 betaHistograms_total(k).array(),5000,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD);
00447 if (globalInput.flags.my_rank != 0)
00448 betaHistograms_total(k).deallocate();
00449 }
00450 if (globalInput.flags.my_rank != 0)
00451 betaHistograms_total.deallocate();
00452 }
00453
00454 if (nalpha > 1 || nbeta > 1)
00455 {
00456 if (globalInput.flags.writePllxCorrelationDiagram == 1)
00457 {
00458 pllxCorrelationDiagram_total.allocate(1000);
00459 for (int i=0; i<1000; i++)
00460 {
00461 pllxCorrelationDiagram_total(i).allocate(1000);
00462 pllxCorrelationDiagram_total(i) = 0.0;
00463 MPI_Reduce( (*QMCnode.getPllxCorrelationDiagram())(i).array(),
00464 pllxCorrelationDiagram_total(i).array(),1000,MPI_DOUBLE,MPI_SUM,0,
00465 MPI_COMM_WORLD);
00466 if (globalInput.flags.my_rank != 0)
00467 pllxCorrelationDiagram_total(i).deallocate();
00468 }
00469 if (globalInput.flags.my_rank != 0)
00470 pllxCorrelationDiagram_total.deallocate();
00471 }
00472 if (globalInput.flags.writePllyCorrelationDiagram == 1)
00473 {
00474 pllyCorrelationDiagram_total.allocate(1000);
00475 for (int i=0; i<1000; i++)
00476 {
00477 pllyCorrelationDiagram_total(i).allocate(1000);
00478 pllyCorrelationDiagram_total(i) = 0.0;
00479 MPI_Reduce( (*QMCnode.getPllyCorrelationDiagram())(i).array(),
00480 pllyCorrelationDiagram_total(i).array(),1000,MPI_DOUBLE,MPI_SUM,0,
00481 MPI_COMM_WORLD);
00482 if (globalInput.flags.my_rank != 0)
00483 pllyCorrelationDiagram_total(i).deallocate();
00484 }
00485 if (globalInput.flags.my_rank != 0)
00486 pllyCorrelationDiagram_total.deallocate();
00487 }
00488 if (globalInput.flags.writePllzCorrelationDiagram == 1)
00489 {
00490 pllzCorrelationDiagram_total.allocate(1000);
00491 for (int i=0; i<1000; i++)
00492 {
00493 pllzCorrelationDiagram_total(i).allocate(1000);
00494 pllzCorrelationDiagram_total(i) = 0.0;
00495 MPI_Reduce( (*QMCnode.getPllzCorrelationDiagram())(i).array(),
00496 pllzCorrelationDiagram_total(i).array(),1000,MPI_DOUBLE,MPI_SUM,0,
00497 MPI_COMM_WORLD);
00498 if (globalInput.flags.my_rank != 0)
00499 pllzCorrelationDiagram_total(i).deallocate();
00500 }
00501 if (globalInput.flags.my_rank != 0)
00502 pllzCorrelationDiagram_total.deallocate();
00503 }
00504 }
00505
00506 if (nalpha > 0 && nbeta > 0)
00507 {
00508 if (globalInput.flags.writeOppxCorrelationDiagram == 1)
00509 {
00510 oppxCorrelationDiagram_total.allocate(1000);
00511 for (int i=0; i<1000; i++)
00512 {
00513 oppxCorrelationDiagram_total(i).allocate(1000);
00514 oppxCorrelationDiagram_total(i) = 0.0;
00515 MPI_Reduce( (*QMCnode.getOppxCorrelationDiagram())(i).array(),
00516 oppxCorrelationDiagram_total(i).array(),1000,MPI_DOUBLE,MPI_SUM,0,
00517 MPI_COMM_WORLD);
00518 if (globalInput.flags.my_rank != 0)
00519 oppxCorrelationDiagram_total(i).deallocate();
00520 }
00521 if (globalInput.flags.my_rank != 0)
00522 oppxCorrelationDiagram_total.deallocate();
00523 }
00524 if (globalInput.flags.writeOppyCorrelationDiagram == 1)
00525 {
00526 oppyCorrelationDiagram_total.allocate(1000);
00527 for (int i=0; i<1000; i++)
00528 {
00529 oppyCorrelationDiagram_total(i).allocate(1000);
00530 oppyCorrelationDiagram_total(i) = 0.0;
00531 MPI_Reduce( (*QMCnode.getOppyCorrelationDiagram())(i).array(),
00532 oppyCorrelationDiagram_total(i).array(),1000,MPI_DOUBLE,MPI_SUM,0,
00533 MPI_COMM_WORLD);
00534 if (globalInput.flags.my_rank != 0)
00535 oppyCorrelationDiagram_total(i).deallocate();
00536 }
00537 if (globalInput.flags.my_rank != 0)
00538 oppyCorrelationDiagram_total.deallocate();
00539 }
00540 if (globalInput.flags.writeOppzCorrelationDiagram == 1)
00541 {
00542 oppzCorrelationDiagram_total.allocate(1000);
00543 for (int i=0; i<1000; i++)
00544 {
00545 oppzCorrelationDiagram_total(i).allocate(1000);
00546 oppzCorrelationDiagram_total(i) = 0.0;
00547 MPI_Reduce( (*QMCnode.getOppzCorrelationDiagram())(i).array(),
00548 oppzCorrelationDiagram_total(i).array(),1000,MPI_DOUBLE,MPI_SUM,0,
00549 MPI_COMM_WORLD);
00550 if (globalInput.flags.my_rank != 0)
00551 oppzCorrelationDiagram_total(i).deallocate();
00552 }
00553 if (globalInput.flags.my_rank != 0)
00554 oppzCorrelationDiagram_total.deallocate();
00555 }
00556 }
00557
00558 localTimers.getGatherPropertiesStopwatch()->stop();
00559 #else
00560
00561 if (nalpha > 1 || nbeta > 1)
00562 pllSpinHistogram_total = *QMCnode.getPllSpinHistogram();
00563
00564 if (nalpha > 0 && nbeta > 0)
00565 oppSpinHistogram_total = *QMCnode.getOppSpinHistogram();
00566
00567 if (nalpha > 0)
00568 {
00569 alphaHistograms_total.allocate(nucleiTypes);
00570 for (int k=0; k<nucleiTypes; k++)
00571 alphaHistograms_total(k) = (*QMCnode.getAlphaHistograms())(k);
00572 }
00573
00574 if (nbeta > 0)
00575 {
00576 betaHistograms_total.allocate(nucleiTypes);
00577 for (int k=0; k<nucleiTypes; k++)
00578 betaHistograms_total(k) = (*QMCnode.getBetaHistograms())(k);
00579 }
00580
00581 if (nalpha > 1 || nbeta > 1)
00582 {
00583 if (globalInput.flags.writePllxCorrelationDiagram == 1)
00584 {
00585 pllxCorrelationDiagram_total.allocate(1000);
00586 for (int i=0; i<1000; i++)
00587 pllxCorrelationDiagram_total(i) =
00588 (*QMCnode.getPllxCorrelationDiagram())(i);
00589 }
00590 if (globalInput.flags.writePllyCorrelationDiagram == 1)
00591 {
00592 pllyCorrelationDiagram_total.allocate(1000);
00593 for (int i=0; i<1000; i++)
00594 pllyCorrelationDiagram_total(i) =
00595 (*QMCnode.getPllyCorrelationDiagram())(i);
00596 }
00597 if (globalInput.flags.writePllzCorrelationDiagram == 1)
00598 {
00599 pllzCorrelationDiagram_total.allocate(1000);
00600 for (int i=0; i<1000; i++)
00601 pllzCorrelationDiagram_total(i) =
00602 (*QMCnode.getPllzCorrelationDiagram())(i);
00603 }
00604 }
00605
00606 if (nalpha > 0 && nbeta > 0)
00607 {
00608 if (globalInput.flags.writeOppxCorrelationDiagram == 1)
00609 {
00610 oppxCorrelationDiagram_total.allocate(1000);
00611 for (int i=0; i<1000; i++)
00612 oppxCorrelationDiagram_total(i) =
00613 (*QMCnode.getOppxCorrelationDiagram())(i);
00614 }
00615 if (globalInput.flags.writeOppyCorrelationDiagram == 1)
00616 {
00617 oppyCorrelationDiagram_total.allocate(1000);
00618 for (int i=0; i<1000; i++)
00619 oppyCorrelationDiagram_total(i) =
00620 (*QMCnode.getOppyCorrelationDiagram())(i);
00621 }
00622 if (globalInput.flags.writeOppzCorrelationDiagram == 1)
00623 {
00624 oppzCorrelationDiagram_total.allocate(1000);
00625 for (int i=0; i<1000; i++)
00626 oppzCorrelationDiagram_total(i) =
00627 (*QMCnode.getOppzCorrelationDiagram())(i);
00628 }
00629 }
00630 #endif
00631 }
00632
00633 int QMCManager::pollForACommand()
00634 {
00635 #ifdef PARALLEL
00636
00637 localTimers.getCommandPollingStopwatch() ->start();
00638
00639 int poll_result = 0;
00640 int itag;
00641 MPI_Status status;
00642 MPI_Request request;
00643
00644 MPI_Iprobe( MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
00645 &poll_result,&status );
00646
00647 if( poll_result==1 )
00648 {
00649 MPI_Irecv( &itag,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD,&request );
00650
00651
00652
00653 if( MPI_Waitall( 1, &request, &status ) )
00654 {
00655 cerr << "ERROR: MPI_Waitall ERROR (QMCManager::MPI_poll)" << endl;
00656 }
00657 }
00658 else
00659 {
00660 itag = -1;
00661 }
00662
00663 localTimers.getCommandPollingStopwatch() ->stop();
00664 return itag;
00665 #else
00666 return -1;
00667 #endif
00668 }
00669
00670 bool QMCManager::run(bool equilibrate)
00671 {
00672 localTimers.getTotalTimeStopwatch()->start();
00673 if(globalInput.flags.optimize_Psi == 1)
00674 {
00675 int numAI = globalInput.getNumberAIParameters();
00676 if(numAI != 0)
00677 globalInput.printAISummary();
00678 else
00679 {
00680 clog << "Error: you have " << numAI << " optimization parameters!" << endl;
00681 exit(0);
00682 }
00683
00688 QMCnode.initializeFunction();
00689 }
00690
00691 if( globalInput.flags.my_rank == 0 &&
00692 globalInput.flags.set_debug == 0)
00693 {
00694 clog << "*************** TheMan.run();" << endl;
00695 writeEnergyResultsHeader(clog);
00696 writeEnergyResultsHeader(*qmcOut);
00697 }
00698
00699 equilibrationProperties.zeroOut();
00700
00701 done = false;
00702 iteration = 0;
00703 int eq_steps = 0;
00704
00705
00706
00707
00708
00709
00710 if (equilibrate == true)
00711 equilibrating = true;
00712
00713 if( equilibrating )
00714 {
00715 globalInput.flags.dt = globalInput.flags.dt_equilibration;
00716 eq_steps = globalInput.flags.equilibration_steps;
00717 }
00718 else
00719 {
00720 globalInput.flags.dt = globalInput.flags.dt_run;
00721 eq_steps = 0;
00722 }
00723
00724
00725 ofstream *energy_strm_out = 0;
00726
00727 if( globalInput.flags.write_all_energies_out == 1 )
00728 {
00729
00730 char my_rank_str[ 32 ];
00731 #if defined(_WIN32) && !defined(__CYGWIN__)
00732 _snprintf( my_rank_str, 32, "%d", globalInput.flags.my_rank );
00733 #else
00734 snprintf( my_rank_str, 32, "%d", globalInput.flags.my_rank );
00735 #endif
00736 string filename = globalInput.flags.base_file_name + ".energy." +
00737 my_rank_str;
00738
00739
00740 energy_strm_out = new ofstream( filename.c_str() );
00741 energy_strm_out->precision( 15 );
00742 }
00743
00744
00745 if( globalInput.flags.parallelization_method == "pure_iterative" )
00746 {
00747 cerr << "FIX Add back in PI parallel" << endl;
00748 }
00749 else if( globalInput.flags.parallelization_method == "manager_worker" )
00750 {}
00751 else
00752 {
00753 cerr << "ERROR: Not a valid form of parallelization (";
00754 cerr << globalInput.flags.parallelization_method << ") in " << endl;
00755 cerr << "QMCManager::run()" << endl << "exiting now" << endl;
00756 exit( 1 );
00757 }
00758
00759 while( !done )
00760 {
00761 if(globalInput.flags.calculate_Derivatives != 0)
00762 if(!equilibrating)
00763 {
00764
00765 globalInput.flags.calculate_Derivatives = 1;
00766 }
00767 else
00768 {
00769
00770
00771 globalInput.flags.calculate_Derivatives = -1;
00772 }
00773
00774
00775 iteration++;
00776
00777 if( equilibrating ) localTimers.getEquilibrationStopwatch()->start();
00778 else
00779 {
00780 if ( globalInput.flags.use_equilibration_array == 1 )
00781 QMCnode.startTimers();
00782 else localTimers.getPropagationStopwatch()->start();
00783 }
00784
00785 bool writeConfigs = !equilibrating &&
00786 globalInput.flags.print_configs == 1 &&
00787 iteration%globalInput.flags.print_config_frequency == 0;
00788
00789 while( !QMCnode.step( writeConfigs, iteration - eq_steps ) )
00790 {
00791
00792 cerr << "Error on node " << globalInput.flags.my_rank << ": ";
00793 cerr << "QMCManager is trashing data and restarting" << endl;
00794
00795
00796
00797
00798
00799
00800 if( equilibrating ) localTimers.getEquilibrationStopwatch()->stop();
00801 else
00802 {
00803 if ( globalInput.flags.use_equilibration_array == 1 ) QMCnode.stopTimers();
00804 else localTimers.getPropagationStopwatch()->stop();
00805 }
00806
00807 equilibrating = globalInput.flags.equilibrate_first_opt_step;
00808
00809 if (equilibrating)
00810 {
00811 globalInput.flags.dt = globalInput.flags.dt_equilibration;
00812 eq_steps = globalInput.flags.equilibration_steps;
00813 }
00814 else
00815 {
00816 globalInput.flags.dt = globalInput.flags.dt_run;
00817 eq_steps = 0;
00818 }
00819
00820
00821 if( equilibrating ) localTimers.getEquilibrationStopwatch()->start();
00822 else
00823 {
00824 if ( globalInput.flags.use_equilibration_array == 1 ) QMCnode.startTimers();
00825 else localTimers.getPropagationStopwatch()->start();
00826 }
00827
00828 done = false;
00829 zeroOut();
00830 }
00831
00832 if( !equilibrating )
00833 {
00834
00835
00836
00837
00838 double weight = QMCnode.getWeights();
00839 weight *= QMCnode.getPopulationSizeBiasCorrectionFactor();
00840 Properties_total.newSample( QMCnode.getTimeStepProperties(),
00841 weight,QMCnode.getNumberOfWalkers() );
00842 }
00843
00844 if( equilibrating )
00845 {
00846 equilibrationProperties = equilibrationProperties +
00847 *QMCnode.getProperties();
00848 updateEffectiveTimeStep( &equilibrationProperties );
00849
00850 if( globalInput.flags.run_type == "diffusion" )
00851 updateTrialEnergy( QMCnode.getWeights(),
00852 globalInput.flags.number_of_walkers_initial );
00853 }
00854 else if( !equilibrating && globalInput.flags.run_type == "diffusion" )
00855 {
00856 if( globalInput.flags.synchronize_dmc_ensemble == 1 )
00857 {
00858 updateEstimatedEnergy( &Properties_total );
00859 updateEffectiveTimeStep( &Properties_total );
00860 }
00861 else
00862 {
00863 updateEstimatedEnergy( QMCnode.getProperties() );
00864 updateEffectiveTimeStep( QMCnode.getProperties() );
00865 }
00866
00867 updateTrialEnergy( QMCnode.getWeights(),
00868 globalInput.flags.number_of_walkers_initial );
00869 }
00870 else
00871 {
00872
00873
00874 updateEffectiveTimeStep( QMCnode.getProperties() );
00875 }
00876
00877 if( globalInput.flags.checkpoint == 1 &&
00878 iteration%globalInput.flags.checkpoint_interval == 0 )
00879 {
00880 writeCheckpoint();
00881
00882
00883 writeEnergyResultsSummary(clog);
00884 }
00885
00886 if( !equilibrating && globalInput.flags.write_all_energies_out == 1 )
00887 {
00888 QMCnode.writeEnergies( *energy_strm_out );
00889 }
00890
00891 if( !equilibrating && globalInput.flags.write_electron_densities == 1 )
00892 {
00893 QMCnode.calculateElectronDensities();
00894 }
00895
00896 if( globalInput.flags.use_hf_potential == 1 )
00897 {
00898 QMCnode.updateHFPotential();
00899 }
00900
00901 if( equilibrating )
00902 {
00903 localTimers.getEquilibrationStopwatch() ->stop();
00904
00905
00906
00907 }
00908 else
00909 {
00910 if ( globalInput.flags.use_equilibration_array == 1 ) QMCnode.stopTimers();
00911 else localTimers.getPropagationStopwatch() ->stop();
00912 }
00913
00914
00915
00916 if(QMCManager::SIGNAL_SAYS_QUIT)
00917 {
00918
00919
00920 static bool written = false;
00921 if(!written)
00922 {
00923 if(QMCManager::PRINT_SIG_INFO)
00924 cout << "Rank " << globalInput.flags.my_rank << " received SIGNAL_SAYS_QUIT."<< endl;
00925 written = true;
00926 }
00927 }
00928
00929 if(QMCManager::INCREASE_TIME)
00930 {
00931 QMCManager::INCREASE_TIME = false;
00932 if(QMCManager::PRINT_SIG_INFO)
00933 {
00934 cout << "Rank " << globalInput.flags.my_rank << " received INCREASE_TIME."<< endl;
00935 cout << "Max time changed from " << globalInput.flags.max_time_steps << " to ";
00936 }
00937 globalInput.flags.max_time_steps = (long)(globalInput.flags.max_time_steps*1.1);
00938 if(QMCManager::PRINT_SIG_INFO)
00939 cout << globalInput.flags.max_time_steps << endl;
00940 }
00941
00942 if( globalInput.flags.my_rank == 0 )
00943 {
00944
00945 if( QMCManager::REDUCE_ALL_NOW )
00946 {
00947 if(QMCManager::PRINT_SIG_INFO)
00948 cout << "Root received REDUCE_ALL_NOW."<< endl;
00949 QMCManager::REDUCE_ALL_NOW = false;
00950
00951 sendAllProcessorsACommand( QMC_REDUCE_ALL );
00952
00953
00954
00955
00956
00957 writeEnergyResultsSummary( cout );
00958 writeEnergyResultsSummary( *qmcOut );
00959
00960 gatherProperties();
00961 gatherExtraProperties();
00962
00963 if (globalInput.flags.write_electron_densities == 1)
00964 {
00965 gatherHistograms();
00966 if( globalInput.flags.my_rank == 0 )
00967 writeElectronDensityHistograms();
00968 }
00969
00970 if ( globalInput.flags.calculate_bf_density == 1 )
00971 gatherDensities();
00972
00973 if(globalInput.flags.nuclear_derivatives != "none")
00974 gatherForces();
00975
00976
00977 finalize();
00978
00979
00980
00981
00982
00983 writeEnergyResultsSummary( cout );
00984 writeEnergyResultsSummary( *qmcOut );
00985
00986 cout << *this;
00987 *getResultsOutputStream() << *this;
00988 writeTimingData( cout );
00989
00990 if(globalInput.flags.checkpoint == 1)
00991 writeCheckpoint();
00992
00993 writeRestart();
00994 }
00995
00996 if( iteration % globalInput.flags.mpireduce_interval == 0 )
00997 {
00998 sendAllProcessorsACommand( QMC_REDUCE );
00999
01000 gatherProperties();
01001 if ( globalInput.flags.write_electron_densities == 1)
01002 {
01003 gatherHistograms();
01004 writeElectronDensityHistograms();
01005 }
01006 checkTerminationCriteria();
01007 }
01008
01009 if( !equilibrating && globalInput.flags.run_type == "diffusion" &&
01010 globalInput.flags.synchronize_dmc_ensemble == 1 &&
01011 iteration % globalInput.flags.synchronize_dmc_ensemble_interval == 0 )
01012 {
01013 sendAllProcessorsACommand( QMC_SYNCHRONIZE );
01014 synchronizeDMCEnsemble();
01015 checkTerminationCriteria();
01016 }
01017
01018 if( done || QMCManager::SIGNAL_SAYS_QUIT )
01019 {
01020 done = true;
01021
01022 sendAllProcessorsACommand( QMC_TERMINATE );
01023 gatherProperties();
01024 gatherExtraProperties();
01025
01026 if (globalInput.flags.write_electron_densities == 1)
01027 {
01028 gatherHistograms();
01029 writeElectronDensityHistograms();
01030 }
01031
01032 if ( globalInput.flags.calculate_bf_density == 1 )
01033 gatherDensities();
01034
01035 if(globalInput.flags.nuclear_derivatives != "none")
01036 gatherForces();
01037
01038
01039 finalize();
01040 }
01041
01042 if( globalInput.flags.print_transient_properties &&
01043 iteration%globalInput.flags.print_transient_properties_interval == 0 )
01044 {
01045 writeTransientProperties( iteration );
01046 }
01047
01048 if( iteration%globalInput.flags.output_interval == 0 )
01049 {
01050 writeEnergyResultsSummary( cout );
01051 writeEnergyResultsSummary( *qmcOut );
01052 }
01053
01054 if( iteration%(100*globalInput.flags.output_interval) == 0 )
01055 {
01056 *getResultsOutputStream() << *this;
01057 writeTimingData( *getResultsOutputStream() );
01058 }
01059 }
01060 else
01061 {
01062
01063 int poll_result = QMC_WORK_STEP;
01064 do
01065 {
01066
01067 if( iteration%globalInput.flags.mpipoll_interval == 0
01068 || QMCManager::REDUCE_ALL_NOW
01069 || QMCManager::SIGNAL_SAYS_QUIT )
01070 {
01071 poll_result = pollForACommand();
01072 }
01073
01074 switch(poll_result)
01075 {
01076 case QMC_REDUCE:
01077 gatherProperties();
01078 if ( globalInput.flags.write_electron_densities == 1)
01079 gatherHistograms();
01080
01081 break;
01082
01083 case QMC_SYNCHRONIZE:
01084 synchronizeDMCEnsemble();
01085 break;
01086
01087 case QMC_TERMINATE:
01088 done = true;
01089
01090 gatherProperties();
01091 gatherExtraProperties();
01092
01093 if (globalInput.flags.write_electron_densities == 1)
01094 gatherHistograms();
01095
01096 if ( globalInput.flags.calculate_bf_density == 1 )
01097 gatherDensities();
01098
01099 if(globalInput.flags.nuclear_derivatives != "none")
01100 gatherForces();
01101
01102
01103 finalize();
01104 break;
01105
01106 case QMC_REDUCE_ALL:
01107
01108
01109
01110
01111
01112
01113 if(QMCManager::REDUCE_ALL_NOW && QMCManager::PRINT_SIG_INFO)
01114 cout << "Rank " << globalInput.flags.my_rank << " received REDUCE_ALL_NOW."<< endl;
01115 QMCManager::REDUCE_ALL_NOW = false;
01116
01117 gatherProperties();
01118 gatherExtraProperties();
01119
01120 if (globalInput.flags.write_electron_densities == 1)
01121 gatherHistograms();
01122
01123 if ( globalInput.flags.calculate_bf_density == 1 )
01124 gatherDensities();
01125
01126 if(globalInput.flags.nuclear_derivatives != "none")
01127 gatherForces();
01128
01129
01130 finalize();
01131
01132 if(globalInput.flags.checkpoint == 1)
01133 writeCheckpoint();
01134
01135 break;
01136 }
01137
01138 }
01139 while(poll_result != -1 && poll_result != QMC_WORK_STEP);
01140 }
01141
01142 if( equilibrating )
01143 {
01144 equilibration_step();
01145 }
01146 }
01147
01148
01149
01150
01151
01152
01153
01154 if( globalInput.flags.my_rank == 0 )
01155 {
01156 writeEnergyResultsSummary( cout );
01157 writeEnergyResultsSummary( *qmcOut );
01158 }
01159
01160 if( globalInput.flags.checkpoint == 1 )
01161 {
01162 writeCheckpoint();
01163 }
01164
01165 if( globalInput.flags.write_all_energies_out == 1 )
01166 {
01167 ( *energy_strm_out ).close();
01168 delete energy_strm_out;
01169 energy_strm_out = 0;
01170 }
01171
01172
01173
01174
01175
01176
01177 updateEstimatedEnergy(&Properties_total);
01178
01184 if(QMCManager::SIGNAL_SAYS_QUIT || Properties_total.energy.getAverage() > 0)
01185 return false;
01186 return true;
01187 }
01188
01189 void QMCManager::optimize()
01190 {
01191 localTimers.getOptimizationStopwatch() ->start();
01192
01193 int configsToSkip = 0;
01194
01195 if ( globalInput.flags.use_equilibration_array == 1 )
01196 {
01197 configsToSkip = 1 + ( iteration - globalInput.flags.equilibration_steps -
01198 QMCnode.getProperties() ->energy.getNumberSamples() ) /
01199 globalInput.flags.print_config_frequency;
01200 }
01201
01202 if( globalInput.flags.optimize_Psi )
01203 {
01204 QMCCorrelatedSamplingVMCOptimization::optimize( &globalInput,
01205 Properties_total,
01206 fwProperties_total,
01207 configsToSkip );
01208
01209
01210
01211 if( globalInput.flags.my_rank == 0 )
01212 {
01213 *qmcRslts << globalInput.JP << endl;
01214 }
01215
01216
01217 globalInput.openConfigFile();
01218 }
01219
01220 localTimers.getOptimizationStopwatch() ->stop();
01221 }
01222
01223 void QMCManager::equilibration_step()
01224 {
01225
01226
01227 if( globalInput.flags.equilibration_function == "step" )
01228 {
01229
01230
01231 if( iteration >= globalInput.flags.equilibration_steps )
01232 {
01233 QMCnode.zeroOut();
01234 equilibrating = false;
01235 globalInput.flags.dt = globalInput.flags.dt_run;
01236 }
01237 }
01238 else if( globalInput.flags.equilibration_function == "ramp" )
01239 {
01240 double ddt = ( globalInput.flags.dt_equilibration-globalInput.flags.dt_run ) / ( globalInput.flags.equilibration_steps-1 );
01241
01242 globalInput.flags.dt -= ddt;
01243
01244 if( iteration >= globalInput.flags.equilibration_steps )
01245 {
01246 globalInput.flags.dt = globalInput.flags.dt_run;
01247
01248 QMCnode.zeroOut();
01249 equilibrating = false;
01250 }
01251 }
01252 else if( globalInput.flags.equilibration_function == "CKAnnealingEquilibration1" )
01253 {
01254 if( globalInput.flags.CKAnnealingEquilibration1_parameter >=
01255 globalInput.flags.equilibration_steps )
01256 {
01257 cerr << "ERROR: For CKAnnealingEquilibration1, "
01258 << "CKAnnealingEquilbration1_parameter must be less than "
01259 << "equilibration_steps!" << endl;
01260 exit( 0 );
01261 }
01262
01263
01264 if( iteration >= globalInput.flags.equilibration_steps )
01265 {
01266 QMCnode.zeroOut();
01267 equilibrating = false;
01268 globalInput.flags.dt = globalInput.flags.dt_run;
01269 }
01270 else
01271 {
01272 if( iteration == -1*globalInput.flags.equilibration_steps + 1 )
01273 {
01274 globalInput.flags.old_walker_acceptance_parameter += -1000;
01275 }
01276 else if( iteration ==
01277 globalInput.flags.CKAnnealingEquilibration1_parameter )
01278 {
01279 globalInput.flags.old_walker_acceptance_parameter -= -1000;
01280 globalInput.flags.dt = globalInput.flags.dt_run;
01281 }
01282 }
01283 }
01284 else
01285 {
01286 cerr << "ERROR: Incorrect Equilibration Method Selected!" << endl;
01287 exit( 1 );
01288 }
01289 }
01290
01291 void QMCManager::writeElectronDensityHistograms()
01292 {
01293
01294
01295
01296 #define PI 3.14159265359
01297
01298 int nalpha = globalInput.WF.getNumberElectrons(true);
01299 int nbeta = globalInput.WF.getNumberElectrons(false);
01300
01301 string baseFileName = globalInput.flags.base_file_name;
01302
01303 double rValue;
01304 double normalHist;
01305 double dividedHist;
01306 double orbital;
01307 double totalWeight;
01308 double dr = QMCnode.getdr();
01309
01310 if (nalpha > 1 || nbeta > 1)
01311 {
01312 string pll_spin_filename = baseFileName + ".pll_pair_density";
01313 ofstream * pll_spin_strm = new ofstream(pll_spin_filename.c_str());
01314 pll_spin_strm->precision(15);
01315
01316
01317 totalWeight = 0.0;
01318 for (int i=0; i<pllSpinHistogram_total.dim1(); i++)
01319 totalWeight += pllSpinHistogram_total(i);
01320
01321 *pll_spin_strm << "#\t" << totalWeight << endl;
01322
01323 for (int i=0; i<pllSpinHistogram_total.dim1(); i++)
01324 {
01325 rValue = (i+0.5)*dr;
01326 normalHist = pllSpinHistogram_total(i)/totalWeight;
01327 dividedHist = normalHist/(4*PI*rValue*rValue*dr);
01328 orbital = sqrt(dividedHist);
01329 *pll_spin_strm << rValue << "\t" << pllSpinHistogram_total(i);
01330 *pll_spin_strm << "\t" << normalHist << "\t" << dividedHist << "\t";
01331 *pll_spin_strm << orbital << endl;
01332 }
01333 delete pll_spin_strm;
01334 pll_spin_strm = 0;
01335 pllSpinHistogram_total.deallocate();
01336 }
01337
01338 if (nalpha > 0 && nbeta > 0)
01339 {
01340 string opp_spin_filename = baseFileName + ".opp_pair_density";
01341 ofstream * opp_spin_strm = new ofstream(opp_spin_filename.c_str());
01342 opp_spin_strm->precision(15);
01343
01344
01345 totalWeight = 0.0;
01346 for (int i=0; i<oppSpinHistogram_total.dim1(); i++)
01347 totalWeight += oppSpinHistogram_total(i);
01348
01349 *opp_spin_strm << "#\t" << totalWeight << endl;
01350
01351 for (int i=0; i<oppSpinHistogram_total.dim1(); i++)
01352 {
01353 rValue = (i+0.5)*dr;
01354 normalHist = oppSpinHistogram_total(i)/totalWeight;
01355 dividedHist = normalHist/(4*PI*rValue*rValue*dr);
01356 orbital = sqrt(dividedHist);
01357 *opp_spin_strm << rValue << "\t" << oppSpinHistogram_total(i);
01358 *opp_spin_strm << "\t" << normalHist << "\t" << dividedHist << "\t";
01359 *opp_spin_strm << orbital << endl;
01360 }
01361 delete opp_spin_strm;
01362 opp_spin_strm = 0;
01363 oppSpinHistogram_total.deallocate();
01364 }
01365
01366 if (nalpha > 0 || nbeta > 0)
01367 {
01368 int nucleiTypes = globalInput.Molecule.NucleiTypes.dim1();
01369 string nucleusType;
01370
01371
01372 for (int i=0; i<nucleiTypes; i++)
01373 {
01374 nucleusType = globalInput.Molecule.NucleiTypes(i);
01375
01376 if (nalpha > 0)
01377 {
01378 string alpha_filename = baseFileName + "." + nucleusType +
01379 "-alpha.density";
01380
01381 ofstream * alpha_strm = new ofstream(alpha_filename.c_str());
01382 alpha_strm->precision(15);
01383
01384
01385 totalWeight = 0.0;
01386 for (int j=0; j<alphaHistograms_total(i).dim1(); j++)
01387 totalWeight += (alphaHistograms_total(i))(j);
01388
01389 *alpha_strm << "#\t" << totalWeight << endl;
01390
01391 for (int j=0; j<alphaHistograms_total(i).dim1(); j++)
01392 {
01393 rValue = (j+0.5)*dr;
01394 normalHist = (alphaHistograms_total(i))(j)/totalWeight;
01395 dividedHist = normalHist/(4*PI*rValue*rValue*dr);
01396 orbital = sqrt(dividedHist);
01397 *alpha_strm << rValue << "\t";
01398 *alpha_strm << (alphaHistograms_total(i))(j) << "\t";
01399 *alpha_strm << normalHist << "\t" << dividedHist << "\t";
01400 *alpha_strm << orbital << endl;
01401 }
01402 delete alpha_strm;
01403 alpha_strm = 0;
01404 alphaHistograms_total(i).deallocate();
01405 }
01406
01407 if (nbeta > 0)
01408 {
01409 string beta_filename = baseFileName + "." + nucleusType +
01410 "-beta.density";
01411
01412 ofstream * beta_strm = new ofstream(beta_filename.c_str());
01413 beta_strm->precision(15);
01414
01415
01416 totalWeight = 0.0;
01417 for (int j=0; j<betaHistograms_total(i).dim1(); j++)
01418 totalWeight += (betaHistograms_total(i))(j);
01419
01420 *beta_strm << "#\t" << totalWeight << endl;
01421
01422 for (int j=0; j<betaHistograms_total(i).dim1(); j++)
01423 {
01424 rValue = (j+0.5)*dr;
01425 normalHist = (betaHistograms_total(i))(j)/totalWeight;
01426 dividedHist = normalHist/(4*PI*rValue*rValue*dr);
01427 orbital = sqrt(dividedHist);
01428 *beta_strm << rValue << "\t" << (betaHistograms_total(i))(j);
01429 *beta_strm << "\t" << normalHist << "\t" << dividedHist;
01430 *beta_strm << "\t" << orbital << endl;
01431 }
01432 delete beta_strm;
01433 beta_strm = 0;
01434 betaHistograms_total(i).deallocate();
01435 }
01436 }
01437 alphaHistograms_total.deallocate();
01438 betaHistograms_total.deallocate();
01439 }
01440
01441 if (nalpha > 1 || nbeta > 1)
01442 {
01443 if (globalInput.flags.writePllxCorrelationDiagram == 1)
01444 {
01445 string pllxFile = baseFileName + ".pllx.CorrelationDiagram";
01446 ofstream * pllxStrm = new ofstream(pllxFile.c_str());
01447 pllxStrm->precision(15);
01448
01449
01450
01451 double min = globalInput.flags.pllxCorrelationDiagramMin;
01452 double max = globalInput.flags.pllxCorrelationDiagramMax;
01453 double dr = (max-min)/pllxCorrelationDiagram_total.dim1();
01454 double rvalue = min;
01455
01456 for (int i=0; i<pllxCorrelationDiagram_total.dim1(); i++)
01457 {
01458 rvalue = min + (i+0.5)*dr;
01459 *pllxStrm << "\t" << rvalue;
01460 }
01461 *pllxStrm << endl;
01462
01463 for (int i=0; i<pllxCorrelationDiagram_total.dim1(); i++)
01464 {
01465 rvalue = min + (i+0.5)*dr;
01466 *pllxStrm << rvalue;
01467 for (int j=0; j<(pllxCorrelationDiagram_total(i)).dim1(); j++)
01468 *pllxStrm << "\t" << (pllxCorrelationDiagram_total(i))(j);
01469 *pllxStrm << endl;
01470 pllxCorrelationDiagram_total(i).deallocate();
01471 }
01472 delete pllxStrm;
01473 pllxStrm = 0;
01474 pllxCorrelationDiagram_total.deallocate();
01475 }
01476 if (globalInput.flags.writePllyCorrelationDiagram == 1)
01477 {
01478 string pllyFile = baseFileName + ".plly.CorrelationDiagram";
01479 ofstream * pllyStrm = new ofstream(pllyFile.c_str());
01480 pllyStrm->precision(15);
01481
01482
01483
01484 double min = globalInput.flags.pllyCorrelationDiagramMin;
01485 double max = globalInput.flags.pllyCorrelationDiagramMax;
01486 double dr = (max-min)/pllyCorrelationDiagram_total.dim1();
01487 double rvalue = min;
01488
01489 for (int i=0; i<pllyCorrelationDiagram_total.dim1(); i++)
01490 {
01491 rvalue = min + (i+0.5)*dr;
01492 *pllyStrm << "\t" << rvalue;
01493 }
01494 *pllyStrm << endl;
01495
01496 for (int i=0; i<pllyCorrelationDiagram_total.dim1(); i++)
01497 {
01498 rvalue = min + (i+0.5)*dr;
01499 *pllyStrm << rvalue;
01500 for (int j=0; j<(pllyCorrelationDiagram_total(i)).dim1(); j++)
01501 *pllyStrm << "\t" << (pllyCorrelationDiagram_total(i))(j);
01502 *pllyStrm << endl;
01503 pllyCorrelationDiagram_total(i).deallocate();
01504 }
01505 delete pllyStrm;
01506 pllyStrm = 0;
01507 pllyCorrelationDiagram_total.deallocate();
01508 }
01509 if (globalInput.flags.writePllzCorrelationDiagram == 1)
01510 {
01511 string pllzFile = baseFileName + ".pllz.CorrelationDiagram";
01512 ofstream * pllzStrm = new ofstream(pllzFile.c_str());
01513 pllzStrm->precision(15);
01514
01515
01516
01517 double min = globalInput.flags.pllzCorrelationDiagramMin;
01518 double max = globalInput.flags.pllzCorrelationDiagramMax;
01519 double dr = (max-min)/pllzCorrelationDiagram_total.dim1();
01520 double rvalue = min;
01521
01522 for (int i=0; i<pllzCorrelationDiagram_total.dim1(); i++)
01523 {
01524 rvalue = min + (i+0.5)*dr;
01525 *pllzStrm << "\t" << rvalue;
01526 }
01527 *pllzStrm << endl;
01528
01529 for (int i=0; i<pllzCorrelationDiagram_total.dim1(); i++)
01530 {
01531 rvalue = min + (i+0.5)*dr;
01532 *pllzStrm << rvalue;
01533 for (int j=0; j<(pllzCorrelationDiagram_total(i)).dim1(); j++)
01534 *pllzStrm << "\t" << (pllzCorrelationDiagram_total(i))(j);
01535 *pllzStrm << endl;
01536 pllzCorrelationDiagram_total(i).deallocate();
01537 }
01538 delete pllzStrm;
01539 pllzStrm = 0;
01540 pllzCorrelationDiagram_total.deallocate();
01541 }
01542 }
01543 if (nalpha > 0 && nbeta > 0)
01544 {
01545 if (globalInput.flags.writeOppxCorrelationDiagram == 1)
01546 {
01547 string oppxFile = baseFileName + ".oppx.CorrelationDiagram";
01548 ofstream * oppxStrm = new ofstream(oppxFile.c_str());
01549 oppxStrm->precision(15);
01550
01551
01552
01553 double min = globalInput.flags.oppxCorrelationDiagramMin;
01554 double max = globalInput.flags.oppxCorrelationDiagramMax;
01555 double dr = (max-min)/oppxCorrelationDiagram_total.dim1();
01556 double rvalue = min;
01557
01558 for (int i=0; i<oppxCorrelationDiagram_total.dim1(); i++)
01559 {
01560 rvalue = min + (i+0.5)*dr;
01561 *oppxStrm << "\t" << rvalue;
01562 }
01563 *oppxStrm << endl;
01564
01565 for (int i=0; i<oppxCorrelationDiagram_total.dim1(); i++)
01566 {
01567 rvalue = min + (i+0.5)*dr;
01568 *oppxStrm << rvalue;
01569 for (int j=0; j<(oppxCorrelationDiagram_total(i)).dim1(); j++)
01570 *oppxStrm << "\t" << (oppxCorrelationDiagram_total(i))(j);
01571 *oppxStrm << endl;
01572 oppxCorrelationDiagram_total(i).deallocate();
01573 }
01574 delete oppxStrm;
01575 oppxStrm = 0;
01576 oppxCorrelationDiagram_total.deallocate();
01577 }
01578 if (globalInput.flags.writeOppyCorrelationDiagram == 1)
01579 {
01580 string oppyFile = baseFileName + ".oppy.CorrelationDiagram";
01581 ofstream * oppyStrm = new ofstream(oppyFile.c_str());
01582 oppyStrm->precision(15);
01583
01584
01585
01586 double min = globalInput.flags.oppyCorrelationDiagramMin;
01587 double max = globalInput.flags.oppyCorrelationDiagramMax;
01588 double dr = (max-min)/oppyCorrelationDiagram_total.dim1();
01589 double rvalue = min;
01590
01591 for (int i=0; i<oppyCorrelationDiagram_total.dim1(); i++)
01592 {
01593 rvalue = min + (i+0.5)*dr;
01594 *oppyStrm << "\t" << rvalue;
01595 }
01596 *oppyStrm << endl;
01597
01598 for (int i=0; i<oppyCorrelationDiagram_total.dim1(); i++)
01599 {
01600 rvalue = min + (i+0.5)*dr;
01601 *oppyStrm << rvalue;
01602 for (int j=0; j<(oppyCorrelationDiagram_total(i)).dim1(); j++)
01603 *oppyStrm << "\t" << (oppyCorrelationDiagram_total(i))(j);
01604 *oppyStrm << endl;
01605 oppyCorrelationDiagram_total(i).deallocate();
01606 }
01607 delete oppyStrm;
01608 oppyStrm = 0;
01609 oppyCorrelationDiagram_total.deallocate();
01610 }
01611 if (globalInput.flags.writeOppzCorrelationDiagram == 1)
01612 {
01613 string oppzFile = baseFileName + ".oppz.CorrelationDiagram";
01614 ofstream * oppzStrm = new ofstream(oppzFile.c_str());
01615 oppzStrm->precision(15);
01616
01617
01618
01619 double min = globalInput.flags.oppzCorrelationDiagramMin;
01620 double max = globalInput.flags.oppzCorrelationDiagramMax;
01621 double dr = (max-min)/oppzCorrelationDiagram_total.dim1();
01622 double rvalue = min;
01623
01624 for (int i=0; i<oppzCorrelationDiagram_total.dim1(); i++)
01625 {
01626 rvalue = min + (i+0.5)*dr;
01627 *oppzStrm << "\t" << rvalue;
01628 }
01629 *oppzStrm << endl;
01630
01631 for (int i=0; i<oppzCorrelationDiagram_total.dim1(); i++)
01632 {
01633 rvalue = min + (i+0.5)*dr;
01634 *oppzStrm << rvalue;
01635 for (int j=0; j<(oppzCorrelationDiagram_total(i)).dim1(); j++)
01636 *oppzStrm << "\t" << (oppzCorrelationDiagram_total(i))(j);
01637 *oppzStrm << endl;
01638 oppzCorrelationDiagram_total(i).deallocate();
01639 }
01640 delete oppzStrm;
01641 oppzStrm = 0;
01642 oppzCorrelationDiagram_total.deallocate();
01643 }
01644 }
01645
01646 #undef PI
01647 }
01648
01649 void QMCManager::writeEnergyResultsHeader( ostream & strm )
01650 {
01651 int width = 16;
01652 strm << setw(10) << "iteration";
01653 strm << setw(width) << "Eavg";
01654 strm << setw(width) << "Estd";
01655 strm << setw(width) << "Num. Samples";
01656 strm << setw(width) << "Tcorr";
01657 strm << setw(width) << "Acceptance";
01658
01659 if( globalInput.flags.run_type == "diffusion" )
01660 {
01661 strm << setw(width) << "Num. Walkers";
01662 strm << setw(width) << "Weights";
01663 strm << setw(width) << "Trial Energy";
01664 strm << setw(width) << "Eff. dt";
01665 }
01666 else
01667 {
01668 strm << setw(width) << "<p dR2>";
01669 strm << setw(width) << "Sample Var.";
01670 strm << setw(width) << "Summary";
01671 }
01672 strm << endl;
01673 }
01674
01675 void QMCManager::writeEnergyResultsSummary( ostream & strm )
01676 {
01677 int width = 15;
01678 double Eave = Properties_total.energy.getAverage();
01679 double Estd = Properties_total.energy.getStandardDeviation();
01680
01681 if( Estd > 1.0e6 )
01682 Estd = 0.0;
01683
01684 strm.flush();
01685
01686
01687
01688
01689
01690
01691
01692 long iter = iteration;
01693
01694 if( equilibrating )
01695 iter -= globalInput.flags.equilibration_steps;
01696
01697 strm << setw( 10 ) << iter << " ";
01698
01699 int fixedPrec = 10;
01700 int scienPrec = 7;
01701
01702 strm.setf(ios::fixed,ios::floatfield);
01703 if(fabs(Eave) >= 1000)
01704 {
01705 strm << setw(width) << setprecision(fixedPrec-1) << Eave << " ";
01706 }
01707 else
01708 {
01709 strm << setw(width) << setprecision(fixedPrec) << Eave << " ";
01710 }
01711
01712 if( fabs(Estd - 99) < 1e-20)
01713 {
01714 strm << setw(width) << 0 << " ";
01715 }
01716 else
01717 {
01718 strm.setf(ios::scientific,ios::floatfield);
01719 strm << setw(width) << setprecision(scienPrec) << Estd << " ";
01720 }
01721
01722 strm << setw(width) << Properties_total.energy.getNumberSamples() << " ";
01723
01724 strm.setf(ios::fixed,ios::floatfield);
01725 strm << setw(width) << setprecision(fixedPrec) << Properties_total.energy.getCorrelationLength() << " ";
01726 strm << setw(width) << setprecision(fixedPrec) << Properties_total.acceptanceProbability.getShortString() << " ";
01727
01728 if( globalInput.flags.run_type == "diffusion" )
01729 {
01730 strm << setw(width) << QMCnode.getNumberOfWalkers() << " ";
01731 strm.setf(ios::fixed,ios::floatfield);
01732 strm << setw(width) << setprecision(fixedPrec) << QMCnode.getWeights() << " ";
01733 strm << setw(width) << setprecision(fixedPrec) << globalInput.flags.energy_trial << " ";
01734
01735 strm.setf(ios::scientific,ios::floatfield);
01736 strm << setw(width) << setprecision(scienPrec) << globalInput.flags.dt_effective << " ";
01737 }
01738 else
01739 {
01740 strm.setf(ios::fixed,ios::floatfield);
01741 strm << setw(width) << setprecision(fixedPrec) << Properties_total.distanceMovedAccepted.getShortString() << " ";
01742 strm << setw(width) << setprecision(fixedPrec) << Properties_total.energy.getSeriallyCorrelatedVariance() << " ";
01743 strm << setw(width) << setprecision(fixedPrec) << Properties_total.energy.getShortString() << " ";
01744 }
01745
01746
01747
01748
01749
01750
01751
01752 strm << endl << setprecision( 15 );
01753 strm.flush();
01754 }
01755
01756 void QMCManager::writeTransientProperties( int label )
01757 {
01758
01759 string filename = globalInput.flags.base_file_name + ".properties." +
01760 StringManipulation::intToString( label );
01761
01762
01763 ofstream QMCprops( filename.c_str() );
01764
01765 QMCprops.setf( ios::fixed,ios::floatfield );
01766
01767 QMCprops.precision( 10 );
01768
01769 QMCprops << *this;
01770
01771 QMCprops.close();
01772 }
01773
01774 void QMCManager::writeTimingData( ostream & strm )
01775 {
01776 double ltime = localTimers.getTotalTimeStopwatch()->timeUS();
01777
01778 ltime /= (1.0e6 * 60.0 * 60.0);
01779
01780 strm.setf(ios::scientific);
01781 if(globalInput.flags.set_debug == 0)
01782 {
01783 strm << "Average iterations per hour: " << (iteration/ltime) << endl;
01784 strm << "Average iterations*walkers per hour: "
01785 << (iteration * globalInput.flags.number_of_walkers_initial / ltime) << endl;
01786 }
01787 strm.unsetf(ios::fixed);
01788 strm.unsetf(ios::scientific);
01789
01790
01791
01792
01793
01794 double time = globalTimers.getPropagationStopwatch()->timeUS();
01795
01796
01797 time /= Properties_total.energy.getNumberSamples();
01798 if(globalInput.flags.set_debug == 0)
01799 strm << "Average microseconds per sample: " << time << endl;
01800
01801
01802 time /= globalInput.flags.number_of_walkers_initial;
01803 strm << "Average microseconds per sample per num initial walkers: " << time << endl;
01804
01805 if(globalInput.flags.set_debug == 0)
01806 {
01807 strm << endl;
01808 strm << "Wallclock Time: " << *localTimers.getTotalTimeStopwatch() << endl;
01809 strm << globalTimers << endl;
01810 }
01811 }
01812
01813 void QMCManager::writeRestart()
01814 {
01815 writeRestart(globalInput.flags.restart_file_name);
01816 }
01817
01818 void QMCManager::writeRestart(string filename)
01819 {
01820 if(globalInput.flags.my_rank != 0)
01821 return;
01822
01823 time_t rawtime;
01824 struct tm * timeinfo;
01825 time ( &rawtime );
01826 timeinfo = localtime ( &rawtime );
01827
01828 ofstream restart( filename.c_str() );
01829
01830 if(! restart)
01831 {
01832 clog << "WARNING: we were unable to open restart file " << filename << endl;
01833 return;
01834 }
01835
01836 if(globalInput.flags.optimize_Psi == 1)
01837 {
01838
01839 restart << "# Optimization tag written " << asctime(timeinfo);
01840 restart << "# ";
01841 writeEnergyResultsHeader(restart);
01842 restart << "# ";
01843 writeEnergyResultsSummary(restart);
01844 }
01845
01846
01847
01848
01849
01850 ifstream input_file(globalInput.flags.input_file_name.c_str());
01851 string temp_string;
01852 getline(input_file,temp_string);
01853 while((temp_string.find("&",0) == string::npos)
01854 && (input_file.eof() != 1))
01855 {
01856 restart << temp_string << endl;
01857 getline(input_file,temp_string);
01858 }
01859 input_file.close();
01860
01861 restart.setf( ios::scientific,ios::floatfield );
01862 restart.precision( 15 );
01863
01864 restart << globalInput << endl;
01865 restart.close();
01866 }
01867
01868 void QMCManager::writeBFDensity()
01869 {
01870 ofstream density( globalInput.flags.density_file_name.c_str() );
01871 density.setf( ios::scientific,ios::floatfield );
01872 density.precision( 15 );
01873
01874 for ( int i=0; i<globalInput.WF.getNumberBasisFunctions(); i++ )
01875 {
01876 density << fwProperties_total.chiDensity( i ) << endl;
01877 }
01878
01879 density.close();
01880 }
01881
01882 void QMCManager::writeForces()
01883 {
01884 ofstream forces( globalInput.flags.force_file_name.c_str() );
01885 forces.setf( ios::scientific,ios::floatfield );
01886 forces.precision( 15 );
01887
01888 for (int i=0; i<fwProperties_total.nuclearForces.dim1(); i++)
01889 {
01890 forces << fwProperties_total.nuclearForces( i ) << endl;
01891 }
01892 forces.close();
01893 }
01894
01895 void QMCManager::writeXML( ostream & strm )
01896 {
01897
01898 ran.writeXML(strm);
01899
01900
01901 strm << "<NumberOfWalkers>\n" << QMCnode.getNumberOfWalkers()
01902 << "\n</NumberOfWalkers>" << endl;
01903
01904
01905 strm << "<Equilibrating>\n" << equilibrating
01906 << "\n</Equilibrating>" << endl;
01907
01908
01909 QMCnode.toXML( strm );
01910 }
01911
01912 void QMCManager::writeCheckpoint()
01913 {
01914
01915
01916
01917
01918
01919
01920 string filename =
01921 globalInput.flags.temp_dir
01922 + "/"
01923 + globalInput.flags.checkout_file_name
01924 + ".checkpoint."
01925 + StringManipulation::intToString( globalInput.flags.my_rank );
01926
01927
01928 ofstream QMCcheckpoint( filename.c_str() );
01929
01930 if (QMCcheckpoint)
01931 {
01932
01933 QMCcheckpoint.setf( ios::scientific,ios::floatfield );
01934 QMCcheckpoint.precision(15);
01935
01936 writeXML(QMCcheckpoint);
01937 QMCcheckpoint.close();
01938 }
01939 else
01940 {
01941 cerr << "Error: we failed to open file "
01942 << filename << " to write the checkpoint." << endl;
01943 exit(0);
01944 }
01945 }
01946
01947 bool QMCManager::readXML( istream & strm )
01948 {
01949
01950 if (!ran.readXML(strm))
01951 return false;
01952
01953 string temp;
01954
01955
01956 strm >> temp;
01957 if (temp != "<NumberOfWalkers>")
01958 return false;
01959 strm >> temp;
01960 globalInput.flags.number_of_walkers = atoi( temp.c_str() );
01961 strm >> temp;
01962 if (temp != "</NumberOfWalkers>")
01963 return false;
01964
01965
01966 strm >> temp;
01967 if (temp != "<Equilibrating>")
01968 return false;
01969 strm >> temp;
01970 equilibrating = atoi( temp.c_str() );
01971 strm >> temp;
01972 if (temp != "</Equilibrating>")
01973 return false;
01974
01975
01976 if (!QMCnode.readXML( strm ))
01977 return false;
01978
01979 if (equilibrating == 0)
01980 iteration = 0;
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991 if(globalInput.flags.run_type == "diffusion" )
01992 {
01993 if( globalInput.flags.synchronize_dmc_ensemble == 1 )
01994 {
01995 synchronizeDMCEnsemble();
01996 updateEstimatedEnergy( &Properties_total );
01997 updateEffectiveTimeStep( &Properties_total );
01998 }
01999 else
02000 {
02001 gatherProperties();
02002 updateEstimatedEnergy( QMCnode.getProperties() );
02003 updateEffectiveTimeStep( QMCnode.getProperties() );
02004 }
02005
02006 updateTrialEnergy( QMCnode.getWeights(),
02007 globalInput.flags.number_of_walkers_initial );
02008 }
02009 else
02010 {
02011 gatherProperties();
02012 updateEffectiveTimeStep(QMCnode.getProperties() );
02013 }
02014 return true;
02015 }
02016
02017 void QMCManager::initializeCalculationState(long int iseed)
02018 {
02019 if (globalInput.flags.use_available_checkpoints == 0)
02020 {
02021 localTimers.getInitializationStopwatch()->start();
02022 ran.initialize(iseed,globalInput.flags.my_rank);
02023 QMCnode.randomlyInitializeWalkers();
02024 if(globalInput.flags.optimize_Psi == 1)
02025 equilibrating = globalInput.flags.equilibrate_first_opt_step;
02026 else
02027 equilibrating = true;
02028 localTimers.getInitializationStopwatch()->stop();
02029 }
02030 else
02031 {
02032
02033 string filename =
02034 globalInput.flags.temp_dir
02035 + "/"
02036 + globalInput.flags.checkin_file_name
02037 + ".checkpoint."
02038 + StringManipulation::intToString( globalInput.flags.my_rank );
02039
02040 clog << "Reading in checkpoint file " << filename << "...";
02041
02042
02043 ifstream qmcCheckpoint(filename.c_str());
02044
02045 if(qmcCheckpoint)
02046 {
02047 localTimers.getInitializationStopwatch()->start();
02048 if(readXML(qmcCheckpoint))
02049 {
02050
02051 clog << " successful." << endl;
02052 qmcCheckpoint.close();
02053 writeEnergyResultsSummary(clog);
02054 if (globalInput.flags.zero_out_checkpoint_statistics == 1)
02055 clog << "Will zero the checkpoint." << endl;
02056 }
02057 else
02058 {
02059
02060
02061 clog << " unsuccessful; readXML failed." << endl;
02062
02063
02064
02065 clog << " Randomly initializing walkers." << endl;
02066 qmcCheckpoint.close();
02067 QMCnode.zeroOut();
02068 ran.initialize(iseed,globalInput.flags.my_rank);
02069 QMCnode.randomlyInitializeWalkers();
02070 equilibrating = globalInput.flags.equilibrate_first_opt_step;
02071 }
02072 localTimers.getInitializationStopwatch()->stop();
02073 }
02074 else
02075 {
02076
02077 clog << " unsuccessful; ifstream open failed." << endl;
02078
02079
02080
02081
02082 clog << "Randomly initializing walkers." << endl;
02083 localTimers.getInitializationStopwatch()->start();
02084 QMCnode.zeroOut();
02085 ran.initialize(iseed,globalInput.flags.my_rank);
02086 QMCnode.randomlyInitializeWalkers();
02087 equilibrating = globalInput.flags.equilibrate_first_opt_step;
02088 localTimers.getInitializationStopwatch()->stop();
02089 }
02090 }
02091 }
02092
02093 void QMCManager::receiveSignal(signalType signal)
02094 {
02095
02096
02097
02098
02099
02100 switch(signal)
02101 {
02102 case SIG_REDUCE:
02103 if(QMCManager::PRINT_SIG_INFO)
02104 clog << "QMCManager procedure for SIG_REDUCE: reduce all properties and dump results, then resume normally." << endl;
02105
02106 QMCManager::SIGNAL_SAYS_QUIT = true;
02107 break;
02108 case SIG_INCREASE:
02109 if(QMCManager::PRINT_SIG_INFO)
02110 clog << "QMCManager procedure for SIG_INCREASE: increase globalInput.flags.max_time_steps by 10%." << endl;
02111 QMCManager::INCREASE_TIME = true;
02112 break;
02113 case SIG_QUIT:
02114 if(QMCManager::PRINT_SIG_INFO)
02115 clog << "QMCManager procedure for SIG_QUIT: reduce and gracefully end." << endl;
02116 QMCManager::SIGNAL_SAYS_QUIT = true;
02117 break;
02118 case SIG_NOTHING:
02119 break;
02120 default:
02121 clog << "Warning: unknown signal sent." << endl;
02122 break;
02123 }
02124 }
02125
02126 void QMCManager::checkTerminationCriteria()
02127 {
02128 checkMaxStepsTerminationCriteria();
02129 checkMaxTimeTerminationCriteria();
02130 checkConvergenceBasedTerminationCriteria();
02131 }
02132
02133 void QMCManager::checkMaxStepsTerminationCriteria()
02134 {
02135 if( globalInput.flags.max_time_steps == 0 )
02136 return;
02137
02138 if(globalInput.flags.one_e_per_iter == 1 && false)
02139 {
02140
02141
02142
02143
02144
02145
02146 int numElectrons = globalInput.WF.getNumberElectrons();
02147 if( iteration >= numElectrons * globalInput.flags.max_time_steps )
02148 done = true;
02149
02150 }
02151 else
02152 {
02153 if( iteration >= globalInput.flags.max_time_steps )
02154 done = true;
02155 }
02156 }
02157
02158 void QMCManager::checkMaxTimeTerminationCriteria()
02159 {
02160 if( globalInput.flags.max_time <= 0 )
02161 return;
02162 static unsigned long total_time =
02163 (unsigned long)(globalInput.flags.max_time / globalInput.flags.dt_run);
02164
02165 if( Properties_total.energy.getNumberSamples() >=
02166 total_time )
02167 {
02168 done = true;
02169 }
02170 }
02171
02172 void QMCManager::checkConvergenceBasedTerminationCriteria()
02173 {
02174 if( Properties_total.energy.getNumberSamples() > 1 &&
02175 Properties_total.energy.getStandardDeviation() <=
02176 globalInput.flags.desired_convergence )
02177 {
02178 done = true;
02179 }
02180 }
02181
02182 void QMCManager::updateEstimatedEnergy( QMCProperties* Properties )
02183 {
02184
02185
02186 if( !equilibrating && Properties->energy.getNumberSamples() > 1 )
02187 {
02188 globalInput.flags.energy_estimated = Properties->energy.getAverage();
02189 }
02190 else
02191 {
02192
02193
02194 }
02195 }
02196
02197 void QMCManager::updateTrialEnergy( double weights, int nwalkers_init )
02198 {
02199
02200 double ratio = weights / nwalkers_init;
02201 double logRatio = 0;
02202 if(ratio > 1e-250)
02203 {
02204 logRatio = log( ratio );
02205 }
02206 else
02207 {
02208
02209 logRatio = 0;
02210 }
02211
02212 if( equilibrating )
02213 {
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223 globalInput.flags.energy_trial = globalInput.flags.energy_estimated -
02224 1.0 / globalInput.flags.dt_effective * logRatio;
02225 }
02226 else
02227 {
02228 if ( globalInput.flags.lock_trial_energy == 0 )
02229 globalInput.flags.energy_trial = globalInput.flags.energy_estimated -
02230 globalInput.flags.population_control_parameter * logRatio;
02231 }
02232 }
02233
02234 void QMCManager::updateEffectiveTimeStep( QMCProperties* Properties )
02235 {
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250 QMCDerivativeProperties derivativeProperties( Properties,
02251 &fwProperties_total,
02252 globalInput.flags.dt );
02253 globalInput.flags.dt_effective = derivativeProperties.getEffectiveTimeStep();
02254 }
02255
02256 void QMCManager::synchronizationBarrier()
02257 {
02258 #ifdef PARALLEL
02259
02260
02261
02262
02263
02264
02265
02266 localTimers.getCommunicationSynchronizationStopwatch() ->start();
02267 MPI_Barrier( MPI_COMM_WORLD );
02268 localTimers.getCommunicationSynchronizationStopwatch() ->stop();
02269 #endif
02270 }
02271
02272 string QMCManager::sendAllProcessorsInputFileName( char **argv )
02273 {
02274 #ifdef PARALLEL
02275
02276 const int maximum_filename_characters = 1024;
02277 char c_runfilename[ maximum_filename_characters ];
02278
02279 if( globalInput.flags.my_rank == 0 )
02280 {
02281
02282
02283 strncpy( c_runfilename, argv[ 1 ], maximum_filename_characters );
02284 }
02285
02286 if( MPI_Bcast( c_runfilename, maximum_filename_characters, MPI_CHAR, 0,
02287 MPI_COMM_WORLD ) )
02288 {
02289 cerr << "ERROR: Error broadcasting the runfile name to all processors"
02290 << endl;
02291 exit( 1 );
02292 }
02293
02294 string runfile = c_runfilename;
02295
02296 #else
02297 string runfile = argv[ 1 ];
02298 #endif
02299
02300 return runfile;
02301 }
02302
02303 QMCInput * QMCManager::getInputData()
02304 {
02305 return &globalInput;
02306 }
02307
02308 ostream * QMCManager::getResultsOutputStream()
02309 {
02310 return qmcRslts;
02311 }
02312
02313 void QMCManager::zeroOut()
02314 {
02315
02316 equilibrationProperties.zeroOut();
02317 QMCnode.zeroOut();
02318 Properties_total.zeroOut();
02319 fwProperties_total.zeroOut();
02320 }
02321
02322 ostream& operator<<( ostream & strm, QMCManager & rhs )
02323 {
02324 strm << "**************** Start of Results *****************" << endl;
02325 strm << rhs.Properties_total;
02326 strm << rhs.fwProperties_total;
02327
02328 QMCDerivativeProperties derivativeProperties( &rhs.Properties_total,
02329 &rhs.fwProperties_total, globalInput.flags.dt );
02330 strm << derivativeProperties << endl;
02331 strm << "**************** End of Results *****************" << endl;
02332 return strm;
02333 }