Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unnecessary output that makes these tests fail every time SMPI changes.
[simgrid.git] / examples / amok / alnem / alnem.c
1 /* ALNeM itself                                                             */
2
3 /* Copyright (c) 2005, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <signal.h>
13 #include <time.h>
14
15 #include <gras.h>
16
17 #include <tbx_graph.h> /* alvin's graph toolbox (+ reconstruction algorithm) */
18
19 /* **********************************************************************
20  * Sensor code
21  * **********************************************************************/
22
23 /* Global private data */
24 typedef struct {
25   gras_sock_t *sock;
26 } sensor_data_t;
27
28 /* Function prototypes */
29 int sensor (int argc,char *argv[]);
30
31 int sensor (int argc,char *argv[]) {
32   xbt_error_t errcode;
33   sensor_data_t *g=gras_userdata_new(sensor_data_t);  
34
35   if ((errcode=gras_sock_server_open(4000,4000,&(g->sock)))) { 
36     fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
37     return 1;
38   }
39
40   if (grasbw_register_messages()) {
41     gras_sock_close(g->sock);
42     return 1;
43   }
44
45   while (1) {
46     if ((errcode=gras_msg_handle(3600.0)) && errcode != timeout_error) {
47       fprintf(stderr,"Sensor: Error '%s' while handling message\n",
48               xbt_error_name(errcode));
49     }
50   }
51
52   gras_sleep(5,0);
53   return gras_sock_close(g->sock);
54 }
55
56 /* **********************************************************************
57  * Maestro code
58  * **********************************************************************/
59
60 /* Global private data */
61 typedef struct {
62   gras_sock_t *sock;
63 } maestro_data_t;
64
65 /* Function prototypes */
66 int maestro (int argc,char *argv[]);
67
68 #define MAXHOSTS 100
69
70 #define INTERF(graph,table,a,u,b,v) INTERFERENCE(table,\
71                                                 TBX_Graph_nodeSearch(graph,a),\
72                                                 TBX_Graph_nodeSearch(graph,u),\
73                                                 TBX_Graph_nodeSearch(graph,b),\
74                                                 TBX_Graph_nodeSearch(graph,v))
75
76 int maestro(int argc,char *argv[]) {
77   int bufSize=32 * 1024;
78   int expSize= 1024 * 1024;
79   int msgSize=expSize;
80   int satSize=msgSize * 100;
81   double dummy,beginSim;
82   xbt_error_t errcode;
83   maestro_data_t *g=gras_userdata_new(maestro_data_t);
84
85   double bw[MAXHOSTS][MAXHOSTS];
86   double bw_sat[MAXHOSTS][MAXHOSTS];
87
88   int a,b,c,d,begin;
89
90   TBX_Graph_t graph = TBX_Graph_newGraph("Essai",0,NULL); /* a dummy graph containing all hosts */
91   TBX_FIFO_t host_fifo = TBX_FIFO_newFIFO();
92   TBX_InterfTable_t interf = NULL; /* the measured interferences */
93   TBX_Graph_t builded_graph = NULL; /* the graph builded from the interferences */
94
95   /* basics setups */
96   if (argc>MAXHOSTS) {
97     fprintf(stderr,"You gave more than %d sensors for this experiment. Increase the MAX HOSTS constant in alnem code to be bigger than this number.\n",argc);
98     return 1;
99   }
100
101   if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) { 
102     fprintf(stderr,"MAESTRO: Error %s encountered while opening the server socket\n",xbt_error_name(errcode));
103     return 1;
104   }
105
106   if (grasbw_register_messages()) {
107     gras_sock_close(g->sock);
108     return 1;
109   }
110
111   for (a=1; a<argc; a++) {
112     TBX_FIFO_insert(host_fifo,TBX_Graph_newNode(graph,argv[a], NULL));
113   }
114   TBX_Graph_fixNodeNumbering(graph);
115   interf=TBX_Graph_newInterfTable(host_fifo);
116   TBX_Graph_graphInterfTableInit(graph,interf);
117
118   /* measure the bandwidths */
119   begin=time(NULL);
120   beginSim=gras_time();
121   for (a=1; a<argc; a++) {
122     for (b=1; b<argc; b++) {
123       int test=0;
124        
125       if (a==b) continue;
126       fprintf(stderr,"BW XP(%s %s)=",argv[a],argv[b]); 
127       while ((errcode=grasbw_request(argv[a],4000,argv[b],4000,bufSize,expSize,msgSize,
128                                   &dummy,&(bw[a][b]))) && (errcode == timeout_error)) {
129          test++;
130          if (test==10) {
131             fprintf(stderr,"MAESTRO: 10 Timeouts; giving up\n");
132             return 1;
133          }
134       }
135       if (errcode) {
136         fprintf(stderr,"MAESTRO: Error %s encountered while doing the test\n",xbt_error_name(errcode));
137         return 1;
138       }
139       fprintf(stderr,"%f Mb/s in %f sec\n",bw[a][b],dummy);
140     }
141   }
142   fprintf(stderr,"Did all BW tests in %ld sec (%.2f simulated sec)\n",
143           time(NULL)-begin,gras_time()-beginSim);
144       
145   /* saturation tests */
146   for (a=1; a<argc; a++) {
147     for (b=1; b<argc; b++) {
148       for (c=1 ;c<argc; c++) {
149         INTERF(graph,interf,argv[a],argv[c],argv[b],argv[c])= 1;
150       }
151     }
152   }
153           
154   for (a=1; a<argc; a++) {
155     for (b=1; b<argc; b++) {
156       if (a==b) continue;
157         
158       if ((errcode=grasbw_saturate_start(argv[a],4000,argv[b],4000,satSize,360000000))) {
159         fprintf(stderr,"MAESTRO: Error %s encountered while starting saturation\n",
160                 xbt_error_name(errcode));
161         return -1;
162       }
163       gras_sleep(1,0);
164
165       begin=time(NULL);
166       beginSim=gras_time();
167       for (c=1 ;c<argc; c++) {
168         if (a==c || b==c) continue;
169
170         for (d=1 ;d<argc; d++) {
171           if (a==d || b==d || c==d) continue;
172           
173           if ((errcode=grasbw_request(argv[c],4000,argv[d],4000,bufSize,expSize,msgSize,
174                                       &dummy,&(bw_sat[c][d])))) {
175             fprintf(stderr,"MAESTRO: Error %s encountered in test\n",xbt_error_name(errcode));
176             return 1;
177           }
178           fprintf(stderr, "MAESTRO[%.2f sec]: SATURATED BW XP(%s %s // %s %s) => %f (%f vs %f)%s\n",
179                   gras_time(),
180                   argv[c],argv[d],argv[a],argv[b],
181                   bw_sat[c][d]/bw[c][d],bw[c][d],bw_sat[c][d],
182
183                   (bw_sat[c][d]/bw[c][d] < 0.75) ? " THERE IS SOME INTERFERENCE !!!":"");
184           INTERF(graph,interf,argv[c],argv[d],argv[a],argv[b])= 
185             (bw_sat[c][d]/bw[c][d] < 0.75) ? 1 : 0;
186         }
187       }
188
189       if ((errcode=grasbw_saturate_stop(argv[a],4000,argv[b],4000))) {
190         fprintf(stderr,"MAESTRO: Error %s encountered while stopping saturation\n",
191                 xbt_error_name(errcode));
192         return -1;
193       }
194       fprintf(stderr,"Did an iteration on saturation pair in %ld sec (%.2f simulated sec)\n",
195               time(NULL)-begin, gras_time()-beginSim);
196     }
197   }
198
199   /* reconstruct the graph */
200   TBX_Graph_interferenceTableDump(interf);
201   TBX_Graph_interferenceTableSave(interf,"interference.dat");
202   begin=time(NULL);
203   fprintf(stderr, "MAESTRO: Reconstruct the graph... ");
204   builded_graph = TBX_Graph_exploreInterference(interf);
205   TBX_Graph_exportToGraphViz(builded_graph, "toto.dot");
206   fprintf(stderr, "done (took %d sec)",(int)time(NULL));
207
208   /* end */
209   TBX_Graph_freeGraph(graph,NULL,NULL,NULL);
210   TBX_Graph_freeGraph(builded_graph,NULL,NULL,NULL);
211   TBX_Graph_freeInterfTable(interf);
212
213   gras_sleep(5,0);
214   exit(0); /* FIXME: There is a bug in MSG preventing me from terminating this server properly */
215   return gras_sock_close(g->sock);
216 }