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

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

Amelioration texte descriptif usage - Reza 18/05/2004

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