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 "simdag/simdag.h"
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 static int name_compare_hosts(const void *n1, const void *n2)
24 char name1[80], name2[80];
25 strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
26 strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
28 return strcmp(name1, name2);
31 int master(int argc, char *argv[])
33 m_task_t task_s = NULL;
34 m_task_t task_r = NULL;
35 unsigned int task_comp_size = 50000000;
36 unsigned int task_comm_size = 1000000;
39 int num = atoi(argv[1]);
41 sprintf(mailbox, "host%d", num+1);
42 if(num == totalHosts-1)
43 sprintf(mailbox, "host%d", 0);
44 sprintf(buffer, "Hello");
46 task_s = MSG_task_create(buffer,
50 MSG_task_send(task_s,mailbox);
52 //MSG_comm_wait(comm, -1);
53 INFO1("Send Data to \"%s\"", mailbox);
55 sprintf(mailbox, "host%d", num);
56 MSG_task_receive(&(task_r), mailbox);
57 //res = MSG_comm_wait(res_irecv, -1);
58 INFO1("Received \"%s\"", MSG_task_get_name(task_r));
59 //MSG_comm_destroy(res_irecv);
63 int slave(int argc, char *argv[])
65 m_task_t task_s = NULL;
66 m_task_t task_r = NULL;
67 unsigned int task_comp_size = 50000000;
68 unsigned int task_comm_size = 1000000;
71 int num = atoi(argv[1]);
73 sprintf(mailbox, "host%d", num);
74 MSG_task_receive(&(task_r), mailbox);
75 //res = MSG_comm_wait(res_irecv, -1);
76 INFO1("Received \"%s\"", MSG_task_get_name(task_r));
77 //MSG_comm_destroy(res_irecv);
78 //Receive something now need to tell it!
80 sprintf(mailbox, "host%d", num+1);
81 if(num == totalHosts-1)
82 sprintf(mailbox, "host%d", 0);
83 sprintf(buffer, "Hello");
84 task_s = MSG_task_create(buffer,
88 MSG_task_send(task_s, mailbox);
89 //MSG_comm_wait(comm, -1);
90 INFO1("Send Data to \"%s\"", mailbox);
95 static int surf_parse_bypass_application(void)
99 static int surfxml_bufferstack_size = 2048;
100 static int surfxml_buffer_stack_stack_ptr = 0;
101 static int surfxml_buffer_stack_stack[1024];
102 /* allocating memory to the buffer, I think 2MB should be enough */
103 surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
105 totalHosts = MSG_get_host_number();
106 hosts = MSG_get_host_table();
109 SURFXML_BUFFER_SET(platform_version, "3");
111 SURFXML_START_TAG(platform);
113 INFO1("process : %s en master",MSG_host_get_name(hosts[0]));
114 /* <process host="host A" function="master"> */
115 SURFXML_BUFFER_SET(process_host, MSG_host_get_name(hosts[0]));
116 SURFXML_BUFFER_SET(process_function, "master");
117 SURFXML_BUFFER_SET(process_start_time, "-1.0");
118 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
119 SURFXML_START_TAG(process);
121 /* <argument value="0"/> */
122 SURFXML_BUFFER_SET(argument_value, "0");
123 SURFXML_START_TAG(argument);
124 SURFXML_END_TAG(argument);
125 SURFXML_END_TAG(process);
127 for(i=1;i<totalHosts;i++)
129 INFO1("process : %s en slave",MSG_host_get_name(hosts[i]));
130 /* <process host="host A" function="slave"> */
131 SURFXML_BUFFER_SET(process_host,MSG_host_get_name(hosts[i]) );
132 SURFXML_BUFFER_SET(process_function, "slave");
133 SURFXML_BUFFER_SET(process_start_time, "-1.0");
134 SURFXML_BUFFER_SET(process_kill_time, "-1.0");
135 SURFXML_START_TAG(process);
137 /* <argument value="num"/> */
138 SURFXML_BUFFER_SET(argument_value, bprintf("%d",i));
139 SURFXML_START_TAG(argument);
140 SURFXML_END_TAG(argument);
141 SURFXML_END_TAG(process);
144 SURFXML_END_TAG(platform);
146 free(surfxml_bufferstack);
155 int main(int argc, char **argv)
158 MSG_global_init(&argc, argv);
159 MSG_set_channel_number(MAX_CHANNEL);
160 MSG_create_environment(argv[1]);
162 MSG_function_register("master", master);
163 MSG_function_register("slave", slave);
164 surf_parse = surf_parse_bypass_application;
165 MSG_launch_application(NULL);
169 INFO1("Simulation time %g", MSG_get_clock());