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);
43 //MSG_comm_wait(comm, -1);
44 INFO1("Send Data to \"%s\"", mailbox);
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);
54 int slave(int argc, char *argv[])
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;
62 int num = atoi(argv[1]);
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!
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,
79 MSG_task_send(task_s, mailbox);
80 //MSG_comm_wait(comm, -1);
81 INFO1("Send Data to \"%s\"", mailbox);
86 static int surf_parse_bypass_application(void)
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);
96 totalHosts = MSG_get_host_number();
97 hosts = MSG_get_host_table();
100 SURFXML_BUFFER_SET(platform_version, "3");
102 SURFXML_START_TAG(platform);
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);
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);
118 for(i=1;i<totalHosts;i++)
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);
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);
135 SURFXML_END_TAG(platform);
137 free(surfxml_bufferstack);
146 int main(int argc, char **argv)
149 MSG_global_init(&argc, argv);
150 MSG_set_channel_number(MAX_CHANNEL);
151 MSG_create_environment(argv[1]);
153 MSG_function_register("master", master);
154 MSG_function_register("slave", slave);
155 surf_parse = surf_parse_bypass_application;
156 MSG_launch_application(NULL);
160 INFO1("Simulation time %g", MSG_get_clock());