3 /* Copyright (c) 2002,2004,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. */
9 * \brief Test program for msg.
14 /** This flag enable the debugging messages from PRINT_DEBUG_MESSAGE() */
18 int unix_emitter(int argc, char *argv[]);
19 int unix_receiver(int argc, char *argv[]);
20 void test_all(const char *platform_file, const char *application_file, double sharing);
23 /** The names of the channels we will use in this simulation. There is
24 only one channel identified by the name PORT_22. */
30 /** The number of task each slave will process */
32 int unix_emitter(int argc, char *argv[])
35 m_host_t *slaves = NULL;
37 m_task_t *todo = NULL;
41 { /* Process organisation */
42 slaves_count = argc - 1;
43 slaves = calloc(slaves_count, sizeof(m_host_t));
45 for (i = 1; i < argc; i++) {
46 slaves[i-1] = MSG_get_host_by_name(argv[i]);
47 if(slaves[i-1]==NULL) {
48 PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
55 char sprintf_buffer[64];
56 int slave = slaves_count;
58 todo = calloc(NB_TASK * slave, sizeof(m_task_t));
59 todo_count = NB_TASK * slave;
61 for (i = 0; i < NB_TASK * slave; i++) {
62 sprintf(sprintf_buffer, "Task_%d", i);
63 todo[i] = MSG_task_create(sprintf_buffer, 5000, 10, NULL);
67 PRINT_MESSAGE("Got %d slave(s) :\n", slaves_count);
68 for (i = 0; i < slaves_count; i++)
69 PRINT_MESSAGE("\t %s\n", slaves[i]->name);
71 PRINT_MESSAGE("Got %d task to process :\n", todo_count);
73 for (i = 0; i < todo_count; i++)
74 PRINT_MESSAGE("\t\"%s\"\n", todo[i]->name);
76 for (i = 0; i < todo_count; i++) {
77 PRINT_MESSAGE("Sending \"%s\" to \"%s\"\n",
79 slaves[i % slaves_count]->name);
80 MSG_task_put(todo[i], slaves[i % slaves_count],
82 PRINT_MESSAGE("Send completed\n");
90 int unix_receiver(int argc, char *argv[])
93 m_task_t *todo = (m_task_t *) calloc(NB_TASK, sizeof(m_task_t));
97 for (i = 0; i < NB_TASK;) {
99 PRINT_MESSAGE("Awaiting Task %d \n", i);
100 a = MSG_task_get(&(todo[i]), PORT_22);
103 PRINT_MESSAGE("Received \"%s\" \n", todo[i]->name);
104 PRINT_MESSAGE("Processing \"%s\" \n", todo[i]->name);
105 MSG_task_execute(todo[i]);
106 PRINT_MESSAGE("\"%s\" done \n", todo[i]->name);
107 MSG_task_destroy(todo[i]);
110 PRINT_MESSAGE("Hey ?! What's up ? \n");
111 DIE("Unexpected behaviour");
119 void test_all(const char *platform_file,const char *application_file, double sharing)
121 { /* Simulation setting */
123 MSG_set_verbosity(MSG_SILENT);
124 MSG_set_channel_number(MAX_CHANNEL);
126 MSG_set_sharing_policy(MSG_TCP,.1);
128 MSG_set_sharing_policy(MSG_STORE_AND_FORWARD,sharing);
130 MSG_create_environment(platform_file);
132 { /* Application deployment */
133 MSG_function_register("master", unix_emitter);
134 MSG_function_register("slave", unix_receiver);
135 MSG_launch_application(application_file);
138 /* printf("Simulation time %g\n",MSG_getClock()); */
142 int main(int argc, char *argv[])
144 test_all("msg_platform.txt","msg_deployment.txt",-.1);
145 test_all("msg_platform.txt","msg_deployment.txt",.1);