Changeset 2624 in Sophya for trunk/SophyaLib/SysTools/timing.c


Ignore:
Timestamp:
Sep 30, 2004, 3:22:10 PM (21 years ago)
Author:
cmv
Message:

rustine pour le calcul des temps CPU en overflow cmv 30/09/04

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/timing.c

    r2212 r2624  
    3232#include "timing.h"
    3333
    34 static clock_t CPUT0, CPUT;
    35 static time_t ELT0, ELT;
    36  
     34static clock_t CPUT0=0, CPUT=0;
     35static time_t ELT0=0, ELT=0;
     36/*-------  modifs Christophe 30/09/04
     37On somme nous memes les temps partiels pour avoir une autre
     38mesure du temps CPU total. En effet, pour des jobs longs
     39clock()-CPUT0 depasse la possibilite de stockage d'un entier
     4032 bits car clock() renvoit des microsecondes.
     41Par exemple pour un job de 20h = 72e+9 micro-secondes > 2^32
     42(Ca ne marche plus pour des jobs > 2146 sec ~= 2^32 microsec)
     43Seul un entier 64 bits pourrait donner un resultat correct
     44mais il n'existe pas sur toutes les plateformes.
     45-------*/
     46static double tcalt_sum = 0.;
    3747 
    3848/* Nouvelle-Fonction */
     
    4757CPUT0 = CPUT = clock();
    4858ELT0 = ELT = time(NULL);
     59tcalt_sum = 0.;
    4960return;
    5061}
     
    5768void PrtTim(const char * Comm)
    5869{
    59 float tcal,tcalt;
     70double tcal,tcalt;
    6071clock_t cput;
    6172time_t elt;
    62 int etm,etmt;
    63  
    64 elt = time(NULL);  cput = clock();
    65 tcalt = ( (float)(cput) - (float)(CPUT0) ) / (float)(CLOCKS_PER_SEC);
    66 tcal = ( (float)(cput) - (float)(CPUT) ) / (float)(CLOCKS_PER_SEC);
     73unsigned long etm,etmt;
     74
     75cput = clock();
     76tcalt = ( (double)(cput) - (double)(CPUT0) ) / (double)(CLOCKS_PER_SEC);
     77tcal = ( (double)(cput) - (double)(CPUT) ) / (double)(CLOCKS_PER_SEC);
     78
     79elt = time(NULL);
    6780etm = elt - ELT;
    6881etmt = elt - ELT0;
    69 printf("%s CPUTime: Total= %g  (Partial= %g) Sec. \n",
    70        Comm, tcalt, tcal);
     82/*-------  modifs Christophe 30/09/04
     83- tcalt_sum en 1/100 ieme de seconde:
     84  On imprime des Secondes que l'on somme N fois
     85  -> on se donne une precision a 1/100 de Seconde
     86- Au moment ou clock()>2^32 tcal devient negatif
     87  ==> On ne somme donc pas tcal et on TRICHE en sommant "etm"
     88      (pour etre vrai il faut que le process ait 100% du CPU !)
     89-------*/
     90if(tcal>0.) tcalt_sum += tcal*100.; else tcalt_sum += (double)etm*100.;
     91
     92printf("%s CPUTime: Total= %g  (Sum~= %.1f) (Partial= %g) Sec. \n",
     93       Comm, tcalt, tcalt_sum/100., tcal);
    7194printf("ElapsedTime(hh:mm:ss): Total= %02d:%02d:%02d ",
    7295       etmt/3600, (etmt%3600)/60, etmt%60);
    7396printf(" (Partial= %02d:%02d:%02d)\n",
    7497       etm/3600, (etm%3600)/60, etm%60);
    75  
     98
    7699ELT = elt;
    77100CPUT = cput;
Note: See TracChangeset for help on using the changeset viewer.