source: Sophya/trunk/Eval/Speed/cpupower.c@ 2533

Last change on this file since 2533 was 2533, checked in by ansari, 21 years ago

Ajout d'un petit programme simple d'evaluation de la puissance CPU (cpupower) - Reza 7 Mai 2004

File size: 3.9 KB
Line 
1/* #include "machdefs.h" */
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <math.h>
6#include <string.h>
7#include <time.h>
8
9
10/* --------------------------------------------------- */
11/* --- Petit programme d'estimation de la puissance CPU */
12/* Compilation: csh> cc -O3 -o cpupower cpupower.c */
13/* R. Ansari - LAL Mai 2004 */
14/* --------------------------------------------------- */
15
16/* Choix de type d'operations float double int ... */
17#define T_Type float
18
19static int SZ; /* Taille de tableau */
20static double N_OP; /* Nb operations */
21static int OPE; /* Choix Operation fop_1 ou fop_2 */
22static int ckprt; /* > 0 : Print check apres calcul */
23
24/* Tableaux X,Y,Z */
25static T_Type * x;
26static T_Type * y;
27static T_Type * z;
28
29void fop_1()
30{
31 T_Type s;
32 int i,j,k;
33 printf("--- fop_1: Double Loop: z[k] = Somme_i(x[k]*y[i]) --- \n");
34 for(k=0; k<SZ; k++) {
35 for(i=0; i<SZ; i++) s += x[k]*y[i];
36 z[k] = s;
37 N_OP += 2*SZ;
38 }
39 return;
40}
41
42void fop_2()
43{
44 T_Type s;
45 int i,j,k;
46 printf("--- fop_2: Double Loop: z[k] = Somme_i(x[k]*y[i]+x[i]*y[k]) --- \n");
47 for(k=0; k<SZ; k++) {
48 for(i=0; i<SZ; i++) s += x[k]*y[i]+x[i]*y[k];
49 z[k] = s;
50 N_OP += 4*SZ;
51 }
52 return;
53}
54
55/* Fonctions de timing (TCPU) - voir en fin de fichier */
56void InitTim(void);
57void PrtTim(const char * Comm);
58double GetPartialCPUTime();
59double GetTotalCPUTime();
60
61int main(int narg, char* arg[])
62{
63 int maxnprt = 1000;
64 int i,nprt;
65 double mflops;
66
67 /* SophyaInit(); */
68 InitTim(); /* Initializing the CPU timer */
69
70 if (narg < 2) {
71 printf("--- Programme cpupower: (Puissance de calcul) ---- \n");
72 printf(" Usage cpupower Op=1/2 [Size=20000] [CkPrt=0] \n");
73 return;
74 }
75 OPE = atoi(arg[1]);
76 SZ = 20000;
77 if (narg > 2) SZ = atoi(arg[2]);
78 ckprt = 0;
79 if (narg > 3) ckprt = atoi(arg[3]);
80
81 printf("::::::: cpupower: OPE=%d SZ= %d ::::::: \n", OPE,SZ);
82 x = malloc(SZ*sizeof(T_Type));
83 y = malloc(SZ*sizeof(T_Type));
84 z = malloc(SZ*sizeof(T_Type));
85
86 for(i=0; i<SZ; i++) {
87 x[i] = (T_Type)((random()%10000)-5000);
88 y[i] = (T_Type)((random()%10000)-5000);
89 y[i] = (T_Type)(0);
90 }
91 PrtTim("--Fin malloc+init x,y,z ");
92 if (OPE == 2) fop_2();
93 else fop_1();
94 PrtTim("---Fin OpeDoubleBoucle ");
95 mflops = N_OP/ GetPartialCPUTime()*1.e-6;
96 printf("-> Nb Operations~= %g MFLOPS~= \n",N_OP,mflops);
97 if (ckprt > 0) {
98 printf(" CheckPrint - ckprt= %d maxnprt= %d \n", ckprt, maxnprt);
99 nprt = 0;
100 for(i=0; i<SZ; i+= ckprt) {
101 printf("i=%d x[i]=%g y[i]=%g z[i]=%g \n", i, (double)x[i],
102 (double)y[i], (double)z[i]);
103 nprt++;
104 if (nprt > 1000) break;
105 }
106 }
107
108 PrtTim("----Fin cpupower");
109 printf(":::::: FIN cpupower N_OP~= %g MFLOPS~= %g ::::::: \n", N_OP,mflops);
110
111 free(x);
112 free(y);
113 free(z);
114}
115
116
117static clock_t CPUT0, CPUT;
118static time_t ELT0, ELT;
119static double _totcpu, _partialcpu;
120
121void InitTim(void)
122{
123CPUT0 = CPUT = clock();
124ELT0 = ELT = time(NULL);
125_totcpu = _partialcpu = 0.;
126return;
127}
128double GetPartialCPUTime() { return _partialcpu; }
129double GetTotalCPUTime() { return _totcpu; }
130
131/* Nouvelle-Fonction */
132void PrtTim(const char * Comm)
133{
134float tcal,tcalt;
135clock_t cput;
136time_t elt;
137int etm,etmt;
138
139elt = time(NULL); cput = clock();
140tcalt = ( (float)(cput) - (float)(CPUT0) ) / (float)(CLOCKS_PER_SEC);
141tcal = ( (float)(cput) - (float)(CPUT) ) / (float)(CLOCKS_PER_SEC);
142_totcpu = tcalt;
143_partialcpu = tcal;
144
145etm = elt - ELT;
146etmt = elt - ELT0;
147printf("%s CPUTime: Total= %g (Partial= %g) Sec. \n",
148 Comm, tcalt, tcal);
149printf("ElapsedTime(hh:mm:ss): Total= %02d:%02d:%02d ",
150 etmt/3600, (etmt%3600)/60, etmt%60);
151printf(" (Partial= %02d:%02d:%02d)\n",
152 etm/3600, (etm%3600)/60, etm%60);
153
154ELT = elt;
155CPUT = cput;
156return;
157}
Note: See TracBrowser for help on using the repository browser.