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. */
9 #include "surf/surf_private.h"
11 extern routing_global_t global_routing;
13 const m_host_t *hosts;
15 int master(int argc, char *argv[]);
16 int slave(int argc, char *argv[]);
18 XBT_LOG_NEW_DEFAULT_CATEGORY(ring,
19 "Messages specific for this msg example");
21 int master(int argc, char *argv[])
23 m_task_t task_s = NULL;
24 m_task_t task_r = NULL;
25 unsigned int task_comp_size = 50000000;
26 unsigned int task_comm_size = 1000000;
29 int num = atoi(argv[1]);
31 sprintf(mailbox, "host%d", num+1);
32 if(num == totalHosts-1)
33 sprintf(mailbox, "host%d", 0);
34 sprintf(buffer, "Token");
36 task_s = MSG_task_create(buffer,
40 MSG_task_send(task_s,mailbox);
42 //MSG_comm_wait(comm, -1);
43 INFO1("Send Data to \"%s\"", mailbox);
45 sprintf(mailbox, "host%d", num);
46 MSG_task_receive(&(task_r), mailbox);
47 //res = MSG_comm_wait(res_irecv, -1);
48 INFO1("Received \"%s\"", MSG_task_get_name(task_r));
49 //MSG_comm_destroy(res_irecv);
53 int slave(int argc, char *argv[])
55 m_task_t task_s = NULL;
56 m_task_t task_r = NULL;
57 unsigned int task_comp_size = 50000000;
58 unsigned int task_comm_size = 1000000;
61 int num = atoi(argv[1]);
63 sprintf(mailbox, "host%d", num);
64 MSG_task_receive(&(task_r), mailbox);
65 //res = MSG_comm_wait(res_irecv, -1);
66 INFO1("Received \"%s\"", MSG_task_get_name(task_r));
67 //MSG_comm_destroy(res_irecv);
68 //Receive something now need to tell it!
70 sprintf(mailbox, "host%d", num+1);
71 if(num == totalHosts-1)
72 sprintf(mailbox, "host%d", 0);
73 sprintf(buffer, "Token");
74 task_s = MSG_task_create(buffer,
78 MSG_task_send(task_s, mailbox);
79 //MSG_comm_wait(comm, -1);
80 INFO1("Send Data to \"%s\"", mailbox);
85 static int surf_parse_bypass_application(void)
89 static int surfxml_bufferstack_size = 2048;
90 static int surfxml_buffer_stack_stack_ptr = 0;
91 static int surfxml_buffer_stack_stack[1024];
92 /* allocating memory to the buffer, I think 2MB should be enough */
93 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
95 totalHosts = MSG_get_host_number();
96 hosts = MSG_get_host_table();
99 SURFXML_BUFFER_SET(platform_version, "3");
101 SURFXML_START_TAG(platform);
103 DEBUG1("process : %s en master",MSG_host_get_name(hosts[0]));
104 /* <process host="host A" function="master"> */
105 SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0]));
106 SURFXML_BUFFER_SET(process_function, "master");
107 SURFXML_BUFFER_SET(process_start_time, "-1.0");
108 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
109 SURFXML_START_TAG(process);
111 /* <argument value="0"/> */
112 SURFXML_BUFFER_SET(argument_value, "0");
113 SURFXML_START_TAG(argument);
114 SURFXML_END_TAG(argument);
115 SURFXML_END_TAG(process);
117 for(i=1;i<totalHosts;i++)
119 DEBUG1("process : %s en slave",MSG_host_get_name(hosts[i]));
120 /* <process host="host A" function="slave"> */
121 SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) );
122 SURFXML_BUFFER_SET(process_function, "slave");
123 SURFXML_BUFFER_SET(process_start_time, "-1.0");
124 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
125 SURFXML_START_TAG(process);
127 /* <argument value="num"/> */
128 SURFXML_BUFFER_SET(argument_value, bprintf("%d",i));
129 SURFXML_START_TAG(argument);
130 SURFXML_END_TAG(argument);
131 SURFXML_END_TAG(process);
134 SURFXML_END_TAG(platform);
136 free(surfxml_bufferstack);
145 int main(int argc, char **argv)
148 MSG_global_init(&argc, argv);
149 MSG_set_channel_number(MAX_CHANNEL);
150 MSG_create_environment(argv[1]);
152 MSG_function_register("master", master);
153 MSG_function_register("slave", slave);
154 surf_parse = surf_parse_bypass_application;
155 MSG_launch_application(NULL);
159 INFO1("Simulation time %g", MSG_get_clock());