1 /* Copyright (c) 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. */
8 #include "msg/msg.h" /* Yeah! If you want to use msg, you
9 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,
16 "Messages specific for this msg example");
18 int execute(int argc, char *argv[]);
19 int redistribute(int argc, char *argv[]);
20 MSG_error_t test_all(const char *platform_file, const char *application_file);
28 int execute(int argc, char *argv[])
32 m_host_t *m_host_list = NULL;
35 double *computation_duration = NULL;
36 double *communication_table = NULL;
37 double communication_amount;
38 double computation_amount;
39 double execution_time;
42 host_list_size = argc - 3;
43 DEBUG1("host_list_size=%d", host_list_size);
44 m_host_list = calloc(host_list_size, sizeof(m_host_t));
45 for (i = 1; i <= host_list_size; i++) {
46 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
47 xbt_assert1(m_host_list[i - 1] != NULL,
48 "Unknown host %s. Stopping Now! ", argv[i]);
51 xbt_assert1(sscanf(argv[argc - 2], "%lg", &computation_amount),
52 "Invalid argument %s\n", argv[argc - 2]);
53 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
54 "Invalid argument %s\n", argv[argc - 1]);
55 computation_duration = (double *) calloc(host_list_size, sizeof(double));
57 (double *) calloc(host_list_size * host_list_size, sizeof(double));
58 for (i = 0; i < host_list_size; i++) {
59 computation_duration[i] = computation_amount / host_list_size;
60 for (j = 0; j < host_list_size; j++)
61 communication_table[i * host_list_size + j] =
62 communication_amount / (host_list_size * host_list_size);
65 sprintf(buffer, "redist#0\n");
66 task = MSG_parallel_task_create(buffer,
70 communication_table, NULL);
72 execution_time = MSG_get_clock();
73 MSG_parallel_task_execute(task);
74 execution_time = MSG_get_clock() - execution_time;
76 INFO1("execution_time=%g ", execution_time);
82 int redistribute(int argc, char *argv[])
86 m_host_t *m_host_list = NULL;
89 double *computation_duration = NULL;
90 double *communication_table = NULL;
91 double communication_amount;
92 double redistribution_time;
95 host_list_size = argc - 2;
96 DEBUG1("host_list_size=%d", host_list_size);
97 m_host_list = calloc(host_list_size, sizeof(m_host_t));
98 for (i = 1; i <= host_list_size; i++) {
99 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
100 xbt_assert1(m_host_list[i - 1] != NULL,
101 "Unknown host %s. Stopping Now! ", argv[i]);
104 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
105 "Invalid argument %s\n", argv[argc - 1]);
106 computation_duration = (double *) calloc(host_list_size, sizeof(double));
107 communication_table =
108 (double *) calloc(host_list_size * host_list_size, sizeof(double));
109 for (i = 0; i < host_list_size; i++) {
110 for (j = 0; j < host_list_size; j++)
111 communication_table[i * host_list_size + j] =
112 communication_amount / (host_list_size * host_list_size);
115 sprintf(buffer, "redist#0\n");
116 task = MSG_parallel_task_create(buffer,
119 computation_duration,
120 communication_table, NULL);
122 redistribution_time = MSG_get_clock();
123 MSG_parallel_task_execute(task);
124 redistribution_time = MSG_get_clock() - redistribution_time;
126 INFO1("redistribution_time=%g ", redistribution_time);
132 MSG_error_t test_all(const char *platform_file, const char *application_file)
134 MSG_error_t res = MSG_OK;
137 MSG_config("workstation/model", "ptask_L07");
139 /* Simulation setting */
140 MSG_set_channel_number(MAX_CHANNEL);
141 MSG_create_environment(platform_file);
143 /* Application deployment */
144 MSG_function_register("execute", execute);
145 MSG_function_register("redistribute", redistribute);
146 MSG_launch_application(application_file);
150 INFO1("Simulation time %g", MSG_get_clock());
155 int main(int argc, char *argv[])
157 MSG_error_t res = MSG_OK;
159 MSG_global_init(&argc, argv);
161 printf("Usage: %s platform_file deployment_file\n", argv[0]);
164 res = test_all(argv[1], argv[2]);