00001 // QMcBeaver 00002 // 00003 // Constructed by 00004 // 00005 // Michael Todd Feldmann 00006 // and 00007 // David Randall "Chip" Kent IV 00008 // 00009 // Copyright 2000. All rights reserved. 00010 // 00011 // drkent@users.sourceforge.net mtfeldmann@users.sourceforge.net 00012 00013 #ifndef QMCManager_H 00014 #define QMCManager_H 00015 00016 //The old macros conflicted with some Windows macros 00017 #define QMC_WORK_STEP 0 00018 #define QMC_REDUCE 1 00019 #define QMC_TERMINATE 2 00020 #define QMC_SYNCHRONIZE 3 00021 #define QMC_REDUCE_ALL 4 00022 00023 //These are all the signals that QMCManager has been programmed 00024 //to handle. 00025 enum signalType {SIG_REDUCE, SIG_INCREASE, SIG_QUIT, SIG_NOTHING}; 00026 00027 #include <iostream> 00028 #include <fstream> 00029 #include <string> 00030 #include <iomanip> 00031 #include <signal.h> 00032 00033 #include "QMCRun.h" 00034 #include "QMCDerivativeProperties.h" 00035 #include "QMCCorrelatedSamplingVMCOptimization.h" 00036 #include "QMCCopyright.h" 00037 #include "QMCProperties.h" 00038 #include "QMCProperty.h" 00039 #include "QMCPropertyArrays.h" 00040 #include "QMCNuclearForces.h" 00041 00042 #ifdef PARALLEL 00043 #include <mpi.h> 00044 #endif 00045 00046 using namespace std; 00047 00053 class QMCManager 00054 { 00055 public: 00059 QMCManager(); 00060 00064 ~QMCManager(); 00065 00071 void initialize(int argc, char **argv); 00072 00076 void finalize(); 00077 00084 bool run(bool equilibrate); 00085 00090 void optimize(); 00091 00095 void zeroOut(); 00096 00100 void resetTimers() 00101 { 00102 localTimers.reset(); 00103 } 00104 00109 void writeRestart(string filename); 00110 00116 void writeRestart(); 00117 00121 void writeBFDensity(); 00122 00126 void writeForces(); 00127 00133 void writeTimingData(ostream & strm); 00134 00139 QMCInput * getInputData(); 00140 00145 ostream * getResultsOutputStream(); 00146 00151 friend ostream & operator<<(ostream & strm, QMCManager & rhs); 00152 00157 static void receiveSignal(signalType signal); 00158 00159 private: 00160 00167 static bool SIGNAL_SAYS_QUIT; 00168 static bool REDUCE_ALL_NOW; 00169 static bool INCREASE_TIME; 00170 static bool PRINT_SIG_INFO; 00171 00175 QMCRun QMCnode; 00176 00186 QMCStopwatches localTimers; 00187 00192 QMCStopwatches globalTimers; 00193 00198 bool equilibrating; 00199 00205 bool done; 00206 00211 unsigned long iteration; 00212 00217 QMCProperties Properties_total; 00218 00228 QMCPropertyArrays fwProperties_total; 00229 00234 QMCProperties equilibrationProperties; 00235 00239 ofstream *qmcRslts; 00240 00244 ofstream *qmcOut; 00245 00250 Array1D<double> pllSpinHistogram_total; 00251 00256 Array1D<double> oppSpinHistogram_total; 00257 00262 Array1D< Array1D<double> > alphaHistograms_total; 00263 00268 Array1D< Array1D<double> > betaHistograms_total; 00269 00274 Array1D< Array1D<double> > pllxCorrelationDiagram_total; 00275 00280 Array1D< Array1D<double> > pllyCorrelationDiagram_total; 00281 00286 Array1D< Array1D<double> > pllzCorrelationDiagram_total; 00287 00292 Array1D< Array1D<double> > oppxCorrelationDiagram_total; 00293 00298 Array1D< Array1D<double> > oppyCorrelationDiagram_total; 00299 00304 Array1D< Array1D<double> > oppzCorrelationDiagram_total; 00305 00309 void initializeMPI(); 00310 00314 void initializeOutputs(); 00315 00319 void finalizeOutputs(); 00320 00324 void writeCheckpoint(); 00325 00330 void writeTransientProperties(int label); 00331 00339 void initializeCalculationState(long int iseed); 00340 00347 string sendAllProcessorsInputFileName(char **argv); 00348 00353 void sendAllProcessorsACommand(int command); 00354 00359 void gatherProperties(); 00360 00368 void gatherExtraProperties(); 00369 00374 void gatherDensities(); 00375 00380 void gatherForces(); 00381 00385 void gatherHistograms(); 00386 00390 void writeElectronDensityHistograms(); 00391 00397 void synchronizeDMCEnsemble(); 00398 00407 int pollForACommand(); 00408 00413 void writeEnergyResultsSummary(ostream & strm); 00414 void writeEnergyResultsHeader(ostream & strm); 00415 00420 void checkTerminationCriteria(); 00421 00426 void checkMaxStepsTerminationCriteria(); 00427 00432 void checkMaxTimeTerminationCriteria(); 00433 00438 void checkConvergenceBasedTerminationCriteria(); 00439 00440 void equilibration_step(); 00441 00445 void updateEstimatedEnergy(QMCProperties * Properties); 00446 00450 void updateTrialEnergy(double totalWeight, int nwalkers_original); 00451 00455 void updateEffectiveTimeStep(QMCProperties * Properties); 00456 00460 void synchronizationBarrier(); 00461 00466 void writeXML(ostream & strm); 00467 00475 bool readXML(istream & strm); 00476 }; 00477 00478 #endif