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 sender(int argc, char *argv[]);
17 int receiver(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file, const char *application_file);
21 /** Sender function */
22 int sender(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 receivers_count = atol(argv[4]);
28 double sleep_start_time = atof(argv[5]);
29 double sleep_test_time = atof(argv[6]);
31 INFO2("sleep_start_time : %f , sleep_test_time : %f",sleep_start_time,sleep_test_time);
33 msg_comm_t comm = NULL;
36 MSG_process_sleep (sleep_start_time);
37 for (i = 0; i < number_of_tasks; i++)
40 char sprintf_buffer[256];
42 sprintf(mailbox,"receiver-%ld",i % receivers_count);
43 sprintf(sprintf_buffer, "Task_%d", i);
45 task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
46 comm=MSG_task_isend(task, mailbox);
47 INFO2("Send to receiver-%ld Task_%d",i % receivers_count,i);
49 if(sleep_test_time == 0)
51 MSG_comm_wait(comm,-1);
55 while(MSG_comm_test(comm) == 0){
56 MSG_process_sleep (sleep_test_time);
58 MSG_comm_destroy(comm);
63 for (i = 0; i < receivers_count; i++)
66 sprintf(mailbox,"receiver-%ld",i % receivers_count);
67 task = MSG_task_create ("finalize", 0, 0, 0);
68 comm = MSG_task_isend(task, mailbox);
69 INFO1("Send to receiver-%ld finalize",i % receivers_count);
70 if(sleep_test_time == 0)
72 MSG_comm_wait(comm,-1);
76 while(MSG_comm_test(comm) == 0){
77 MSG_process_sleep (sleep_test_time);
79 MSG_comm_destroy(comm);
84 INFO0("Goodbye now!");
88 /** Receiver function */
89 int receiver(int argc, char *argv[])
96 double sleep_start_time = atof(argv[2]);
97 INFO1("sleep_start_time : %f ",sleep_start_time);
99 xbt_assert1(sscanf(argv[1],"%d", &id),
100 "Invalid argument %s\n",argv[1]);
102 MSG_process_sleep (sleep_start_time);
104 sprintf(mailbox,"receiver-%d",id);
106 res_irecv = MSG_task_irecv(&(task), mailbox);
107 INFO0("Wait to receive a task");
108 res = MSG_comm_wait(res_irecv,-1);
110 xbt_assert0(res == MSG_OK, "MSG_task_get failed");
111 INFO1("Received \"%s\"", MSG_task_get_name(task));
112 if (!strcmp(MSG_task_get_name(task),"finalize")) {
113 MSG_task_destroy(task);
117 INFO1("Processing \"%s\"", MSG_task_get_name(task));
118 MSG_task_execute(task);
119 INFO1("\"%s\" done", MSG_task_get_name(task));
120 MSG_task_destroy(task);
123 INFO0("I'm done. See you!");
125 } /* end_of_receiver */
128 MSG_error_t test_all(const char *platform_file,
129 const char *application_file)
131 MSG_error_t res = MSG_OK;
133 /* MSG_config("workstation/model","KCCFLN05"); */
134 { /* Simulation setting */
135 MSG_set_channel_number(0);
136 MSG_create_environment(platform_file);
138 { /* Application deployment */
139 MSG_function_register("sender", sender);
140 MSG_function_register("receiver", receiver);
141 MSG_launch_application(application_file);
145 INFO1("Simulation time %g",MSG_get_clock());
147 } /* end_of_test_all */
151 int main(int argc, char *argv[])
153 MSG_error_t res = MSG_OK;
155 MSG_global_init(&argc,argv);
157 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
158 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
161 res = test_all(argv[1],argv[2]);
162 SIMIX_message_sizes_output("toto.txt");