Logo AND Algorithmique Numérique Distribuée

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