00001 #include "statistics.h"
00002
00003 #include <unistd.h>
00004 #include <time.h>
00005
00006
00018
00019
00020
00021 void InitStatistics(unsigned int np,double v,Tstatistics *t)
00022 {
00023 t->np=np;
00024 t->volume=v;
00025 t->s_volume=0.0;
00026 t->s_diagonal=0.0;
00027
00028 t->n_max_level=0;
00029
00030 t->n_processed_boxes=0;
00031 t->n_solution_boxes=0;
00032 t->n_validated_solution_boxes=0;
00033 t->n_empty_boxes=0;
00034 t->n_splitted_boxes=0;
00035
00036 t->n_lost_boxes=0;
00037
00038 t->n_box_reductions=0;
00039
00040 t->n_errors=0;
00041
00042 t->t_init=GetTime(t);
00043 }
00044
00045 void CopyStatistics(Tstatistics *t_dst,Tstatistics *t_src)
00046 {
00047 t_dst->volume=t_src->volume;
00048 t_dst->s_volume=t_src->s_volume;
00049 t_dst->s_diagonal=t_src->s_diagonal;
00050
00051 t_dst->n_max_level=t_src->n_max_level;
00052
00053 t_dst->n_processed_boxes=t_src->n_processed_boxes;
00054 t_dst->n_solution_boxes=t_src->n_solution_boxes;
00055 t_dst->n_validated_solution_boxes=t_src->n_validated_solution_boxes;
00056 t_dst->n_empty_boxes=t_src->n_empty_boxes;
00057 t_dst->n_splitted_boxes=t_src->n_splitted_boxes;
00058
00059 t_dst->n_lost_boxes=t_src->n_lost_boxes;
00060
00061 t_dst->n_box_reductions=t_src->n_box_reductions;
00062
00063 t_dst->n_errors=t_src->n_errors;
00064
00065 t_dst->t_init=t_src->t_init;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 double GetTime(Tstatistics *t)
00075 {
00076 if (t->np>1)
00077 return((double)time(NULL));
00078 else
00079 {
00080 double ts;
00081 struct tms tm;
00082
00083 times(&tm);
00084 ts=(double)sysconf(_SC_CLK_TCK);
00085 return((double)((tm.tms_utime)+(tm.tms_stime)+(tm.tms_cutime)+(tm.tms_cstime))/ts);
00086 }
00087 }
00088
00089
00090
00091
00092 double GetElapsedTime(Tstatistics *t)
00093 {
00094 return(GetTime(t)-t->t_init);
00095 }
00096
00097
00098
00099
00100 double GetInitialTime(Tstatistics *t)
00101 {
00102 return(t->t_init);
00103 }
00104
00105
00106
00107
00108
00109 void SetInitialTime(double tm,Tstatistics *t)
00110 {
00111 t->t_init=tm;
00112 }
00113
00114
00115
00116
00117 void NewMaxLevel(unsigned int m,Tstatistics *t)
00118 {
00119 if (m>t->n_max_level)
00120 t->n_max_level=m;
00121 }
00122
00123
00124
00125
00126 void NewBoxProcessed(Tstatistics *t)
00127 {
00128 t->n_processed_boxes++;
00129 }
00130
00131
00132
00133
00134 void NewSolutionBox(boolean validated,double vs,double d,Tstatistics *t)
00135 {
00136 if (d>t->s_diagonal) t->s_diagonal=d;
00137 t->s_volume+=vs;
00138 t->n_solution_boxes++;
00139 if (validated)
00140 t->n_validated_solution_boxes++;
00141 }
00142
00143
00144
00145
00146
00147 void NewEmptyBox(Tstatistics *t)
00148 {
00149 t->n_empty_boxes++;
00150 }
00151
00152
00153
00154
00155
00156 void NewSplittedBox(Tstatistics *t)
00157 {
00158 t->n_splitted_boxes++;
00159 }
00160
00161
00162
00163
00164
00165 void NewRBError(Tstatistics *t)
00166 {
00167 t->n_errors++;
00168 }
00169
00170
00171
00172
00173 void NewLostBox(Tstatistics *t)
00174 {
00175 t->n_lost_boxes++;
00176 }
00177
00178
00179
00180
00181 void NewBoxReduction(Tstatistics *t)
00182 {
00183 t->n_box_reductions++;
00184 }
00185
00186 unsigned int GetNBoxReductions(Tstatistics *t)
00187 {
00188 return(t->n_box_reductions);
00189 }
00190
00191 unsigned int GetNSolutionBoxes(Tstatistics *t)
00192 {
00193 return(t->n_solution_boxes);
00194 }
00195
00196 void ResetNBoxReductions(Tstatistics *t)
00197 {
00198 t->n_box_reductions=0;
00199 }
00200
00201 void AddNBoxReductions(unsigned int nr,Tstatistics *t)
00202 {
00203 t->n_box_reductions+=nr;
00204 }
00205
00206
00207
00208
00209 void PrintStatistics(FILE *f,Tstatistics *t)
00210 {
00211 double tm;
00212
00213 tm=GetElapsedTime(t);
00214
00215 fprintf(f,"STATITISTICS FOR Cuik:\n\n");
00216
00217 fprintf(f,"Volume of the search space: %g\n",t->volume);
00218 fprintf(f,"Volume of the solution space: %g\n",t->s_volume);
00219 if (t->volume>0.0)
00220 fprintf(f," Volume ratio: %5.2f %%\n",t->s_volume/t->volume);
00221 fprintf(f,"Max solution diagonal: %g\n",t->s_diagonal);
00222
00223 fprintf(f,"Number of processors: %u\n",t->np);
00224 fprintf(f,"User time in process: %f seg (%f min)\n",tm,tm/60.0);
00225
00226 fprintf(f,"Box level information:\n");
00227 fprintf(f," N processed boxes : %6u\n",t->n_processed_boxes);
00228 fprintf(f," Max depth : %6u\n",t->n_max_level);
00229 fprintf(f," Types of boxes:\n");
00230
00231 fprintf(f," N solution boxes: %6u (%u)",t->n_solution_boxes,t->n_validated_solution_boxes);
00232 if (t->n_processed_boxes>0)
00233 fprintf(f," (%5.2f%%)",(double)t->n_solution_boxes/(double)t->n_processed_boxes*100.0);
00234 fprintf(f,"\n");
00235
00236 fprintf(f," N empty boxes : %6u ",t->n_empty_boxes);
00237 if (t->n_processed_boxes>0)
00238 fprintf(f," (%5.2f%%)",(double)t->n_empty_boxes/(double)t->n_processed_boxes*100.0);
00239 fprintf(f,"\n");
00240
00241 fprintf(f," N bisected boxes: %6u ",t->n_splitted_boxes);
00242 if (t->n_processed_boxes>0)
00243 fprintf(f," (%5.2f%%)",(double)t->n_splitted_boxes/(double)t->n_processed_boxes*100.0);
00244 fprintf(f,"\n");
00245
00246 #if (_USE_MPI)
00247 fprintf(f," N lost boxes : %6u ",t->n_lost_boxes);
00248 if (t->n_processed_boxes>0)
00249 fprintf(f," (%5.2f%%)",(double)t->n_lost_boxes/(double)t->n_processed_boxes*100.0);
00250 fprintf(f,"\n");
00251 #endif
00252
00253 fprintf(f," Box Reductions : %6u\n",t->n_box_reductions);
00254 fprintf(f," N Errors : %6u \n\n",t->n_errors);
00255
00256 fprintf(f,"\n==========================================================================\n\n");
00257 }
00258
00259
00260 void SaveStatistics(FILE *f,Tstatistics *t)
00261 {
00262 fwrite(t,sizeof(Tstatistics),1,f);
00263 }
00264
00265
00266 void LoadStatistics(FILE *f,Tstatistics *t)
00267 {
00268 fread(t,sizeof(Tstatistics),1,f);
00269 }
00270
00271
00272
00273
00274 void DeleteStatistics(Tstatistics *t)
00275 {
00276 }