Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix tesh file. Surprisingly, according to git, it was already wrong when first commit...
[simgrid.git] / examples / msg / gtnets / gtnets_kayo.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "msg/msg.h"
4 #include "xbt/log.h"
5 #include "xbt/asserts.h"
6
7 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
8                              "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 1500
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 const char *slavenames[NTASKS];
26 const char *masternames[NTASKS];
27 int gl_task_array_id = 0;
28
29 #define FINALIZE ((void*)221297)        /* a magic number to tell people to stop working */
30
31 /** master */
32 int master(int argc, char *argv[])
33 {
34   char *slavename = NULL;
35   double task_comm_size = 0;
36   m_task_t todo;
37   m_host_t slave;
38   char id_alias[10];
39   //unique id to control statistics
40   int id = -1;
41
42   if (argc != 4) {
43     INFO1("Strange number of arguments expected 3 got %d", argc - 1);
44   }
45
46   /* data size */
47   xbt_assert1(sscanf(argv[1], "%lg", &task_comm_size),
48               "Invalid argument %s\n", argv[1]);
49
50   /* slave name */
51   slavename = argv[2];
52   id = atoi(argv[3]);
53   sprintf(id_alias, "%d", id);
54   slavenames[id] = slavename;
55
56   masternames[id] = MSG_host_get_name(MSG_host_self());
57
58   {                             /*  Task creation.  */
59     char sprintf_buffer[64] = "Task_0";
60     todo = MSG_task_create(sprintf_buffer, 0, task_comm_size, NULL);
61     //keep track of running tasks
62     gl_task_array[id] = todo;
63     gl_data_size[id] = task_comm_size;
64   }
65
66   {                             /* Process organisation */
67     slave = MSG_get_host_by_name(slavename);
68   }
69
70   /* time measurement */
71   start_time = MSG_get_clock();
72   MSG_task_send(todo, id_alias);
73   end_time = MSG_get_clock();
74
75   INFO5
76     ("===> Estimated Bw of FLOW[%d] : %f ;  message from %s to %s  with remaining : %f",
77      id + 1, task_comm_size / (end_time - start_time), masternames[id],
78      slavenames[id], 0.0);
79
80
81   return 0;
82 }                               /* end_of_master */
83
84 /** Receiver function  */
85 int slave(int argc, char *argv[])
86 {
87
88   m_task_t task = NULL;
89   int a;
90   int id = 0;
91   char id_alias[10];
92
93   if (argc != 2) {
94     INFO1("Strange number of arguments expected 1 got %d", argc - 1);
95   }
96   id = atoi(argv[1]);
97   sprintf(id_alias, "%d", id);
98
99   a = MSG_task_receive(&(task), id_alias);
100   return 0;
101 }                               /* end_of_slave */
102
103 /** Test function */
104 MSG_error_t test_all(const char *platform_file, const char *application_file)
105 {
106   MSG_error_t res = MSG_OK;
107   MSG_set_channel_number(MAX_CHANNEL);
108   MSG_create_environment(platform_file);
109   MSG_function_register("master", master);
110   MSG_function_register("slave", slave);
111   MSG_launch_application(application_file);
112   res = MSG_main();
113   return res;
114 }                               /* end_of_test_all */
115
116 /** Main function */
117 int main(int argc, char *argv[])
118 {
119   MSG_error_t res = MSG_OK;
120   bool_printed = 0;
121
122   MSG_global_init(&argc, argv);
123   if (argc < 3) {
124     printf("Usage: %s platform_file deployment_file\n", argv[0]);
125     exit(1);
126   }
127   res = test_all(argv[1], argv[2]);
128
129   MSG_clean();
130
131   if (res == MSG_OK)
132     return 0;
133   else
134     return 1;
135 }                               /* end_of_main */