Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
misleading typo in test description
[simgrid.git] / examples / msg / gtnets / gtnets.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "msg/msg.h"
4 /* Create a log channel to have nice outputs. */
5 #include "xbt/log.h"
6 #include "xbt/asserts.h"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
9
10 int master(int argc, char *argv[]);
11 int slave(int argc, char *argv[]);
12 MSG_error_t test_all(const char *platform_file, const char *application_file);
13
14 typedef enum {
15   PORT_22 = 0,
16   MAX_CHANNEL
17 } channel_t;
18
19 //keep a pointer to all surf running tasks.
20 #define NTASKS 2
21 int bool_printed=0;
22 double start_time, end_time, elapsed_time;
23 double   gl_data_size[NTASKS];
24 m_task_t gl_task_array[NTASKS];
25 int gl_task_array_id=0;
26
27 /** master */
28 int master(int argc, char *argv[])
29 {
30   char *slavename = NULL;
31   double task_comm_size = 0;
32   m_task_t todo;
33   m_host_t slave;
34   //unique id to control statistics
35   int id=gl_task_array_id++;
36
37   /* data size */
38   xbt_assert1(sscanf(argv[1],"%lg", &task_comm_size),
39               "Invalid argument %s\n", argv[1]);
40
41   /* slave name */
42   slavename = argv[2];
43   
44   { /*  Task creation.  */
45     char sprintf_buffer[64] = "Task_0";
46     todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
47     //keep track of running tasks
48     gl_task_array[id] = todo;
49     gl_data_size[id]=task_comm_size;
50   }
51
52   { /* Process organisation */
53     slave = MSG_get_host_by_name(slavename);
54   }
55
56   /* time measurement */
57   double start_time = MSG_get_clock();
58   MSG_task_put(todo, slave, PORT_22);
59   double end_time = MSG_get_clock();
60   INFO3("Send completed (to %s). Transfer time: %f\t Agregate bandwidth: %f",
61         slave->name, (end_time - start_time), task_comm_size/(end_time-start_time));
62   INFO2("Completed peer: %s time: %f", slave->name, (end_time-start_time));
63
64   return 0;
65 } /* end_of_master */
66
67 /** Receiver function  */
68 int slave(int argc, char *argv[])
69 {
70   m_task_t task = NULL;
71   int a;
72   int id=0;
73   double remaining=0;
74
75   a = MSG_task_get(&(task), PORT_22);
76   if (a != MSG_OK) {
77     INFO0("Hey?! What's up?");
78     xbt_assert0(0,"Unexpected behavior.");
79   }
80
81   elapsed_time = MSG_get_clock() - start_time;
82
83   if(!bool_printed){
84     bool_printed=1;
85     for(id=0; id<NTASKS; id++){
86       if(gl_task_array[id] == NULL){
87         INFO0("===> Task already done, skipping print statistics");
88       }else if(gl_task_array[id] == task){
89         INFO1("===> Bandwidth of first finishing (this) flow : %f.", gl_data_size[id]/elapsed_time);
90       }else{
91         remaining = MSG_task_get_remaining_communication(gl_task_array[id]);
92         INFO1("===> Bandwidth of last finishing  flow        : %f.", (gl_data_size[id]-remaining)/elapsed_time);
93       }
94     }
95   }
96
97   MSG_task_destroy(task);
98
99   return 0;
100 } /* end_of_slave */
101
102 /** Test function */
103 MSG_error_t test_all(const char *platform_file,
104                      const char *application_file)
105 {
106   MSG_error_t res = MSG_OK;
107
108 /*   MSG_config("workstation_model", "GTNETS"); */
109   /* MSG_config("workstation_model","KCCFLN05"); */
110   {                             /*  Simulation setting */
111     MSG_set_channel_number(MAX_CHANNEL);
112     MSG_paje_output("msg_test.trace");
113     MSG_create_environment(platform_file);
114   }
115   {                   /*   Application deployment */
116     MSG_function_register("master", master);
117     MSG_function_register("slave", slave);
118     MSG_launch_application(application_file);
119   }
120   res = MSG_main();
121   return res;
122 } /* end_of_test_all */
123
124
125 /** Main function */
126 int main(int argc, char *argv[])
127 {
128   MSG_error_t res = MSG_OK;
129
130   MSG_global_init(&argc,argv);
131   if (argc < 3) {
132      printf ("Usage: %s platform_file deployment_file\n",argv[0]);
133      exit(1);
134   }
135   res = test_all(argv[1],argv[2]);
136
137   MSG_clean();
138
139   if(res==MSG_OK) return 0; 
140   else return 1;
141 } /* end_of_main */
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156