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

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

Programme cpupower : passage en double et ajout OPE=3 - Reza 7 Mai 2004

File size: 4.2 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 double
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
55void fop_3()
56{
57 T_Type s;
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
68/* Fonctions de timing (TCPU) - voir en fin de fichier */
69void InitTim(void);
70void PrtTim(const char * Comm);
71double GetPartialCPUTime();
72double GetTotalCPUTime();
73
74int main(int narg, char* arg[])
75{
76 int maxnprt = 1000;
77 int i,nprt;
78 double mflops;
79
80 /* SophyaInit(); */
81 InitTim(); /* Initializing the CPU timer */
82
83 if (narg < 2) {
84 printf("--- Programme cpupower: (Puissance de calcul) ---- \n");
85 printf(" Usage cpupower Op=1/2/3 [Size=20000] [CkPrt=0] \n");
86 return 1;
87 }
88 OPE = atoi(arg[1]);
89 SZ = 20000;
90 if (narg > 2) SZ = atoi(arg[2]);
91 ckprt = 0;
92 if (narg > 3) ckprt = atoi(arg[3]);
93
94 printf("::::::: cpupower: OPE=%d SZ= %d ::::::: \n", OPE,SZ);
95 x = malloc(SZ*sizeof(T_Type));
96 y = malloc(SZ*sizeof(T_Type));
97 z = malloc(SZ*sizeof(T_Type));
98
99 for(i=0; i<SZ; i++) {
100 x[i] = (T_Type)((random()%10000)-5000);
101 y[i] = (T_Type)((random()%10000)-5000);
102 y[i] = (T_Type)(0);
103 }
104 PrtTim("--Fin malloc+init x,y,z ");
105 if (OPE == 3) fop_3();
106 else if (OPE == 2) fop_2();
107 else fop_1();
108 PrtTim("---Fin OpeDoubleBoucle ");
109 mflops = N_OP/ GetPartialCPUTime()*1.e-6;
110 printf("-> Nb Operations= %g MFLOPS= %g \n",N_OP,mflops);
111 if (ckprt > 0) {
112 printf(" CheckPrint - ckprt= %d maxnprt= %d \n", ckprt, maxnprt);
113 nprt = 0;
114 for(i=0; i<SZ; i+= ckprt) {
115 printf("i=%d x[i]=%g y[i]=%g z[i]=%g \n", i, (double)x[i],
116 (double)y[i], (double)z[i]);
117 nprt++;
118 if (nprt > 1000) break;
119 }
120 }
121
122 PrtTim("----Fin cpupower");
123 printf(":::::: FIN cpupower N_OP= %g MFLOPS= %g ::::::: \n", N_OP,mflops);
124
125 free(x);
126 free(y);
127 free(z);
128 return 0;
129}
130
131
132static clock_t CPUT0, CPUT;
133static time_t ELT0, ELT;
134static double _totcpu, _partialcpu;
135
136void InitTim(void)
137{
138CPUT0 = CPUT = clock();
139ELT0 = ELT = time(NULL);
140_totcpu = _partialcpu = 0.;
141return;
142}
143double GetPartialCPUTime() { return _partialcpu; }
144double GetTotalCPUTime() { return _totcpu; }
145
146/* Nouvelle-Fonction */
147void PrtTim(const char * Comm)
148{
149float tcal,tcalt;
150clock_t cput;
151time_t elt;
152int etm,etmt;
153
154elt = time(NULL); cput = clock();
155tcalt = ( (float)(cput) - (float)(CPUT0) ) / (float)(CLOCKS_PER_SEC);
156tcal = ( (float)(cput) - (float)(CPUT) ) / (float)(CLOCKS_PER_SEC);
157_totcpu = tcalt;
158_partialcpu = tcal;
159
160etm = elt - ELT;
161etmt = elt - ELT0;
162printf("%s CPUTime: Total= %g (Partial= %g) Sec. \n",
163 Comm, tcalt, tcal);
164printf("ElapsedTime(hh:mm:ss): Total= %02d:%02d:%02d ",
165 etmt/3600, (etmt%3600)/60, etmt%60);
166printf(" (Partial= %02d:%02d:%02d)\n",
167 etm/3600, (etm%3600)/60, etm%60);
168
169ELT = elt;
170CPUT = cput;
171return;
172}
Note: See TracBrowser for help on using the repository browser.