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 = 0;
39 double computation_amount = 0;
40 double execution_time;
43 host_list_size = argc - 3;
44 XBT_DEBUG("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_assert(m_host_list[i - 1] != NULL,
49 "Unknown host %s. Stopping Now! ", argv[i]);
53 read = sscanf(argv[argc - 2], "%lg", &computation_amount);
54 xbt_assert(read, "Invalid argument %s\n", argv[argc - 2]);
55 read = sscanf(argv[argc - 1], "%lg", &communication_amount);
56 xbt_assert(read, "Invalid argument %s\n", argv[argc - 1]);
57 computation_duration = (double *) calloc(host_list_size, sizeof(double));
59 (double *) calloc(host_list_size * host_list_size, sizeof(double));
60 for (i = 0; i < host_list_size; i++) {
61 computation_duration[i] = computation_amount / host_list_size;
62 for (j = 0; j < host_list_size; j++)
63 communication_table[i * host_list_size + j] =
64 communication_amount / (host_list_size * host_list_size);
67 sprintf(buffer, "redist#0\n");
68 task = MSG_parallel_task_create(buffer,
72 communication_table, NULL);
74 execution_time = MSG_get_clock();
75 MSG_parallel_task_execute(task);
76 MSG_task_destroy(task);
77 xbt_free(m_host_list);
78 execution_time = MSG_get_clock() - execution_time;
80 XBT_INFO("execution_time=%g ", execution_time);
86 int redistribute(int argc, char *argv[])
90 m_host_t *m_host_list = NULL;
93 double *computation_duration = NULL;
94 double *communication_table = NULL;
95 double communication_amount = 0;
96 double redistribution_time;
99 host_list_size = argc - 2;
100 XBT_DEBUG("host_list_size=%d", host_list_size);
101 m_host_list = calloc(host_list_size, sizeof(m_host_t));
102 for (i = 1; i <= host_list_size; i++) {
103 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
104 xbt_assert(m_host_list[i - 1] != NULL,
105 "Unknown host %s. Stopping Now! ", argv[i]);
109 read = sscanf(argv[argc - 1], "%lg", &communication_amount);
110 xbt_assert(read, "Invalid argument %s\n", argv[argc - 1]);
111 computation_duration = (double *) calloc(host_list_size, sizeof(double));
112 communication_table =
113 (double *) calloc(host_list_size * host_list_size, sizeof(double));
114 for (i = 0; i < host_list_size; i++) {
115 for (j = 0; j < host_list_size; j++)
116 communication_table[i * host_list_size + j] =
117 communication_amount / (host_list_size * host_list_size);
120 sprintf(buffer, "redist#0\n");
121 task = MSG_parallel_task_create(buffer,
124 computation_duration,
125 communication_table, NULL);
127 redistribution_time = MSG_get_clock();
128 MSG_parallel_task_execute(task);
129 MSG_task_destroy(task);
130 xbt_free(m_host_list);
131 redistribution_time = MSG_get_clock() - redistribution_time;
133 XBT_INFO("redistribution_time=%g ", redistribution_time);
139 MSG_error_t test_all(const char *platform_file,
140 const char *application_file)
142 MSG_error_t res = MSG_OK;
145 MSG_config("workstation/model", "ptask_L07");
147 /* Simulation setting */
148 MSG_set_channel_number(MAX_CHANNEL);
149 MSG_create_environment(platform_file);
151 /* Application deployment */
152 MSG_function_register("execute", execute);
153 MSG_function_register("redistribute", redistribute);
154 MSG_launch_application(application_file);
158 XBT_INFO("Simulation time %g", MSG_get_clock());
163 int main(int argc, char *argv[])
165 MSG_error_t res = MSG_OK;
167 MSG_global_init(&argc, argv);
169 printf("Usage: %s platform_file deployment_file\n", argv[0]);
172 res = test_all(argv[1], argv[2]);