1 /* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
10 #include "surf/surf_private.h"
12 extern routing_global_t global_routing;
14 const m_host_t *hosts;
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
19 XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
20 "Messages specific for this msg example");
22 int master(int argc, char *argv[])
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;
30 int num = atoi(argv[1]);
32 sprintf(mailbox, "host%d", num+1);
33 if(num == totalHosts-1)
34 sprintf(mailbox, "host%d", 0);
35 sprintf(buffer, "Token");
37 task_s = MSG_task_create(buffer,
41 MSG_task_send(task_s,mailbox);
42 XBT_INFO("Send Data to \"%s\"", mailbox);
44 sprintf(mailbox, "host%d", num);
45 MSG_task_receive(&(task_r), mailbox);
46 XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r));
50 int slave(int argc, char *argv[])
52 m_task_t task_s = NULL;
53 m_task_t task_r = NULL;
54 unsigned int task_comp_size = 50000000;
55 unsigned int task_comm_size = 1000000;
58 int num = atoi(argv[1]);
60 sprintf(mailbox, "host%d", num);
61 MSG_task_receive(&(task_r), mailbox);
62 XBT_INFO("Received \"%s\"", MSG_task_get_name(task_r));
63 sprintf(mailbox, "host%d", num+1);
64 if(num == totalHosts-1)
65 sprintf(mailbox, "host%d", 0);
66 sprintf(buffer, "Token");
67 task_s = MSG_task_create(buffer,
71 MSG_task_send(task_s, mailbox);
72 XBT_INFO("Send Data to \"%s\"", mailbox);
77 static int surf_parse_bypass_application(void)
81 static int surfxml_bufferstack_size = 2048;
82 static int surfxml_buffer_stack_stack_ptr = 0;
83 static int surfxml_buffer_stack_stack[1024];
84 /* allocating memory to the buffer, I think 2MB should be enough */
85 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
87 totalHosts = MSG_get_host_number();
88 hosts = MSG_get_host_table();
91 SURFXML_BUFFER_SET(platform_version, "3");
93 SURFXML_START_TAG(platform);
95 XBT_DEBUG("process : %s en master",MSG_host_get_name(hosts[0]));
96 /* <process host="host A" function="master"> */
97 SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0]));
98 SURFXML_BUFFER_SET(process_function, "master");
99 SURFXML_BUFFER_SET(process_start_time, "-1.0");
100 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
101 SURFXML_START_TAG(process);
103 /* <argument value="0"/> */
104 SURFXML_BUFFER_SET(argument_value, "0");
105 SURFXML_START_TAG(argument);
106 SURFXML_END_TAG(argument);
107 SURFXML_END_TAG(process);
109 for(i=1;i<totalHosts;i++)
111 XBT_DEBUG("process : %s en slave",MSG_host_get_name(hosts[i]));
112 /* <process host="host A" function="slave"> */
113 SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) );
114 SURFXML_BUFFER_SET(process_function, "slave");
115 SURFXML_BUFFER_SET(process_start_time, "-1.0");
116 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
117 SURFXML_START_TAG(process);
119 /* <argument value="num"/> */
120 SURFXML_BUFFER_SET(argument_value, bprintf("%d",i));
121 SURFXML_START_TAG(argument);
122 SURFXML_END_TAG(argument);
123 SURFXML_END_TAG(process);
126 SURFXML_END_TAG(platform);
128 free(surfxml_bufferstack);
137 int main(int argc, char **argv)
140 MSG_global_init(&argc, argv);
141 MSG_set_channel_number(MAX_CHANNEL);
142 MSG_create_environment(argv[1]);
144 MSG_function_register("master", master);
145 MSG_function_register("slave", slave);
146 surf_parse = surf_parse_bypass_application;
147 MSG_launch_application(NULL);
151 XBT_INFO("Simulation time %g", MSG_get_clock());