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,
21 const char *application_file);
29 int execute(int argc, char *argv[])
33 m_host_t *m_host_list = NULL;
36 double *computation_duration = NULL;
37 double *communication_table = NULL;
38 double communication_amount;
39 double computation_amount;
40 double execution_time;
43 host_list_size = argc - 3;
44 DEBUG1("host_list_size=%d", host_list_size);
45 m_host_list = calloc(host_list_size, sizeof(m_host_t));
46 for (i = 1; i <= host_list_size; i++) {
47 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
48 xbt_assert1(m_host_list[i - 1] != NULL,
49 "Unknown host %s. Stopping Now! ", argv[i]);
52 xbt_assert1(sscanf(argv[argc - 2], "%lg", &computation_amount),
53 "Invalid argument %s\n", argv[argc - 2]);
54 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
55 "Invalid argument %s\n", argv[argc - 1]);
56 computation_duration = (double *) calloc(host_list_size, sizeof(double));
58 (double *) calloc(host_list_size * host_list_size, sizeof(double));
59 for (i = 0; i < host_list_size; i++) {
60 computation_duration[i] = computation_amount / host_list_size;
61 for (j = 0; j < host_list_size; j++)
62 communication_table[i * host_list_size + j] =
63 communication_amount / (host_list_size * host_list_size);
66 sprintf(buffer, "redist#0\n");
67 task = MSG_parallel_task_create(buffer,
71 communication_table, NULL);
73 execution_time = MSG_get_clock();
74 MSG_parallel_task_execute(task);
75 MSG_task_destroy(task);
76 xbt_free(m_host_list);
77 execution_time = MSG_get_clock() - execution_time;
79 INFO1("execution_time=%g ", execution_time);
85 int redistribute(int argc, char *argv[])
89 m_host_t *m_host_list = NULL;
92 double *computation_duration = NULL;
93 double *communication_table = NULL;
94 double communication_amount;
95 double redistribution_time;
98 host_list_size = argc - 2;
99 DEBUG1("host_list_size=%d", host_list_size);
100 m_host_list = calloc(host_list_size, sizeof(m_host_t));
101 for (i = 1; i <= host_list_size; i++) {
102 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
103 xbt_assert1(m_host_list[i - 1] != NULL,
104 "Unknown host %s. Stopping Now! ", argv[i]);
107 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
108 "Invalid argument %s\n", argv[argc - 1]);
109 computation_duration = (double *) calloc(host_list_size, sizeof(double));
110 communication_table =
111 (double *) calloc(host_list_size * host_list_size, sizeof(double));
112 for (i = 0; i < host_list_size; i++) {
113 for (j = 0; j < host_list_size; j++)
114 communication_table[i * host_list_size + j] =
115 communication_amount / (host_list_size * host_list_size);
118 sprintf(buffer, "redist#0\n");
119 task = MSG_parallel_task_create(buffer,
122 computation_duration,
123 communication_table, NULL);
125 redistribution_time = MSG_get_clock();
126 MSG_parallel_task_execute(task);
127 MSG_task_destroy(task);
128 xbt_free(m_host_list);
129 redistribution_time = MSG_get_clock() - redistribution_time;
131 INFO1("redistribution_time=%g ", redistribution_time);
137 MSG_error_t test_all(const char *platform_file,
138 const char *application_file)
140 MSG_error_t res = MSG_OK;
143 MSG_config("workstation/model", "ptask_L07");
145 /* Simulation setting */
146 MSG_set_channel_number(MAX_CHANNEL);
147 MSG_create_environment(platform_file);
149 /* Application deployment */
150 MSG_function_register("execute", execute);
151 MSG_function_register("redistribute", redistribute);
152 MSG_launch_application(application_file);
156 INFO1("Simulation time %g", MSG_get_clock());
161 int main(int argc, char *argv[])
163 MSG_error_t res = MSG_OK;
165 MSG_global_init(&argc, argv);
167 printf("Usage: %s platform_file deployment_file\n", argv[0]);
170 res = test_all(argv[1], argv[2]);