1 /* Copyright (c) 2010-2018. 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. */
7 #include "simgrid/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 static int slave(int argc, char *argv[])
13 msg_task_t task = NULL;
14 XBT_ATTRIB_UNUSED int res;
16 const char * mailbox = "jupi";
19 res = MSG_task_receive(&(task), mailbox);
20 xbt_assert(res == MSG_OK, "MSG_task_get failed");
22 if (!strcmp(MSG_task_get_name(task), "finalize")) {
23 MSG_task_destroy(task);
26 MSG_task_execute(task);
27 XBT_INFO("Task \"%s\" done", MSG_task_get_name(task));
29 MSG_task_destroy(task);
33 XBT_INFO("I'm done. See you!");
37 static int master(int argc, char *argv[])
39 double task_comp_size = 5E7;
40 double task_comm_size = 1E6;
42 const char * mailbox = "jupi";
43 msg_host_t jupiter = MSG_host_by_name("Jupiter");
45 msg_task_t task = MSG_task_create("task on", task_comp_size, task_comm_size, NULL);
46 XBT_INFO("Sending \"%s\"", task->name);
47 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
48 MSG_task_destroy(task);
51 MSG_host_off(jupiter);
53 task = MSG_task_create("task off", task_comp_size, task_comm_size, NULL);
54 XBT_INFO("Sending \"%s\"", task->name);
55 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
56 MSG_task_destroy(task);
60 xbt_dynar_t jupi_processes = xbt_dynar_new(sizeof(msg_process_t), NULL);
61 MSG_host_get_process_list(jupiter, jupi_processes);
62 msg_process_t process = NULL;
64 xbt_dynar_foreach (jupi_processes, cursor, process) {
65 MSG_process_kill(process);
67 xbt_dynar_free(&jupi_processes);
69 task = MSG_task_create("task on without proc", task_comp_size, task_comm_size, NULL);
70 XBT_INFO("Sending \"%s\"", task->name);
71 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
72 MSG_task_destroy(task);
74 char **argvF = xbt_new(char*, 2);
75 argvF[0] = xbt_strdup("slave");
76 MSG_process_create_with_arguments("slave", slave, NULL, MSG_host_by_name("Jupiter"), 1, argvF);
78 task = MSG_task_create("task on with proc", task_comp_size, task_comm_size, NULL);
79 XBT_INFO("Sending \"%s\"", task->name);
80 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
81 MSG_task_destroy(task);
83 task = MSG_task_create("finalize", 0, 0, 0);
84 XBT_INFO("Sending \"%s\"", task->name);
85 if (MSG_task_send_with_timeout(task, mailbox, 1) != MSG_OK)
86 MSG_task_destroy(task);
88 XBT_INFO("Goodbye now!");
92 int main(int argc, char *argv[])
96 MSG_init(&argc, argv);
97 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
99 MSG_create_environment(argv[1]);
101 MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
102 MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Jupiter"));
106 XBT_INFO("Simulation time %g", MSG_get_clock());
108 return res != MSG_OK;