00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "QMCStopwatches.h"
00014
00015 QMCStopwatches::QMCStopwatches()
00016 {
00017 reset();
00018
00019 #ifdef PARALLEL
00020 if( !mpiTypeCreated )
00021 {
00022 mpiTypeCreated = true;
00023 buildMpiType();
00024 buildMpiReduce();
00025 }
00026 #endif
00027
00028 }
00029
00030 void QMCStopwatches::stop()
00031 {
00032 if(Initialization.isRunning()) Initialization.stop();
00033 if(Equilibration.isRunning()) Equilibration.stop();
00034 if(Propagation.isRunning()) Propagation.stop();
00035 if(Communication_send.isRunning()) Communication_send.stop();
00036 if(Communication_reduce.isRunning()) Communication_reduce.stop();
00037 if(Communication_synch.isRunning()) Communication_synch.stop();
00038 if(Communication_poll.isRunning()) Communication_poll.stop();
00039 if(Total.isRunning()) Total.stop();
00040 }
00041
00042 void QMCStopwatches::reset()
00043 {
00044 Total.reset();
00045 Initialization.reset();
00046 Equilibration.reset();
00047 Propagation.reset();
00048 Communication_send.reset();
00049 Communication_reduce.reset();
00050 Communication_synch.reset();
00051 Communication_poll.reset();
00052 Optimization.reset();
00053 }
00054
00055 Stopwatch * QMCStopwatches::getInitializationStopwatch()
00056 {
00057 return &(this->Initialization);
00058 }
00059
00060 Stopwatch * QMCStopwatches::getEquilibrationStopwatch()
00061 {
00062 return &(this->Equilibration);
00063 }
00064
00065 Stopwatch * QMCStopwatches::getPropagationStopwatch()
00066 {
00067 return &(this->Propagation);
00068 }
00069
00070 Stopwatch * QMCStopwatches::getSendCommandStopwatch()
00071 {
00072 return &(this->Communication_send);
00073 }
00074
00075 Stopwatch * QMCStopwatches::getGatherPropertiesStopwatch()
00076 {
00077 return &(this->Communication_reduce);
00078 }
00079
00080 Stopwatch * QMCStopwatches::getCommunicationSynchronizationStopwatch()
00081 {
00082 return &(this->Communication_synch);
00083 }
00084
00085 Stopwatch * QMCStopwatches::getCommandPollingStopwatch()
00086 {
00087 return &(this->Communication_poll);
00088 }
00089
00090 Stopwatch * QMCStopwatches::getOptimizationStopwatch()
00091 {
00092 return &(this->Optimization);
00093 }
00094
00095 Stopwatch * QMCStopwatches::getTotalTimeStopwatch()
00096 {
00097 return &(this->Total);
00098 }
00099
00100 void QMCStopwatches::operator =(const QMCStopwatches & rhs)
00101 {
00102 Initialization = rhs.Initialization;
00103 Equilibration = rhs.Equilibration;
00104 Propagation = rhs.Propagation;
00105 Communication_send = rhs.Communication_send;
00106 Communication_reduce = rhs.Communication_reduce;
00107 Communication_synch = rhs.Communication_synch;
00108 Communication_poll = rhs.Communication_poll;
00109 Optimization = rhs.Optimization;
00110 Total = rhs.Total;
00111 }
00112
00113 QMCStopwatches QMCStopwatches::operator+(QMCStopwatches & rhs)
00114 {
00115 QMCStopwatches result;
00116
00117 result.Initialization = this->Initialization + rhs.Initialization;
00118 result.Equilibration = this->Equilibration + rhs.Equilibration;
00119 result.Propagation = this->Propagation + rhs.Propagation;
00120 result.Communication_send = this->Communication_send +
00121 rhs.Communication_send;
00122 result.Communication_reduce = this->Communication_reduce +
00123 rhs.Communication_reduce;
00124 result.Communication_synch = this->Communication_synch +
00125 rhs.Communication_synch;
00126 result.Communication_poll = this->Communication_poll +
00127 rhs.Communication_poll;
00128 result.Optimization = this->Optimization + rhs.Optimization;
00129 result.Total = this->Total + rhs.Total;
00130
00131 return result;
00132 }
00133
00134 ostream& operator <<(ostream& strm, QMCStopwatches & rhs)
00135 {
00136 double total = rhs.getTotalTimeStopwatch()->timeUS() / 100.0;
00137 strm.setf(ios::fixed);
00138 strm.unsetf(ios::scientific);
00139 int prec = 2;
00140 int width = 10;
00141 strm << "Total Time: " << *rhs.getTotalTimeStopwatch()
00142 << setprecision(prec) << setw(width) << (double) rhs.getTotalTimeStopwatch()->timeUS() / total
00143 << " %" << endl;
00144 strm << "Initialization Time: " << *rhs.getInitializationStopwatch()
00145 << setprecision(prec) << setw(width) << (double) rhs.getInitializationStopwatch()->timeUS() / total
00146 << " %" << endl;
00147 strm << "Equilibration Time: " << *rhs.getEquilibrationStopwatch()
00148 << setprecision(prec) << setw(width) << (double) rhs.getEquilibrationStopwatch()->timeUS() / total
00149 << " %" << endl;
00150 strm << "Propagation Time: " << *rhs.getPropagationStopwatch()
00151 << setprecision(prec) << setw(width) << (double) rhs.getPropagationStopwatch()->timeUS() / total
00152 << " %" << endl;
00153 strm << "Send Command Time: " << *rhs.getSendCommandStopwatch()
00154 << setprecision(prec) << setw(width) << (double) rhs.getSendCommandStopwatch()->timeUS() / total
00155 << " %" << endl;
00156 strm << "Gather Properties Time: " << *rhs.getGatherPropertiesStopwatch()
00157 << setprecision(prec) << setw(width) << (double) rhs.getGatherPropertiesStopwatch()->timeUS() / total
00158 << " %" << endl;
00159 strm << "Synchronization Time: " << *rhs.getCommunicationSynchronizationStopwatch()
00160 << setprecision(prec) << setw(width) << (double) rhs.getCommunicationSynchronizationStopwatch()->timeUS() / total
00161 << " %" << endl;
00162 strm << "Poll for Command Time: " << *rhs.getCommandPollingStopwatch()
00163 << setprecision(prec) << setw(width) << (double) rhs.getCommandPollingStopwatch()->timeUS() / total
00164 << " %" << endl;
00165 strm << "Optimization Time: " << *rhs.getOptimizationStopwatch()
00166 << setprecision(prec) << setw(width) << (double) rhs.getOptimizationStopwatch()->timeUS() / total
00167 << " %" << endl;
00168
00169 return strm;
00170 }
00171
00172
00173
00174 #ifdef PARALLEL
00175
00176 bool QMCStopwatches::mpiTypeCreated = false;
00177
00178 void QMCStopwatches::buildMpiReduce()
00179 {
00180 MPI_Op_create((MPI_User_function*)Reduce_Function,
00181 true,&MPI_REDUCE);
00182 }
00183
00184 void QMCStopwatches::buildMpiType()
00185 {
00186 QMCStopwatches indata;
00187
00188 const int numberDataTypes = 9;
00189
00190 int block_lengths[numberDataTypes];
00191 MPI_Aint displacements[numberDataTypes];
00192 MPI_Aint addresses[numberDataTypes+1];
00193 MPI_Datatype typelist[numberDataTypes];
00194
00195 typelist[0] = Stopwatch::MPI_TYPE;
00196 typelist[1] = Stopwatch::MPI_TYPE;
00197 typelist[2] = Stopwatch::MPI_TYPE;
00198 typelist[3] = Stopwatch::MPI_TYPE;
00199 typelist[4] = Stopwatch::MPI_TYPE;
00200 typelist[5] = Stopwatch::MPI_TYPE;
00201 typelist[6] = Stopwatch::MPI_TYPE;
00202 typelist[7] = Stopwatch::MPI_TYPE;
00203 typelist[8] = Stopwatch::MPI_TYPE;
00204
00205 block_lengths[0] = 1;
00206 block_lengths[1] = 1;
00207 block_lengths[2] = 1;
00208 block_lengths[3] = 1;
00209 block_lengths[4] = 1;
00210 block_lengths[5] = 1;
00211 block_lengths[6] = 1;
00212 block_lengths[7] = 1;
00213 block_lengths[8] = 1;
00214
00215 MPI_Address(&indata, &addresses[0]);
00216 MPI_Address(&(indata.Initialization), &addresses[1]);
00217 MPI_Address(&(indata.Equilibration), &addresses[2]);
00218 MPI_Address(&(indata.Propagation), &addresses[3]);
00219 MPI_Address(&(indata.Communication_send), &addresses[4]);
00220 MPI_Address(&(indata.Communication_reduce), &addresses[5]);
00221 MPI_Address(&(indata.Communication_synch), &addresses[6]);
00222 MPI_Address(&(indata.Communication_poll), &addresses[7]);
00223 MPI_Address(&(indata.Optimization), &addresses[8]);
00224 MPI_Address(&(indata.Total), &addresses[9]);
00225
00226 displacements[0] = addresses[1] - addresses[0];
00227 displacements[1] = addresses[2] - addresses[0];
00228 displacements[2] = addresses[3] - addresses[0];
00229 displacements[3] = addresses[4] - addresses[0];
00230 displacements[4] = addresses[5] - addresses[0];
00231 displacements[5] = addresses[6] - addresses[0];
00232 displacements[6] = addresses[7] - addresses[0];
00233 displacements[7] = addresses[8] - addresses[0];
00234 displacements[8] = addresses[9] - addresses[0];
00235
00236 MPI_Type_struct(numberDataTypes, block_lengths, displacements, typelist,
00237 &MPI_TYPE);
00238 MPI_Type_commit(&MPI_TYPE);
00239 }
00240
00241
00242 MPI_Datatype QMCStopwatches::MPI_TYPE;
00243
00244 MPI_Op QMCStopwatches::MPI_REDUCE;
00245
00246 void QMCStopwatches::Reduce_Function(QMCStopwatches *in,
00247 QMCStopwatches *inout,
00248 int *len, MPI_Datatype *dptr)
00249 {
00250 *inout = *inout + *in;
00251 }
00252
00253
00254 #endif
00255