Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Plug a bunch of memleaks, and play with the new min_duration argument
[simgrid.git] / examples / amok / bandwidth / bandwidth.c
1 /* $Id$ */
2
3 /* bandwidth - bandwidth test demo of GRAS features                         */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
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 "gras.h"
12 #include "amok/bandwidth.h"
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(Bandwidth,"Messages specific to this example");
15
16 /* **********************************************************************
17  * Sensor code
18  * **********************************************************************/
19
20 /* Global private data */
21 typedef struct {
22   gras_socket_t sock;
23   int done;
24 } s_sensor_data_t,*sensor_data_t;
25
26 static int sensor_cb_quit(gras_msg_cb_ctx_t ctx, void *payload) {
27   sensor_data_t globals=(sensor_data_t)gras_userdata_get();
28                           
29   globals->done = 1;                  
30   return 1;         
31 }
32
33 /* Function prototypes */
34 int sensor (int argc,char *argv[]);
35
36 int sensor (int argc,char *argv[]) {
37   sensor_data_t g;
38
39   gras_init(&argc, argv);
40   g=gras_userdata_new(s_sensor_data_t);  
41   amok_bw_init();
42    
43   g->sock=gras_socket_server(atoi(argv[1]));
44   g->done = 0;
45   
46   gras_msgtype_declare("quit",NULL);
47   gras_cb_register(gras_msgtype_by_name("quit"),&sensor_cb_quit);
48   
49   while (! g->done )
50     gras_msg_handle(60.0);
51
52   gras_socket_close(g->sock);
53   gras_exit();
54   return 0;
55 }
56
57 /* **********************************************************************
58  * Maestro code
59  * **********************************************************************/
60
61 /* Global private data */
62 typedef struct {
63   gras_socket_t sock;
64 } s_maestro_data_t,*maestro_data_t;
65
66 /* Function prototypes */
67 int maestro (int argc,char *argv[]);
68
69 int maestro(int argc,char *argv[]) {
70   maestro_data_t g;
71   double sec, bw;
72   int buf_size=32      *1024;
73   int exp_size=1024*50 *1024;
74   int msg_size=512     *1024;
75   double min_duration = 1;
76   gras_socket_t peer;
77
78   gras_init(&argc, argv);
79   g=gras_userdata_new(s_maestro_data_t);
80   amok_bw_init();
81
82   if (argc != 5) {
83      ERROR0("Usage: maestro host port host port\n");
84      return 1;
85   }
86
87   /* wait to ensure that all server sockets are there before starting the experiment */ 
88   gras_os_sleep(0.5);
89   
90   peer = gras_socket_client(argv[1],atoi(argv[2]));
91
92   INFO0("Test the BW between me and one of the sensors");  
93   amok_bw_test(peer,buf_size,exp_size,msg_size,min_duration,&sec,&bw);
94   INFO6("Experience between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %f kb/s",
95         argv[1],atoi(argv[2]),
96         exp_size,msg_size,
97         sec,((double)bw)/1024.0);
98
99   INFO4("Test the BW between %s:%s and %s:%s",argv[1],argv[2],argv[3],argv[4]);
100   amok_bw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
101                   buf_size,exp_size,msg_size,&sec,&bw); 
102   INFO6("Experience between %s:%s and %s:%s took took %f sec, achieving %f kb/s",
103         argv[1],argv[2],argv[3],argv[4],
104         sec,((double)bw)/1024.0);
105
106   /* ask sensors to quit */                    
107   gras_msgtype_declare("quit",NULL);
108   gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL);
109   gras_socket_close(peer);
110
111   peer = gras_socket_client(argv[3],atoi(argv[4]));
112   gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL);
113   gras_socket_close(peer);
114
115   gras_socket_close(g->sock);
116   gras_exit();
117   return 0;
118 }