Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix a compilation warning introduced by r9557
[simgrid.git] / examples / msg / token_ring / ring_call.c
1 /* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "msg/msg.h"
10 #include "surf/surf_private.h"
11
12 extern routing_global_t global_routing;
13 int totalHosts= 0;
14 const m_host_t *hosts;
15
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
18
19 XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
20                              "Messages specific for this msg example");
21
22 int master(int argc, char *argv[])
23 {
24         m_task_t task_s = NULL;
25         m_task_t task_r = NULL;
26         unsigned int task_comp_size = 50000000;
27         unsigned int task_comm_size = 1000000;
28         char mailbox[80];
29         char buffer[20];
30         int num = atoi(argv[1]);
31
32     sprintf(mailbox, "host%d", num+1);
33     if(num == totalHosts-1)
34         sprintf(mailbox, "host%d", 0);
35     sprintf(buffer, "Token");
36
37     task_s = MSG_task_create(buffer,
38                                                         task_comp_size,
39                                                         task_comm_size,
40                                                         NULL);
41     MSG_task_send(task_s,mailbox);
42
43     //MSG_comm_wait(comm, -1);
44     INFO1("Send Data to \"%s\"", mailbox);
45
46         sprintf(mailbox, "host%d", num);
47         MSG_task_receive(&(task_r), mailbox);
48         //res = MSG_comm_wait(res_irecv, -1);
49         INFO1("Received \"%s\"", MSG_task_get_name(task_r));
50         //MSG_comm_destroy(res_irecv);
51         return 0;
52 }
53
54 int slave(int argc, char *argv[])
55 {
56         m_task_t task_s = NULL;
57         m_task_t task_r = NULL;
58         unsigned int task_comp_size = 50000000;
59         unsigned int task_comm_size = 1000000;
60         char mailbox[80];
61         char buffer[20];
62         int num = atoi(argv[1]);
63
64         sprintf(mailbox, "host%d", num);
65         MSG_task_receive(&(task_r), mailbox);
66         //res = MSG_comm_wait(res_irecv, -1);
67         INFO1("Received \"%s\"", MSG_task_get_name(task_r));
68         //MSG_comm_destroy(res_irecv);
69         //Receive something now need to tell it!
70
71         sprintf(mailbox, "host%d", num+1);
72         if(num == totalHosts-1)
73                 sprintf(mailbox, "host%d", 0);
74         sprintf(buffer, "Token");
75         task_s = MSG_task_create(buffer,
76                                                         task_comp_size,
77                                                         task_comm_size,
78                                                         NULL);
79         MSG_task_send(task_s, mailbox);
80         //MSG_comm_wait(comm, -1);
81         INFO1("Send Data to \"%s\"", mailbox);
82
83         return 0;
84 }
85
86 static int surf_parse_bypass_application(void)
87 {
88         int i;
89         static int AX_ptr;
90         static int surfxml_bufferstack_size = 2048;
91         static int surfxml_buffer_stack_stack_ptr = 0;
92         static int surfxml_buffer_stack_stack[1024];
93         /* allocating memory to the buffer, I think 2MB should be enough */
94         surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
95
96         totalHosts = MSG_get_host_number();
97         hosts = MSG_get_host_table();
98
99         /* <platform> */
100         SURFXML_BUFFER_SET(platform_version, "3");
101
102         SURFXML_START_TAG(platform);
103
104         DEBUG1("process : %s en master",MSG_host_get_name(hosts[0]));
105         /*   <process host="host A" function="master"> */
106         SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0]));
107         SURFXML_BUFFER_SET(process_function, "master");
108         SURFXML_BUFFER_SET(process_start_time, "-1.0");
109         SURFXML_BUFFER_SET(process_kill_time, "-1.0");
110         SURFXML_START_TAG(process);
111
112         /*      <argument value="0"/> */
113         SURFXML_BUFFER_SET(argument_value, "0");
114         SURFXML_START_TAG(argument);
115         SURFXML_END_TAG(argument);
116         SURFXML_END_TAG(process);
117
118         for(i=1;i<totalHosts;i++)
119         {
120         DEBUG1("process : %s en slave",MSG_host_get_name(hosts[i]));
121         /*   <process host="host A" function="slave"> */
122         SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) );
123         SURFXML_BUFFER_SET(process_function, "slave");
124         SURFXML_BUFFER_SET(process_start_time, "-1.0");
125         SURFXML_BUFFER_SET(process_kill_time, "-1.0");
126         SURFXML_START_TAG(process);
127
128         /*      <argument value="num"/> */
129         SURFXML_BUFFER_SET(argument_value, bprintf("%d",i));
130         SURFXML_START_TAG(argument);
131         SURFXML_END_TAG(argument);
132         SURFXML_END_TAG(process);
133         }
134         /* </platform> */
135         SURFXML_END_TAG(platform);
136
137         free(surfxml_bufferstack);
138         return 0;
139 }
140
141 typedef enum {
142   PORT_22 = 20,
143   MAX_CHANNEL
144 } channel_t;
145
146 int main(int argc, char **argv)
147 {
148         int res;
149   MSG_global_init(&argc, argv);
150   MSG_set_channel_number(MAX_CHANNEL);
151   MSG_create_environment(argv[1]);
152
153   MSG_function_register("master", master);
154   MSG_function_register("slave", slave);
155   surf_parse = surf_parse_bypass_application;
156   MSG_launch_application(NULL);
157
158   res = MSG_main();
159
160   INFO1("Simulation time %g", MSG_get_clock());
161
162   MSG_clean();
163
164   if (res == MSG_OK)
165     return 0;
166   else
167     return 1;
168
169 }