1 /* Copyright (c) 2007, 2008, 2009, 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. */
11 #include "xbt/asserts.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
14 "Messages specific for this msg example");
16 int master(int argc, char *argv[]);
17 int slave(int argc, char *argv[]);
18 int timer(int argc, char *argv[]);
19 MSG_error_t test_all(const char *platform_file,
20 const char *application_file);
22 int timer_start; //set as 1 in the master process
24 //keep a pointer to all surf running tasks.
27 double start_time, end_time, elapsed_time;
28 double gl_data_size[NTASKS];
29 m_task_t gl_task_array[NTASKS];
30 const char *slavenames[NTASKS];
31 const char *masternames[NTASKS];
32 int gl_task_array_id = 0;
33 int count_finished = 0;
35 #define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */
38 int master(int argc, char *argv[])
40 char *slavename = NULL;
41 double task_comm_size = 0;
44 //unique id to control statistics
47 xbt_assert(argc==4,"Strange number of arguments expected 3 got %d", argc - 1);
49 XBT_DEBUG ("Master started");
53 read = sscanf(argv[1], "%lg", &task_comm_size);
54 xbt_assert(read, "Invalid argument %s\n", argv[1]);
59 sprintf(id_alias, "flow_%d", id);
60 slavenames[id] = slavename;
61 TRACE_category(id_alias);
63 masternames[id] = MSG_host_get_name(MSG_host_self());
65 { /* Task creation. */
66 char sprintf_buffer[64] = "Task_0";
67 todo = MSG_task_create(sprintf_buffer, 100*task_comm_size, task_comm_size, NULL);
68 TRACE_msg_set_task_category(todo, id_alias);
69 //keep track of running tasks
70 gl_task_array[id] = todo;
71 gl_data_size[id] = task_comm_size;
74 { /* Process organisation */
75 MSG_get_host_by_name(slavename);
81 /* time measurement */
82 sprintf(id_alias, "%d", id);
83 start_time = MSG_get_clock();
84 //MSG_task_execute(todo);
85 MSG_task_send(todo, id_alias);
86 end_time = MSG_get_clock();
88 XBT_DEBUG ("Finished");
94 int timer(int argc, char *argv[])
99 xbt_assert(argc==3,"Strange number of arguments expected 2 got %d", argc - 1);
101 sscanf(argv[1], "%lf", &first_sleep);
102 sscanf(argv[2], "%lf", &sleep_time);
104 XBT_DEBUG ("Timer started");
107 MSG_process_sleep(first_sleep);
111 XBT_DEBUG ("Get sleep");
112 MSG_process_sleep(sleep_time);
113 } while(timer_start);
115 XBT_DEBUG ("Finished");
119 /** Receiver function */
120 int slave(int argc, char *argv[])
123 m_task_t task = NULL;
128 xbt_assert(argc==2,"Strange number of arguments expected 1 got %d", argc - 1);
130 XBT_DEBUG ("Slave started");
133 sprintf(id_alias, "%d", id);
135 a = MSG_task_receive(&(task), id_alias);
138 if(count_finished == 0){
145 XBT_INFO("Hey?! What's up?");
146 xbt_die("Unexpected behavior.");
149 elapsed_time = MSG_get_clock() - start_time;
151 XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s",
153 MSG_task_get_data_size(task),
156 // MSG_task_execute(task);
157 MSG_task_destroy(task);
159 XBT_DEBUG ("Finished");
164 MSG_error_t test_all(const char *platform_file,
165 const char *application_file)
167 MSG_error_t res = MSG_OK;
169 /* MSG_config("workstation/model", "GTNETS"); */
170 /* MSG_config("workstation/model","KCCFLN05"); */
171 { /* Simulation setting */
172 MSG_create_environment(platform_file);
175 TRACE_declare_mark("endmark");
177 { /* Application deployment */
178 MSG_function_register("master", master);
179 MSG_function_register("slave", slave);
180 MSG_function_register("timer", timer);
182 MSG_launch_application(application_file);
186 } /* end_of_test_all */
189 int main(int argc, char *argv[])
191 MSG_error_t res = MSG_OK;
194 MSG_global_init(&argc, argv);
196 printf("Usage: %s platform_file deployment_file\n", argv[0]);
200 res = test_all(argv[1], argv[2]);