1 /* Copyright (c) 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. */
8 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h" /* calloc, printf */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
18 int forwarder(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file, const char *application_file);
21 /** Emitter function */
22 int master(int argc, char *argv[])
24 long number_of_tasks = atol(argv[1]);
25 double task_comp_size = atof(argv[2]);
26 double task_comm_size = atof(argv[3]);
27 long slaves_count = atol(argv[4]);
31 INFO2("Got %ld slaves and %ld tasks to process", slaves_count,number_of_tasks);
33 for (i = 0; i < number_of_tasks; i++) {
35 char sprintf_buffer[256];
38 sprintf(mailbox,"slave-%ld",i % slaves_count);
39 sprintf(sprintf_buffer, "Task_%d", i);
40 task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
41 if (number_of_tasks<10000 || i%10000 == 0)
42 INFO3("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
44 MSG_task_send(task, mailbox);
47 INFO0("All tasks have been dispatched. Let's tell everybody the computation is over.");
48 for (i = 0; i < slaves_count; i++) {
51 sprintf(mailbox,"slave-%ld",i % slaves_count);
52 m_task_t finalize = MSG_task_create ("finalize", 0, 0, 0);
53 MSG_task_send(finalize, mailbox);
56 // INFO0("Goodbye now!");
60 /** Receiver function */
61 int slave(int argc, char *argv[])
68 xbt_assert1(sscanf(argv[1],"%d", &id),
69 "Invalid argument %s\n",argv[1]);
71 sprintf(mailbox,"slave-%d",id);
74 res = MSG_task_receive(&(task), mailbox);
75 xbt_assert0(res == MSG_OK, "MSG_task_get failed");
77 // INFO1("Received \"%s\"", MSG_task_get_name(task));
78 if (!strcmp(MSG_task_get_name(task),"finalize")) {
79 MSG_task_destroy(task);
83 // INFO1("Processing \"%s\"", MSG_task_get_name(task));
84 MSG_task_execute(task);
85 // INFO1("\"%s\" done", MSG_task_get_name(task));
86 MSG_task_destroy(task);
89 INFO0("I'm done. See you!");
94 MSG_error_t test_all(const char *platform_file,
95 const char *application_file)
97 MSG_error_t res = MSG_OK;
99 /* MSG_config("workstation/model","KCCFLN05"); */
100 { /* Simulation setting */
101 MSG_set_channel_number(0);
102 MSG_create_environment(platform_file);
104 { /* Application deployment */
105 MSG_function_register("master", master);
106 MSG_function_register("slave", slave);
107 MSG_launch_application(application_file);
111 INFO1("Simulation time %g",MSG_get_clock());
113 } /* end_of_test_all */
117 int main(int argc, char *argv[])
119 MSG_error_t res = MSG_OK;
122 MSG_global_init(&argc,argv);
124 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
125 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
128 res = test_all(argv[1],argv[2]);
129 SIMIX_message_sizes_output("toto.txt");