Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
port the SG part to the new stuff intended to work on AIX
[simgrid.git] / examples / bandwidth / bandwidth.c
1 /* $Id$ */
2
3 /* bandwidth - bandwidth test demo of GRAS features                         */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <signal.h>
14
15 #include <gras.h>
16
17 /* **********************************************************************
18  * Sensor code
19  * **********************************************************************/
20
21 /* Global private data */
22 typedef struct {
23   gras_sock_t *sock;
24 } sensor_data_t;
25
26 /* Function prototypes */
27 int sensor (int argc,char *argv[]);
28
29 int sensor (int argc,char *argv[]) {
30   gras_error_t errcode;
31   sensor_data_t *g=gras_userdata_new(sensor_data_t);  
32
33   if ((errcode=gras_sock_server_open(4000,4000,&(g->sock)))) { 
34     fprintf(stderr,"Sensor: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
35     return 1;
36   }
37
38   if (grasbw_register_messages()) {
39     gras_sock_close(g->sock);
40     return 1;
41   }
42
43   while (1) {
44     if ((errcode=gras_msg_handle(60.0)) && errcode != timeout_error) {
45       fprintf(stderr,"Sensor: Error '%s' while handling message\n",gras_error_name(errcode));
46       gras_sock_close(g->sock);
47       return errcode;
48     }
49     if (errcode==no_error)
50        break;
51   }
52
53   gras_sleep(5,0);
54   return gras_sock_close(g->sock);
55 }
56
57 /* **********************************************************************
58  * Maestro code
59  * **********************************************************************/
60
61 /* Global private data */
62 typedef struct {
63   gras_sock_t *sock;
64 } maestro_data_t;
65
66 /* Function prototypes */
67 int maestro (int argc,char *argv[]);
68
69 int maestro(int argc,char *argv[]) {
70   gras_error_t errcode;
71   maestro_data_t *g=gras_userdata_new(maestro_data_t);
72   double sec, bw;
73   int bufSize=32 * 1024;
74   int expSize=64 * 1024;
75   int msgSize=64 * 1024;
76
77   if ((errcode=gras_sock_server_open(4000,5000,&(g->sock)))) { 
78     fprintf(stderr,"Maestro: Error %s encountered while opening the server socket\n",gras_error_name(errcode));
79     return 1;
80   }
81
82   if (grasbw_register_messages()) {
83     gras_sock_close(g->sock);
84     return 1;
85   }
86
87   if (argc != 5) {
88      fprintf(stderr,"Usage: maestro host port host port\n");
89      return 1;
90   }
91      
92   if ((errcode=grasbw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
93                               bufSize,expSize,msgSize,&sec,&bw))) {
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: Experience (%d ko in msgs of %d ko) took %f sec, achieving %f Mb/s\n",
99           expSize/1024,msgSize/1024,
100           sec,bw);
101
102   gras_sleep(5,0);
103   return gras_sock_close(g->sock);
104 }