/* #include "machdefs.h" */ #include #include #include #include #include /* --------------------------------------------------- */ /* --- Petit programme d'estimation de la puissance CPU */ /* Compilation: csh> cc -O3 -o cpupower cpupower.c -lm */ /* OU csh> cc -O -DT_Type=int cpupowerI cpupower.c -lm */ /* R. Ansari - LAL Mai 2004 */ /* --------------------------------------------------- */ /* Choix de type d'operations float double int ... */ #ifndef T_Type #define T_Type double #endif static int SZ=20000; /* Taille de tableau */ static double N_OP=0; /* Nb operations */ static int OPE=0; /* Choix Operation fop_1/2/3/4 */ static int ckprt=0; /* > 0 : Print check apres calcul */ /* Tableaux X,Y,Z */ static T_Type * x; static T_Type * y; static T_Type * z; void fop_0() { T_Type s=0; int k; /* printf("--- fop_0: Simple Loop: z[k] = x[k]*y[i] --- \n"); */ for(k=0; k= 4) SZ = 2000; if (narg > 2) SZ = atoi(arg[2]); nloop = 100; if (narg > 3) nloop = atoi(arg[3]); ckprt = 0; if (narg > 4) ckprt = atoi(arg[4]); printf("::::::: cpupower: OPE=%d SZ= %d ::::::: \n", OPE,SZ); x = malloc(SZ*sizeof(T_Type)); y = malloc(SZ*sizeof(T_Type)); z = malloc(SZ*sizeof(T_Type)); for(i=0; i Nb Operations= %g MFLOPS= %g \n",N_OP,mflops); if (ckprt > 0) { printf(" CheckPrint - ckprt= %d maxnprt= %d \n", ckprt, maxnprt); nprt = 0; for(i=0; i 1000) break; } } PrtTim("----Fin cpupower"); printf(":::::: FIN cpupower N_OP= %g MFLOPS= %g ::::::: \n", N_OP,mflops); free(x); free(y); free(z); return 0; } static clock_t CPUT0, CPUT; static time_t ELT0, ELT; static double _totcpu, _partialcpu; void InitTim(void) { CPUT0 = CPUT = clock(); ELT0 = ELT = time(NULL); _totcpu = _partialcpu = 0.; return; } double GetPartialCPUTime() { return _partialcpu; } double GetTotalCPUTime() { return _totcpu; } /* Nouvelle-Fonction */ void PrtTim(const char * Comm) { float tcal,tcalt; clock_t cput; time_t elt; int etm,etmt; elt = time(NULL); cput = clock(); tcalt = ( (float)(cput) - (float)(CPUT0) ) / (float)(CLOCKS_PER_SEC); tcal = ( (float)(cput) - (float)(CPUT) ) / (float)(CLOCKS_PER_SEC); _totcpu = tcalt; _partialcpu = tcal; etm = elt - ELT; etmt = elt - ELT0; printf("%s CPUTime: Total= %g (Partial= %g) Sec. \n", Comm, tcalt, tcal); printf("ElapsedTime(hh:mm:ss): Total= %02d:%02d:%02d ", etmt/3600, (etmt%3600)/60, etmt%60); printf(" (Partial= %02d:%02d:%02d)\n", etm/3600, (etm%3600)/60, etm%60); ELT = elt; CPUT = cput; return; }