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

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

Ajout test simple boucle (fop0) ds cpupower.c - Reza 30/07/2004

File size: 6.1 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 -lm */
13/* R. Ansari - LAL Mai 2004 */
14/* --------------------------------------------------- */
15
16/* Choix de type d'operations float double int ... */
17#define T_Type double
18
19static int SZ=20000; /* Taille de tableau */
20static double N_OP=0; /* Nb operations */
21static int OPE=0; /* Choix Operation fop_1/2/3/4 */
22static int ckprt=0; /* > 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_0()
30{
31 T_Type s=0;
32 int i,k;
33 printf("--- fop_0: Simple Loop: z[k] = x[k]*y[i] --- \n");
34 for(k=0; k<SZ; k++) z[k] = x[k]*y[k];
35 N_OP += SZ;
36 return;
37}
38
39void fop_1()
40{
41 T_Type s=0;
42 int i,j,k;
43 printf("--- fop_1: Double Loop: z[k] = Somme_i(x[k]*y[i]) --- \n");
44 for(k=0; k<SZ; k++) {
45 for(i=0; i<SZ; i++) s += x[k]*y[i];
46 z[k] = s;
47 N_OP += 2*SZ;
48 }
49 return;
50}
51
52void fop_2()
53{
54 T_Type s=0;
55 int i,j,k;
56 printf("--- fop_2: Double Loop: z[k] = Somme_i(x[k]*y[i]+x[i]*y[k]) --- \n");
57 for(k=0; k<SZ; k++) {
58 for(i=0; i<SZ; i++) s += x[k]*y[i]+x[i]*y[k];
59 z[k] = s;
60 N_OP += 4*SZ;
61 }
62 return;
63}
64
65void fop_3()
66{
67 T_Type s=0;
68 int i,j,k;
69 printf("--- fop_3: Double Loop: z[k] = Somme_i(x[k]*y[i]+x[i]*y[k]-0.85*(y[k]+x[k])) --- \n");
70 for(k=0; k<SZ; k++) {
71 for(i=0; i<SZ; i++) s += x[k]*y[i]+x[i]*y[k]-0.85*(y[k]+x[k]);
72 z[k] = s;
73 N_OP += 7*SZ;
74 }
75 return;
76}
77
78void fop_4()
79{
80 T_Type s=0;
81 int i,j,k;
82 printf("--- fop_4: Double Loop: z[k] = Somme_i(x[k]*sin(y[i])+y[k]*cos(x[i])) --- \n");
83 for(k=0; k<SZ; k++) {
84 for(i=0; i<SZ; i++) s += x[k]*sin(y[i])+y[k]*cos(x[i]);
85 z[k] = s;
86 N_OP += 70*SZ; /* le facteur 70 est approximatif */
87 }
88 return;
89}
90
91void fop_5()
92{
93 T_Type s=0;
94 int i,j,k;
95 printf("--- fop_5: Double Loop: z[k] = Somme_i(x[k]*sin(y[i])+log(fabs(x[i])+0.1)+y[k]) --- \n");
96 for(k=0; k<SZ; k++) {
97 for(i=0; i<SZ; i++) s += x[k]*sin(y[i])+log(fabs(x[i])+0.1)+y[k];
98 z[k] = s;
99 N_OP += 100*SZ; /* le facteur 100 est approximatif */
100 }
101 return;
102}
103
104/* Fonctions de timing (TCPU) - voir en fin de fichier */
105void InitTim(void);
106void PrtTim(const char * Comm);
107double GetPartialCPUTime();
108double GetTotalCPUTime();
109
110int main(int narg, char* arg[])
111{
112 int maxnprt = 1000;
113 int nloop = 1000;
114 int i,nprt;
115 double mflops;
116
117 /* SophyaInit(); */
118 InitTim(); /* Initializing the CPU timer */
119
120 if (narg < 2) {
121 printf("--- Programme cpupower: (Puissance de calcul) ---- \n");
122 printf(" Usage cpupower Op=0/1/2/3/4/5 [Size=20000] [NLoop=1000] [CkPrt=0]\n");
123 printf(" Op=0 Simple Loop: z[k] = x[k]*y[k] effectue NLoop fois\n");
124 printf(" Size=10^6 par defaut, NLoop=100 \n");
125 printf(" Op=1 Double Loop: z[k] = Somme_i(x[k]*y[i]) \n");
126 printf(" Op=1 *,+=2 op / tour de boucle \n");
127 printf(" Op=2 Double Loop: z[k] = Somme_i(x[k]*y[i]+x[i]*y[k]) \n");
128 printf(" Op=2 2x(*,+)=4 op / tour de boucle \n");
129 printf(" Op=3 Double Loop: z[k] = Somme_i(x[k]*y[i]+x[i]*y[k]-0.85*(y[k]+x[k])) \n");
130 printf(" Op=3 7 op (*,+) / tour de boucle \n");
131 printf(" Op=4 Double Loop: z[k] = Somme_i(x[k]*sin(y[i])+y[k]*cos(x[i])) \n");
132 printf(" Op=4 ~ 70 op float / tour de boucle \n");
133 printf(" Op=5 Double Loop: z[k] = Somme_i(x[k]*sin(y[i])+log(fabs(x[i])+0.1)+y[k]) \n");
134 printf(" Op=5 ~ 100 op float / tour de boucle \n");
135 printf(" Test 4,5 Size=2000 par defaut \n");
136 return 1;
137 }
138 OPE = atoi(arg[1]);
139 SZ = 20000;
140 if (OPE == 0) SZ = 1000000;
141 if (OPE >= 4) SZ = 2000;
142 if (narg > 2) SZ = atoi(arg[2]);
143 nloop = 100;
144 if (narg > 3) nloop = atoi(arg[3]);
145 ckprt = 0;
146 if (narg > 3) ckprt = atoi(arg[4]);
147
148 printf("::::::: cpupower: OPE=%d SZ= %d ::::::: \n", OPE,SZ);
149 x = malloc(SZ*sizeof(T_Type));
150 y = malloc(SZ*sizeof(T_Type));
151 z = malloc(SZ*sizeof(T_Type));
152
153 for(i=0; i<SZ; i++) {
154 x[i] = (T_Type)((random()%10000)-5000);
155 y[i] = (T_Type)((random()%10000)-5000);
156 z[i] = (T_Type)(0);
157 }
158 PrtTim("--Fin malloc+init x,y,z ");
159 N_OP = 0;
160 if (OPE == 5) fop_5();
161 else if (OPE == 4) fop_4();
162 else if (OPE == 3) fop_3();
163 else if (OPE == 2) fop_2();
164 else if (OPE == 1) fop_1();
165 else for(i=0; i<nloop; i++) fop_0();
166 PrtTim("---Fin OpeDoubleBoucle ");
167 mflops = N_OP/ GetPartialCPUTime()*1.e-6;
168 printf("-> Nb Operations= %g MFLOPS= %g \n",N_OP,mflops);
169 if (ckprt > 0) {
170 printf(" CheckPrint - ckprt= %d maxnprt= %d \n", ckprt, maxnprt);
171 nprt = 0;
172 for(i=0; i<SZ; i+= ckprt) {
173 printf("i=%d x[i]=%g y[i]=%g z[i]=%g \n", i, (double)x[i],
174 (double)y[i], (double)z[i]);
175 nprt++;
176 if (nprt > 1000) break;
177 }
178 }
179
180 PrtTim("----Fin cpupower");
181 printf(":::::: FIN cpupower N_OP= %g MFLOPS= %g ::::::: \n", N_OP,mflops);
182
183 free(x);
184 free(y);
185 free(z);
186 return 0;
187}
188
189
190static clock_t CPUT0, CPUT;
191static time_t ELT0, ELT;
192static double _totcpu, _partialcpu;
193
194void InitTim(void)
195{
196CPUT0 = CPUT = clock();
197ELT0 = ELT = time(NULL);
198_totcpu = _partialcpu = 0.;
199return;
200}
201double GetPartialCPUTime() { return _partialcpu; }
202double GetTotalCPUTime() { return _totcpu; }
203
204/* Nouvelle-Fonction */
205void PrtTim(const char * Comm)
206{
207float tcal,tcalt;
208clock_t cput;
209time_t elt;
210int etm,etmt;
211
212elt = time(NULL); cput = clock();
213tcalt = ( (float)(cput) - (float)(CPUT0) ) / (float)(CLOCKS_PER_SEC);
214tcal = ( (float)(cput) - (float)(CPUT) ) / (float)(CLOCKS_PER_SEC);
215_totcpu = tcalt;
216_partialcpu = tcal;
217
218etm = elt - ELT;
219etmt = elt - ELT0;
220printf("%s CPUTime: Total= %g (Partial= %g) Sec. \n",
221 Comm, tcalt, tcal);
222printf("ElapsedTime(hh:mm:ss): Total= %02d:%02d:%02d ",
223 etmt/3600, (etmt%3600)/60, etmt%60);
224printf(" (Partial= %02d:%02d:%02d)\n",
225 etm/3600, (etm%3600)/60, etm%60);
226
227ELT = elt;
228CPUT = cput;
229return;
230}
Note: See TracBrowser for help on using the repository browser.