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. */
9 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
10 #include "xbt/sysdep.h" /* calloc, printf */
12 /* Create a log channel to have nice outputs. */
14 #include "xbt/asserts.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
17 int master(int argc, char *argv[]);
18 int slave(int argc, char *argv[]);
19 int forwarder(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file, const char *application_file);
22 /** Emitter function */
23 int master(int argc, char *argv[])
25 long number_of_tasks = atol(argv[1]);
26 double task_comp_size = atof(argv[2]);
27 double task_comm_size = atof(argv[3]);
28 long slaves_count = atol(argv[4]);
32 printf("Got %ld slaves and %ld tasks to process\n", slaves_count,number_of_tasks);
33 // INFO2("Got %ld slaves and %ld tasks to process", slaves_count,number_of_tasks);
35 for (i = 0; i < number_of_tasks; i++) {
37 char sprintf_buffer[256];
40 sprintf(mailbox,"slave-%ld",i % slaves_count);
41 sprintf(sprintf_buffer, "Task_%d", i);
42 task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
43 if (number_of_tasks<10000 || i%10000 == 0) {
44 printf("Sending \"%s\" (of %ld) to mailbox \"%s\"\n", task->name, number_of_tasks, mailbox);
48 MSG_task_send(task, mailbox);
52 INFO0("All tasks have been dispatched. Let's tell everybody the computation is over.");
53 for (i = 0; i < slaves_count; i++) {
56 sprintf(mailbox,"slave-%ld",i % slaves_count);
57 MSG_task_send(MSG_task_create("finalize", 0, 0, 0), mailbox);
60 // INFO0("Goodbye now!");
64 /** Receiver function */
65 int slave(int argc, char *argv[])
72 xbt_assert1(sscanf(argv[1],"%d", &id),
73 "Invalid argument %s\n",argv[1]);
75 sprintf(mailbox,"slave-%d",id);
78 res = MSG_task_receive(&(task), mailbox);
79 xbt_assert0(res == MSG_OK, "MSG_task_get failed");
81 // INFO1("Received \"%s\"", MSG_task_get_name(task));
82 if (!strcmp(MSG_task_get_name(task),"finalize")) {
83 MSG_task_destroy(task);
87 // INFO1("Processing \"%s\"", MSG_task_get_name(task));
88 MSG_task_execute(task);
89 // INFO1("\"%s\" done", MSG_task_get_name(task));
90 MSG_task_destroy(task);
93 INFO0("I'm done. See you!");
98 MSG_error_t test_all(const char *platform_file,
99 const char *application_file)
101 MSG_error_t res = MSG_OK;
103 /* MSG_config("surf_workstation_model","KCCFLN05"); */
104 { /* Simulation setting */
105 MSG_set_channel_number(0);
106 MSG_paje_output("msg_test.trace");
107 MSG_create_environment(platform_file);
109 { /* Application deployment */
110 MSG_function_register("master", master);
111 MSG_function_register("slave", slave);
112 MSG_launch_application(application_file);
116 INFO1("Simulation time %g",MSG_get_clock());
118 } /* end_of_test_all */
122 int main(int argc, char *argv[])
124 MSG_error_t res = MSG_OK;
126 MSG_global_init(&argc,argv);
128 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
129 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
132 res = test_all(argv[1],argv[2]);