1 /* Copyright (c) 2008-2012. 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);
24 int execute(int argc, char *argv[])
28 msg_host_t *m_host_list = NULL;
29 msg_task_t task = NULL;
31 double *computation_duration = NULL;
32 double *communication_table = NULL;
33 double communication_amount = 0;
34 double computation_amount = 0;
35 double execution_time;
38 host_list_size = argc - 3;
39 XBT_DEBUG("host_list_size=%d", host_list_size);
40 m_host_list = calloc(host_list_size, sizeof(msg_host_t));
41 for (i = 1; i <= host_list_size; i++) {
42 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
43 xbt_assert(m_host_list[i - 1] != NULL,
44 "Unknown host %s. Stopping Now! ", argv[i]);
47 _XBT_GNUC_UNUSED int read;
48 read = sscanf(argv[argc - 2], "%lg", &computation_amount);
49 xbt_assert(read, "Invalid argument %s\n", argv[argc - 2]);
50 read = sscanf(argv[argc - 1], "%lg", &communication_amount);
51 xbt_assert(read, "Invalid argument %s\n", argv[argc - 1]);
52 computation_duration = (double *) calloc(host_list_size, sizeof(double));
54 (double *) calloc(host_list_size * host_list_size, sizeof(double));
55 for (i = 0; i < host_list_size; i++) {
56 computation_duration[i] = computation_amount / host_list_size;
57 for (j = 0; j < host_list_size; j++)
58 communication_table[i * host_list_size + j] =
59 communication_amount / (host_list_size * host_list_size);
62 sprintf(buffer, "redist#0\n");
63 task = MSG_parallel_task_create(buffer,
67 communication_table, NULL);
69 execution_time = MSG_get_clock();
70 MSG_parallel_task_execute(task);
71 MSG_task_destroy(task);
72 xbt_free(m_host_list);
73 execution_time = MSG_get_clock() - execution_time;
75 XBT_INFO("execution_time=%g ", execution_time);
81 int redistribute(int argc, char *argv[])
85 msg_host_t *m_host_list = NULL;
86 msg_task_t task = NULL;
88 double *computation_duration = NULL;
89 double *communication_table = NULL;
90 double communication_amount = 0;
91 double redistribution_time;
94 host_list_size = argc - 2;
95 XBT_DEBUG("host_list_size=%d", host_list_size);
96 m_host_list = calloc(host_list_size, sizeof(msg_host_t));
97 for (i = 1; i <= host_list_size; i++) {
98 m_host_list[i - 1] = MSG_get_host_by_name(argv[i]);
99 xbt_assert(m_host_list[i - 1] != NULL,
100 "Unknown host %s. Stopping Now! ", argv[i]);
103 _XBT_GNUC_UNUSED int read;
104 read = sscanf(argv[argc - 1], "%lg", &communication_amount);
105 xbt_assert(read, "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 MSG_task_destroy(task);
125 xbt_free(m_host_list);
126 redistribution_time = MSG_get_clock() - redistribution_time;
128 XBT_INFO("redistribution_time=%g ", redistribution_time);
134 msg_error_t test_all(const char *platform_file,
135 const char *application_file)
137 msg_error_t res = MSG_OK;
140 MSG_config("workstation/model", "ptask_L07");
142 /* Simulation setting */
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 XBT_INFO("Simulation time %g", MSG_get_clock());
157 int main(int argc, char *argv[])
159 msg_error_t res = MSG_OK;
161 MSG_init(&argc, argv);
163 printf("Usage: %s platform_file deployment_file\n", argv[0]);
166 res = test_all(argv[1], argv[2]);