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 execution_time = MSG_get_clock() - execution_time;
77 INFO1("execution_time=%g ", execution_time);
83 int redistribute(int argc, char *argv[])
87 m_host_t *m_host_list = NULL;
90 double *computation_duration = NULL;
91 double *communication_table = NULL;
92 double communication_amount;
93 double redistribution_time;
96 host_list_size = argc - 2;
97 DEBUG1("host_list_size=%d", host_list_size);
98 m_host_list = calloc(host_list_size, sizeof(m_host_t));
99 for (i = 1; i <= host_list_size; i++) {
100 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
101 xbt_assert1(m_host_list[i - 1] != NULL,
102 "Unknown host %s. Stopping Now! ", argv[i]);
105 xbt_assert1(sscanf(argv[argc - 1], "%lg", &communication_amount),
106 "Invalid argument %s\n", argv[argc - 1]);
107 computation_duration = (double *) calloc(host_list_size, sizeof(double));
108 communication_table =
109 (double *) calloc(host_list_size * host_list_size, sizeof(double));
110 for (i = 0; i < host_list_size; i++) {
111 for (j = 0; j < host_list_size; j++)
112 communication_table[i * host_list_size + j] =
113 communication_amount / (host_list_size * host_list_size);
116 sprintf(buffer, "redist#0\n");
117 task = MSG_parallel_task_create(buffer,
120 computation_duration,
121 communication_table, NULL);
123 redistribution_time = MSG_get_clock();
124 MSG_parallel_task_execute(task);
125 redistribution_time = MSG_get_clock() - redistribution_time;
127 INFO1("redistribution_time=%g ", redistribution_time);
133 MSG_error_t test_all(const char *platform_file,
134 const char *application_file)
136 MSG_error_t res = MSG_OK;
139 MSG_config("workstation/model", "ptask_L07");
141 /* Simulation setting */
142 MSG_set_channel_number(MAX_CHANNEL);
143 MSG_create_environment(platform_file);
145 /* Application deployment */
146 MSG_function_register("execute", execute);
147 MSG_function_register("redistribute", redistribute);
148 MSG_launch_application(application_file);
152 INFO1("Simulation time %g", MSG_get_clock());
157 int main(int argc, char *argv[])
159 MSG_error_t res = MSG_OK;
161 MSG_global_init(&argc, argv);
163 printf("Usage: %s platform_file deployment_file\n", argv[0]);
166 res = test_all(argv[1], argv[2]);