Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix make dist
[simgrid.git] / examples / saturate / saturate.c
1 /* $Id$ */
2
3 /* saturate - link saturation demo of GRAS features                         */
4 /* Authors: Martin Quinson                                                  */
5 /* Copyright (C) 2003 the OURAGAN project.                                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8    under the terms of the license (GNU LGPL) which comes with this package. */
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <signal.h>
14 #include <time.h>
15
16 #include <gras.h>
17
18 /* **********************************************************************
19  * Sensor code
20  * **********************************************************************/
21
22 /* Global private data */
23 typedef struct {
24   gras_sock_t *sock;
25 } sensor_data_t;
26
27 /* Function prototypes */
28 int sensor (int argc,char *argv[]);
29
30 int sensor (int argc,char *argv[]) {
31   gras_error_t errcode;
32   sensor_data_t *g=gras_userdata_new(sensor_data_t);  
33
34   if ((errcode=gras_sock_server_open(4000,4000,&(g->sock)))) { 
35     fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
36     return 1;
37   }
38
39   if (grasbw_register_messages()) {
40     gras_sock_close(g->sock);
41     return 1;
42   }
43
44   while (1) {
45     if ((errcode=gras_msg_handle(60.0)) && errcode != timeout_error) {
46       fprintf(stderr,"Sensor: Error '%s' while handling message\n",
47               gras_error_name(errcode));
48     }
49   }
50
51   gras_sleep(5,0);
52   return gras_sock_close(g->sock);
53 }
54
55 /* **********************************************************************
56  * Maestro code
57  * **********************************************************************/
58
59 /* Global private data */
60 typedef struct {
61   gras_sock_t *sock;
62 } maestro_data_t;
63
64 /* Function prototypes */
65 int maestro (int argc,char *argv[]);
66 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2);
67
68 double XP(const char *bw1, const char *bw2, const char *sat1, const char *sat2) {
69   gras_error_t errcode;
70   int bufSize=32 * 1024;
71   int expSize=64 * 1024;
72   int msgSize=64 * 1024;
73   int satSize=msgSize * 10;
74   double sec, bw, sec_sat,bw_sat;
75
76   if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec,&bw))) {
77     fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
78     return -1;
79   }
80    
81   fprintf(stderr,"MAESTRO: BW(%s,%s) => %f sec, achieving %f Mb/s\n",bw1,bw2,sec,bw);
82
83   if ((errcode=grasbw_saturate_start(sat1,4000,sat2,4000,satSize,60))) {
84     fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
85             gras_error_name(errcode));
86     return -1;
87   }
88   gras_sleep(1,0);
89   if ((errcode=grasbw_request(bw1,4000,bw2,4000,bufSize,expSize,msgSize,&sec_sat,&bw_sat))) {
90     fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
91     return -1;
92   }
93    
94   fprintf(stderr,"MAESTRO: BW(%s,%s//%s,%s) => %f sec, achieving %f Mb/s\n",
95          bw1,bw2,sat1,sat2,sec_sat,bw_sat);
96
97   if ((errcode=grasbw_saturate_stop(sat1,4000,sat2,4000))) {
98     fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
99             gras_error_name(errcode));
100     return -1;
101   }
102
103   if (bw_sat/bw < 0.7) {
104     fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE !!!\n");
105   } 
106   if (bw/bw_sat < 0.7) {
107     fprintf(stderr,"MAESTRO: THERE IS SOME INTERFERENCE (and Im a cretin) !!!\n");
108   } 
109   return bw_sat/bw;
110
111 }
112
113 //#define MAXHOSTS 33
114 #define MAXHOSTS 4
115
116 int maestro(int argc,char *argv[]) {
117   int bufSize=32 * 1024;
118   int expSize= 1024 * 1024;
119   int msgSize=expSize;
120   int satSize=msgSize * 100;
121   double dummy,beginSim;
122   gras_error_t errcode;
123   maestro_data_t *g=gras_userdata_new(maestro_data_t);
124   //  const char *hosts[MAXHOSTS] = { "61", "62", "63", "69", "70", "77", "81", "83", "85", "87", "88", "95", "98", "107", "109", "111", "112", "121", "124", "125", "131", "145", "150", "156", "157", "162", "165", "168", "169", "170", "175", "177", "178" };
125   const char *hosts[MAXHOSTS] = { "A", "B", "C", "D" };
126
127   double bw[MAXHOSTS][MAXHOSTS];
128   double bw_sat[MAXHOSTS][MAXHOSTS];
129
130   int a,b,c,d,begin;
131
132   if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) { 
133     fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
134     return 1;
135   }
136
137   if (grasbw_register_messages()) {
138     gras_sock_close(g->sock);
139     return 1;
140   }
141
142   begin=time(NULL);
143   beginSim=gras_time();
144   for (a=0; a<MAXHOSTS; a++) {
145     for (b=0; b<MAXHOSTS; b++) {
146       if (a==b) continue;
147       fprintf(stderr,"BW XP(%s %s)=",hosts[a],hosts[b]); 
148       if ((errcode=grasbw_request(hosts[a],4000,hosts[b],4000,bufSize,expSize,msgSize,
149                                   &dummy,&(bw[a][b])))) {
150         fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
151         return 1;
152       }
153       fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
154     }
155   }
156   fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
157           time(NULL)-begin,gras_time()-beginSim);
158       
159   for (a=0; a<MAXHOSTS; a++) {
160     for (b=0; b<MAXHOSTS; b++) {
161       if (a==b) continue;
162         
163       if ((errcode=grasbw_saturate_start(hosts[a],4000,hosts[b],4000,satSize,360000000))) {
164         fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
165                 gras_error_name(errcode));
166         return -1;
167       }
168       gras_sleep(1,0);
169
170       begin=time(NULL);
171       beginSim=gras_time();
172       for (c=0 ;c<MAXHOSTS; c++) {
173         if (a==c) continue;
174         if (b==c) continue;
175
176         for (d=0 ;d<MAXHOSTS; d++) {
177           if (a==d) continue;
178           if (b==d) continue;
179           if (c==d) continue;
180           
181           if ((errcode=grasbw_request(hosts[c],4000,hosts[d],4000,bufSize,expSize,msgSize,
182                                       &dummy,&(bw_sat[c][d])))) {
183             fprintf(stderr,"MAESTRO: Error %s encountered in test\n",gras_error_name(errcode));
184             return 1;
185           }
186           fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
187                   gras_time(),
188                   hosts[c],hosts[d],hosts[a],hosts[b],
189                   bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
190
191                   (bw_sat[c][d]/bw[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE !!!":
192                   ((bw[c][d]/bw_sat[c][d] < 0.7) ? " THERE IS SOME INTERFERENCE (and Im a cretin) !!!":
193                    ""));
194         }
195       }
196
197       if ((errcode=grasbw_saturate_stop(hosts[a],4000,hosts[b],4000))) {
198         fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
199                 gras_error_name(errcode));
200         return -1;
201       }
202       fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
203               time(NULL)-begin, gras_time()-beginSim);
204     }
205   }
206
207   gras_sleep(5,0);
208   exit(0);
209 #if 0
210   return 0;
211   /* start saturation */
212   fprintf(stderr,"MAESTRO: Start saturation with size %d\n",msgSize);
213   if ((errcode=grasbw_saturate_start(argv[5],atoi(argv[6]),argv[7],atoi(argv[8]),msgSize*10,60))) {
214     fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
215             gras_error_name(errcode));
216     return 1;
217   }
218   fprintf(stderr,"MAESTRO: Saturation started\n");
219   gras_sleep(5,0);
220
221   /* test with saturation */
222   if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
223                               bufSize,expSize,msgSize,&sec,&bw))) {
224     fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
225     return 1;
226   }
227    
228   fprintf(stderr,"MAESTRO: Experience3 (%d ko in msgs of %d ko with saturation) took %f sec, achieving %f Mb/s\n",
229           expSize/1024,msgSize/1024,
230           sec,bw);
231
232   /* stop saturation */
233   if ((errcode=grasbw_saturate_stop(argv[5],atoi(argv[6]),argv[7],atoi(argv[8])))) {
234     fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
235             gras_error_name(errcode));
236     return 1;
237   }
238
239   /* test without saturation */
240   if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
241                               bufSize,expSize,msgSize,&sec,&bw))) {
242     fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",gras_error_name(errcode));
243     return 1;
244   }
245    
246   fprintf(stderr,"MAESTRO: Experience4 (%d ko in msgs of %d ko, without saturation) took %f sec, achieving %f Mb/s\n",
247           expSize/1024,msgSize/1024,
248           sec,bw);
249
250   gras_sleep(5,0);
251 #endif
252   return gras_sock_close(g->sock);
253 }