From 2ec830ddedc4c09e2076a760494ab5eaff9b1ab2 Mon Sep 17 00:00:00 2001 From: michiguel Date: Sun, 17 Apr 2016 11:38:46 -0500 Subject: [PATCH] [1.2.2] include switch to turn on --timelog --- groups.c | 21 +++++++++++---------- main.c | 54 +++++++++++++++++++++++++++-------------------------- mytimer.c | 39 ++++++++++++++++++++++++++++++++++++++ mytimer.h | 6 ++++++ rating.c | 7 +++---- report.c | 8 ++++---- version.h | 2 +- version.txt | 2 +- 8 files changed, 93 insertions(+), 46 deletions(-) diff --git a/groups.c b/groups.c index 9f5165c..33db91a 100644 --- a/groups.c +++ b/groups.c @@ -762,18 +762,19 @@ groupvar_build (group_var_t *gv, player_t n_plyrs, const char **name, const stru super_t SP; super_t *sp = &SP; - printf ("%8.2lf | memory initialization... \n", timer_get()); + timelog("memory initialization..."); if (supporting_encmem_init (encounters->n, sp, &SElnk)) { - printf ("%8.2lf | scan games... \n", timer_get()); + timelog("scan games..."); scan_encounters (encounters->enc, encounters->n, gv->groupbelong, players->n, sp->SE2, &sp->N_se2, SElnk , &SElnk_n); - printf ("%8.2lf | general initialization...\n", timer_get()); + timelog("general initialization..."); convert_general_init (gv, n_plyrs); // Initiate groups from critical "super" encounters - printf ("%8.2lf | incorporate links into groups... N=%ld, Unique=%ld\n", timer_get(), (long)sp->N_se2, (long)SElnk_n); + timelog_ld("incorporate links into groups... N=", (long)sp->N_se2); + timelog_ld("incorporate links into groups... Unique=", (long)SElnk_n); groupset_reset_finding (gv); @@ -788,7 +789,7 @@ groupvar_build (group_var_t *gv, player_t n_plyrs, const char **name, const stru exit(EXIT_FAILURE); } - printf ("%8.2lf | start groups for each player with no links...\n", timer_get()); + timelog("start groups for each player with no links..."); // Initiate groups for each player present in the database that did not have // critical super encounters @@ -797,7 +798,7 @@ groupvar_build (group_var_t *gv, player_t n_plyrs, const char **name, const stru node_add_group (gv,i); } - printf ("%8.2lf | add list of participants... \n", timer_get()); + timelog("add list of participants..."); // for all the previous added groups, add respective list of participants for (i = 0; i < n_plyrs; i++) { if (node_is_occupied(gv,i)) { @@ -808,17 +809,17 @@ groupvar_build (group_var_t *gv, player_t n_plyrs, const char **name, const stru assert(groupset_sanity_check_nocombines(gv)); - printf ("%8.2lf | group joining and simplification... \n", timer_get()); + timelog("group joining and simplification..."); groupvar_simplify(gv); - printf ("%8.2lf | finish complex circuits... \n", timer_get()); + timelog("finish complex circuits..."); groupvar_finish(gv); - printf ("%8.2lf | sort... \n", timer_get()); + timelog("sort..."); groupvar_list_sort (gv); groupvar_finallist_sort(gv); - printf ("%8.2lf | assign new indexes... \n", timer_get()); + timelog("assign new indexes..."); groupvar_assign_newid (gv); ret = groupvar_counter(gv) ; diff --git a/main.c b/main.c index 1f81839..8cc0b74 100644 --- a/main.c +++ b/main.c @@ -129,6 +129,7 @@ struct helpline SH[] = { {'q', "quiet", no_argument, NULL, 0, "quiet mode (no progress updates on screen)"}, {'\0', "silent", no_argument, NULL, 0, "same as --quiet"}, {'Q', "terse", no_argument, NULL, 0, "same as --quiet, but shows simulation counter"}, +{'\0', "timelog", no_argument, NULL, 0, "outputs elapsed time after each step"}, {'a', "average", required_argument, "NUM", 0, "set rating for the pool average"}, {'A', "anchor", required_argument, "", 0, "anchor: rating given by '-a' is fixed for "}, {'V', "pool-relative",no_argument, NULL, 0, "errors relative to pool average, not to the anchor"}, @@ -168,7 +169,7 @@ struct helpline SH[] = { {'i', "include", required_argument, "FILE", 0, "include only games of participants present in FILE"}, {'x', "exclude", required_argument, "FILE", 0, "names in FILE will not have their games included"}, {'\0', "no-warnings", no_argument, NULL, 0, "supress warnings of names from -x or -i that do not match names in input file"}, -{'b', "column-format",required_argument, "FILE", 0, "format column output, each line being ,,\"Header\""}, +{'b', "column-format",required_argument, "FILE", 0, "format column output, each line form FILE being ,,\"Header\""}, {0, NULL, 0, NULL, 0, NULL}, @@ -380,6 +381,9 @@ int main (int argc, char *argv[]) cfs_column = FALSE; dowarning = TRUE; + // global default + TIMELOG = FALSE; + strlist_init(psl); @@ -402,6 +406,8 @@ int main (int argc, char *argv[]) synstr = opt_arg; } else if (!strcmp(long_options[longoidx].name, "no-warnings")) { dowarning = FALSE; + } else if (!strcmp(long_options[longoidx].name, "timelog")) { + TIMELOG = TRUE; } else { fprintf (stderr, "ERROR: %d\n", op); exit(EXIT_FAILURE); @@ -707,9 +713,9 @@ int main (int argc, char *argv[]) /*==== set input ====*/ -timer_reset(); -printf ("%8.2lf | start \n", timer_get()); -printf ("%8.2lf | input... \n", timer_get()); + timer_reset(); + timelog("start"); + timelog("input..."); if (NULL != (pdaba = database_init_frompgn (psl, synstr, quiet_mode))) { if (0 == pdaba->n_players || 0 == pdaba->n_games) { @@ -978,8 +984,8 @@ printf ("%8.2lf | input... \n", timer_get()); summations_init(&sfe); -printf ("%8.2lf | done with input\n", timer_get()); -printf ("%8.2lf | process groups if needed...\n", timer_get()); + timelog("done with input"); + timelog("process groups if needed..."); /*===== groups ========*/ @@ -989,19 +995,17 @@ printf ("%8.2lf | process groups if needed...\n", timer_get()); encounters_calculate (ENCOUNTERS_FULL, &Games, Players.flagged, &Encounters); if (group_is_output || groupcheck) { - - printf ("%8.2lf | processing groups... \n", timer_get()); - if (NULL == (gv = GV_make (&Encounters, &Players))) { - fprintf (stderr, "not enough memory for encounters allocation\n"); - exit(EXIT_FAILURE); - } + timelog("processing groups..."); + if (NULL == (gv = GV_make (&Encounters, &Players))) { + fprintf (stderr, "not enough memory for encounters allocation\n"); + exit(EXIT_FAILURE); + } } if (group_is_output) { - gamesnum_t intra; - gamesnum_t inter; + gamesnum_t intra, inter; - printf ("%8.2lf | sieve groups... \n", timer_get()); + timelog("sieve groups..."); GV_sieve (gv, &Encounters, &intra, &inter); GV_out (gv, groupf); @@ -1029,7 +1033,7 @@ printf ("%8.2lf | process groups if needed...\n", timer_get()); } } - // Not used beyond this point + // Not used anymore beyond this point if (gv) { GV_kill(gv); gv = NULL; @@ -1056,13 +1060,10 @@ printf ("%8.2lf | process groups if needed...\n", timer_get()); fprintf (stderr, "* Run switch -G to ignore warnings and force calculation *\n"); fprintf (stderr, "* (Attempting it may be very slow and may not converge) *\n"); fprintf (stderr, "*************************************************************\n"); - exit(EXIT_FAILURE); } - - -printf ("%8.2lf | calculate rating... \n", timer_get()); + timelog("calculate rating..."); Encounters.n = calc_rating ( quiet_mode , Forces_ML || Prior_mode @@ -1105,7 +1106,7 @@ printf ("%8.2lf | calculate rating... \n", timer_get()); /* Simulation block, begin */ if (Simulate > 1) { -printf ("%8.2lf | simulation block... \n", timer_get()); + timelog("simulation block..."); simul_smp ( cpus , Simulate @@ -1160,7 +1161,7 @@ printf ("%8.2lf | simulation block... \n", timer_get()); /*==== reports ====*/ -printf ("%8.2lf | output reports... \n", timer_get()); + timelog("output reports..."); all_report ( &Games , &Players @@ -1213,7 +1214,7 @@ printf ("%8.2lf | output reports... \n", timer_get()); } if (head2head_str != NULL) { -printf ("%8.2lf | head to head output... \n", timer_get()); + timelog("head to head output..."); head2head_output ( &Games , &Players @@ -1230,7 +1231,7 @@ printf ("%8.2lf | head to head output... \n", timer_get()); } if (Elostat_output) { -printf ("%8.2lf | output in elostat format... \n", timer_get()); + timelog("output in elostat format..."); cegt_output ( quiet_mode , &Games , &Players @@ -1245,7 +1246,7 @@ printf ("%8.2lf | output in elostat format... \n", timer_get()); , Decimals_set? OUTDECIMALS: 0); } -printf ("%8.2lf | release memory... \n", timer_get()); + timelog("release memory..."); /*==== clean up ====*/ @@ -1275,7 +1276,8 @@ printf ("%8.2lf | release memory... \n", timer_get()); mythread_mutex_destroy (&Summamtx); mythread_mutex_destroy (&Printmtx); -printf ("%8.2lf | DONE!! \n", timer_get()); + timelog("DONE!!"); + if (!quiet_mode) printf ("\ndone!\n"); return EXIT_SUCCESS; } diff --git a/mytimer.c b/mytimer.c index 0ec1b9d..0878932 100644 --- a/mytimer.c +++ b/mytimer.c @@ -1,5 +1,29 @@ +/* + Ordo is program for calculating ratings of engine or chess players + Copyright 2013 Miguel A. Ballicora + + This file is part of Ordo. + + Ordo is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Ordo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Ordo. If not, see . +*/ + #include +#include #include "mytimer.h" +#include "boolean.h" + +bool_t TIMELOG = TRUE; static clock_t Standard_clock = 0; @@ -12,3 +36,18 @@ double timer_get(void) { return ( (double)clock()-(double)Standard_clock)/(double)CLOCKS_PER_SEC; } + +void timelog (const char *s) +{ + if (TIMELOG) {printf ("%8.2lf | %s\n", timer_get(), s);} +} + +void timelog_ld (const char *s, long ld) +{ + if (TIMELOG) { + printf ("%8.2lf | %s%ld\n", timer_get(), s, ld); + } +} + + + diff --git a/mytimer.h b/mytimer.h index 403ba53..0774556 100644 --- a/mytimer.h +++ b/mytimer.h @@ -23,8 +23,14 @@ #define H_TIMER /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ +#include "boolean.h" + +extern bool_t TIMELOG; + extern void timer_reset(void); extern double timer_get(void); +extern void timelog (const char *s); +extern void timelog_ld (const char *s, long ld); /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ #endif diff --git a/rating.c b/rating.c index 1f97508..b7425ce 100644 --- a/rating.c +++ b/rating.c @@ -766,7 +766,7 @@ calc_rating_ordo correct_excess (n_players, flagged, excess, ratingof); } -printf ("%8.2lf | Post-Convergence rating estimation... \n", timer_get()); + timelog("Post-Convergence rating estimation..."); encounters_calculate(ENCOUNTERS_FULL, g, flagged, encount); enc = encount->enc; @@ -774,7 +774,7 @@ printf ("%8.2lf | Post-Convergence rating estimation... \n", timer_get()); calc_obtained_playedby(enc, n_enc, n_players, obtained, playedby); -printf ("%8.2lf | rate_super_players... \n", timer_get()); + timelog("rate_super_players..."); rate_super_players(quiet, enc, n_enc, Performance_type, n_players, ratingof, white_adv, flagged, name, draw_rate, BETA); @@ -784,8 +784,7 @@ printf ("%8.2lf | rate_super_players... \n", timer_get()); calc_obtained_playedby(enc, n_enc, n_players, obtained, playedby); - -printf ("%8.2lf | done with rating calculation. \n", timer_get()); + timelog("done with rating calculation."); *pWhite_advantage = white_adv; *pDraw_date = draw_rate; diff --git a/report.c b/report.c index cfbb8b0..5af77db 100644 --- a/report.c +++ b/report.c @@ -846,7 +846,7 @@ all_report ( const struct GAMES *g calc_obtained_playedby(e->enc, e->n, p->n, r->obtained, r->playedby); -printf ("%8.2lf | calculate output info... \n", timer_get()); + timelog("calculate output info..."); calc_output_info( e->enc, e->n, r->ratingof_results, p->n, sdev, out_info); @@ -854,7 +854,7 @@ printf ("%8.2lf | calculate output info... \n", timer_get()); r->sorted[j] = j; } -printf ("%8.2lf | sort... \n", timer_get()); + timelog("sort..."); my_qsort(r->ratingof_results, (size_t)p->n, r->sorted); @@ -866,7 +866,7 @@ printf ("%8.2lf | sort... \n", timer_get()); addabsent (list_chosen, 6); } -printf ("%8.2lf | calculation for printing... \n", timer_get()); + timelog("calculation for printing..."); /* calculation for printing */ for (i = 0; i < p->n; i++) { @@ -1000,7 +1000,7 @@ printf ("%8.2lf | calculation for printing... \n", timer_get()); memrel (q); memrel (listbuff); -printf ("%8.2lf | done with all reports. \n", timer_get()); + timelog("done with all reports."); return; } diff --git a/version.h b/version.h index 2e33006..1f48170 100755 --- a/version.h +++ b/version.h @@ -1,2 +1,2 @@ -#define VERSION "1.2.1" +#define VERSION "1.2.2" diff --git a/version.txt b/version.txt index 6085e94..23aa839 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.1 +1.2.2