2 #include "msg/msg.h" /* Yeah! If you want to use msg, you
3 need to include msg/msg.h */
4 #include "xbt/sysdep.h" /* calloc, printf */
6 /* Create a log channel to have nice outputs. */
8 #include "xbt/asserts.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
10 "Messages specific for this msg example");
12 int execute(int argc, char *argv[]);
13 int redistribute(int argc, char *argv[]);
14 MSG_error_t test_all(const char *platform_file, const char *application_file);
22 int execute(int argc, char *argv[])
26 m_host_t *m_host_list = NULL;
29 double *computation_duration = NULL;
30 double *communication_table = NULL;
31 double communication_amount;
32 double computation_amount;
33 double execution_time;
36 host_list_size = argc - 3;
37 DEBUG1("host_list_size=%d", host_list_size);
38 m_host_list = calloc(host_list_size, sizeof(m_host_t));
39 for (i = 1; i <= host_list_size; i++) {
40 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
41 xbt_assert1(m_host_list[i - 1] != NULL,
42 "Unknown host %s. Stopping Now! ", argv[i]);
45 xbt_assert1(sscanf(argv[argc - 2], "%lg", &computation_amount),
46 "Invalid argument %s\n", argv[argc - 2]);
47 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
48 "Invalid argument %s\n", argv[argc - 1]);
49 computation_duration = (double *) calloc(host_list_size, sizeof(double));
51 (double *) calloc(host_list_size * host_list_size, sizeof(double));
52 for (i = 0; i < host_list_size; i++) {
53 computation_duration[i] = computation_amount / host_list_size;
54 for (j = 0; j < host_list_size; j++)
55 communication_table[i * host_list_size + j] =
56 communication_amount / (host_list_size * host_list_size);
59 sprintf(buffer, "redist#0\n");
60 task = MSG_parallel_task_create(buffer,
64 communication_table, NULL);
66 execution_time = MSG_get_clock();
67 MSG_parallel_task_execute(task);
68 execution_time = MSG_get_clock() - execution_time;
70 INFO1("execution_time=%g ", execution_time);
76 int redistribute(int argc, char *argv[])
80 m_host_t *m_host_list = NULL;
83 double *computation_duration = NULL;
84 double *communication_table = NULL;
85 double communication_amount;
86 double redistribution_time;
89 host_list_size = argc - 2;
90 DEBUG1("host_list_size=%d", host_list_size);
91 m_host_list = calloc(host_list_size, sizeof(m_host_t));
92 for (i = 1; i <= host_list_size; i++) {
93 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
94 xbt_assert1(m_host_list[i - 1] != NULL,
95 "Unknown host %s. Stopping Now! ", argv[i]);
98 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
99 "Invalid argument %s\n", argv[argc - 1]);
100 computation_duration = (double *) calloc(host_list_size, sizeof(double));
101 communication_table =
102 (double *) calloc(host_list_size * host_list_size, sizeof(double));
103 for (i = 0; i < host_list_size; i++) {
104 for (j = 0; j < host_list_size; j++)
105 communication_table[i * host_list_size + j] =
106 communication_amount / (host_list_size * host_list_size);
109 sprintf(buffer, "redist#0\n");
110 task = MSG_parallel_task_create(buffer,
113 computation_duration,
114 communication_table, NULL);
116 redistribution_time = MSG_get_clock();
117 MSG_parallel_task_execute(task);
118 redistribution_time = MSG_get_clock() - redistribution_time;
120 INFO1("redistribution_time=%g ", redistribution_time);
126 MSG_error_t test_all(const char *platform_file, const char *application_file)
128 MSG_error_t res = MSG_OK;
131 MSG_config("workstation_model", "ptask_L07");
133 /* Simulation setting */
134 MSG_set_channel_number(MAX_CHANNEL);
135 MSG_create_environment(platform_file);
137 /* Application deployment */
138 MSG_function_register("execute", execute);
139 MSG_function_register("redistribute", redistribute);
140 MSG_launch_application(application_file);
144 INFO1("Simulation time %g", MSG_get_clock());
149 int main(int argc, char *argv[])
151 MSG_error_t res = MSG_OK;
153 MSG_global_init(&argc, argv);
155 printf("Usage: %s platform_file deployment_file\n", argv[0]);
158 res = test_all(argv[1], argv[2]);