Logo AND Algorithmique Numérique Distribuée

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