3 /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
13 int master(int argc, char *argv[]);
14 int slave(int argc, char *argv[]);
15 int forwarder(int argc, char *argv[]);
16 void test_all(const char *platform_file, const char *application_file);
24 void print_args(int argc, char** argv);
25 void print_args(int argc, char** argv)
31 fprintf(stderr,"%s ",argv[i]);
32 fprintf(stderr,">\n");
35 int master(int argc, char *argv[])
38 m_host_t *slaves = NULL;
39 m_task_t *todo = NULL;
40 int number_of_tasks = 0;
41 double task_comp_size = 0;
42 double task_comm_size = 0;
47 print_args(argc,argv);
49 ASSERT(sscanf(argv[1],"%d", &number_of_tasks),
50 "Invalid argument %s\n",argv[1]);
51 ASSERT(sscanf(argv[2],"%lg", &task_comp_size),
52 "Invalid argument %s\n",argv[2]);
53 ASSERT(sscanf(argv[3],"%lg", &task_comm_size),
54 "Invalid argument %s\n",argv[3]);
57 char sprintf_buffer[64];
59 todo = calloc(number_of_tasks, sizeof(m_task_t));
61 for (i = 0; i < number_of_tasks; i++) {
62 sprintf(sprintf_buffer, "Task_%d", i);
63 todo[i] = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
67 { /* Process organisation */
68 slaves_count = argc - 4;
69 slaves = calloc(slaves_count, sizeof(m_host_t));
71 for (i = 4; i < argc; i++) {
72 slaves[i-4] = MSG_get_host_by_name(argv[i]);
73 if(slaves[i-4]==NULL) {
74 PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
80 PRINT_MESSAGE("Got %d slave(s) :\n", slaves_count);
81 for (i = 0; i < slaves_count; i++)
82 PRINT_MESSAGE("\t %s\n", slaves[i]->name);
84 PRINT_MESSAGE("Got %d task to process :\n", number_of_tasks);
86 for (i = 0; i < number_of_tasks; i++)
87 PRINT_MESSAGE("\t\"%s\"\n", todo[i]->name);
89 for (i = 0; i < number_of_tasks; i++) {
90 PRINT_MESSAGE("Sending \"%s\" to \"%s\"\n",
92 slaves[i % slaves_count]->name);
93 MSG_task_put(todo[i], slaves[i % slaves_count],
95 PRINT_MESSAGE("Send completed\n");
98 PRINT_MESSAGE("All tasks have been dispatched. Bye!\n");
104 int slave(int argc, char *argv[])
106 print_args(argc,argv);
109 m_task_t task = NULL;
111 a = MSG_task_get(&(task), PORT_22);
113 PRINT_MESSAGE("Received \"%s\" \n", task->name);
114 PRINT_MESSAGE("Processing \"%s\" \n", task->name);
115 MSG_task_execute(task);
116 PRINT_MESSAGE("\"%s\" done \n", task->name);
117 MSG_task_destroy(task);
119 PRINT_MESSAGE("Hey ?! What's up ? \n");
120 DIE("Unexpected behaviour");
123 PRINT_MESSAGE("I'm done. See you!\n");
128 int forwarder(int argc, char *argv[])
131 int slaves_count = argc - 1;
132 m_host_t *slaves = calloc(slaves_count, sizeof(m_host_t));
134 print_args(argc,argv);
136 { /* Process organisation */
137 slaves_count = argc - 1;
138 slaves = calloc(slaves_count, sizeof(m_host_t));
140 for (i = 1; i < argc; i++) {
141 slaves[i-1] = MSG_get_host_by_name(argv[i]);
142 if(slaves[i-1]==NULL) {
143 PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
151 m_task_t task = NULL;
153 a = MSG_task_get(&(task), PORT_22);
155 PRINT_MESSAGE("Received \"%s\" \n", task->name);
156 PRINT_MESSAGE("Sending \"%s\" to \"%s\"\n",
158 slaves[i % slaves_count]->name);
159 MSG_task_put(task, slaves[i % slaves_count],
162 PRINT_MESSAGE("Hey ?! What's up ? \n");
163 DIE("Unexpected behaviour");
167 PRINT_MESSAGE("I'm done. See you!\n");
172 void test_all(const char *platform_file,const char *application_file)
174 { /* Simulation setting */
175 MSG_set_channel_number(MAX_CHANNEL);
176 MSG_create_environment(platform_file);
178 { /* Application deployment */
179 MSG_function_register("master", master);
180 MSG_function_register("slave", slave);
181 MSG_function_register("forwarder", forwarder);
182 MSG_launch_application(application_file);
185 printf("Simulation time %g\n",MSG_getClock());
188 int main(int argc, char *argv[])
190 MSG_global_init_args(&argc,argv);
191 test_all("msg_platform.xml","msg_deployment.xml");