add_executable(get_sender ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/get_sender.c)
add_executable(pid ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid.c)
add_executable(host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.c)
+add_executable(task_destroy_cancel ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/task_destroy_cancel.c)
### Add definitions for compile
target_link_libraries(get_sender simgrid)
target_link_libraries(host_on_off simgrid)
+target_link_libraries(task_destroy_cancel simgrid)
if(NOT WIN32)
target_link_libraries(pid simgrid m pthread)
else()
${CMAKE_CURRENT_SOURCE_DIR}/get_sender.tesh
${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh
+ ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.tesh
PARENT_SCOPE
)
set(xml_files
${CMAKE_CURRENT_SOURCE_DIR}/pid_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/pid_p.xml
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.xml
PARENT_SCOPE
)
set(teshsuite_src
${CMAKE_CURRENT_SOURCE_DIR}/get_sender.c
${CMAKE_CURRENT_SOURCE_DIR}/pid.c
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.c
PARENT_SCOPE
)
set(bin_files
-$ msg/host_on_off ${srcdir:=.}/msg/host_on_off.xml
-> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Sending "task on"
-> [Jupiter:slave:(2) 0.682345] [msg_test/INFO] Task "task on" done
-> [Tremblay:master:(1) 1.027003] [msg_test/INFO] Sending "task off"
-> [Tremblay:master:(1) 2.027003] [msg_test/INFO] Sending "task on without proc"
-> [Tremblay:master:(1) 3.027003] [msg_test/INFO] Sending "task on with proc"
-> [Tremblay:master:(1) 3.054005] [msg_test/INFO] Sending "finalize"
-> [Jupiter:slave:(3) 3.709348] [msg_test/INFO] Task "task on with proc" done
-> [Tremblay:master:(1) 3.710127] [msg_test/INFO] Goodbye now!
-> [Jupiter:slave:(3) 3.710127] [msg_test/INFO] I'm done. See you!
-> [3.710127] [msg_test/INFO] Simulation time 3.71013
+$ msg/task_destroy_cancel ${srcdir:=.}/msg/task_destroy_cancel.xml
+> [Tremblay:master:(1) 0.000000] [msg_test/INFO] Sending task: "normal"
+> [Jupiter:slave:(2) 0.027003] [msg_test/INFO] Handleling Task "normal"
+> [Tremblay:master:(1) 0.027003] [msg_test/INFO] Canceling task "cancel directly" directly
+> [Tremblay:master:(1) 0.027003] [msg_test/INFO] Destroying task "destroy directly" directly
+> [Tremblay:master:(1) 0.027003] [msg_test/INFO] Canceling task "cancel" during comm
+> [Tremblay:master:(1) 0.027003] [msg_test/INFO] Destroying task "finalize" during comm
+> [Jupiter:slave:(2) 0.682345] [msg_test/INFO] Task "normal" done in 0.655342 (amount 0.000000)
+> [Jupiter:slave:(2) 0.709348] [msg_test/INFO] Handleling Task "cancel"
+> [Jupiter:worker1:(3) 0.709348] [msg_test/INFO] Start cancel
+> [Jupiter:slave:(2) 0.709348] [msg_test/INFO] Canceling task "cancel"
+> [Jupiter:slave:(2) 0.709348] /home/bedaride/Boulot/simgrid/src/msg/msg_mailbox.c:129: [msg_mailbox/WARNING] Asked to write the received task in a non empty struct -- proceeding.
+> [Jupiter:worker1:(3) 0.710127] [msg_test/INFO] Task done
+> [Tremblay:master:(1) 0.736350] [msg_test/INFO] Goodbye now!
+> [Jupiter:slave:(2) 0.736350] [msg_test/INFO] Handleling Task "finalize"
+> [Jupiter:slave:(2) 0.736350] [msg_test/INFO] Destroying task "finalize"
+> [Jupiter:slave:(2) 0.736350] [msg_test/INFO] I'm done. See you!
+> [0.736350] [msg_test/INFO] Simulation time 0.73635
--- /dev/null
+/* Copyright (c) 2010-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <stdio.h>
+#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
+#include "xbt/sysdep.h" /* calloc, printf */
+
+/* Create a log channel to have nice outputs. */
+#include "xbt/log.h"
+#include "xbt/asserts.h"
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
+ "Messages specific for this msg example");
+
+int master(int argc, char *argv[]);
+int slave(int argc, char *argv[]);
+
+/** Emitter function */
+int master(int argc, char *argv[])
+{
+ double task_comp_size = 5E7;
+ double task_comm_size = 1E6;
+ double timeout = 1;
+
+ char mailbox[256];
+ msg_task_t task = NULL;
+ msg_comm_t comm = NULL;
+ sprintf(mailbox, "jupi");
+
+ task = MSG_task_create("normal", task_comp_size, task_comm_size, NULL);
+ XBT_INFO("Sending task: \"%s\"", task->name);
+ MSG_task_send_with_timeout(task, mailbox, timeout);
+
+ task = MSG_task_create("cancel directly", task_comp_size, task_comm_size, NULL);
+ XBT_INFO("Canceling task \"%s\" directly", task->name);
+ MSG_task_cancel(task);
+
+ task = MSG_task_create("destroy directly", task_comp_size, task_comm_size, NULL);
+ XBT_INFO("Destroying task \"%s\" directly", task->name);
+ MSG_task_destroy(task);
+
+ task = MSG_task_create("cancel", task_comp_size, task_comm_size, NULL);
+ comm = MSG_task_isend(task, mailbox);
+ XBT_INFO("Canceling task \"%s\" during comm", task->name);
+ MSG_task_cancel(task);
+
+ task = MSG_task_create("finalize", task_comp_size, task_comm_size, NULL);
+ comm = MSG_task_isend(task, mailbox);
+ XBT_INFO("Destroying task \"%s\" during comm", task->name);
+ MSG_task_destroy(task);
+
+ task = MSG_task_create("cancel", task_comp_size, task_comm_size, NULL);
+ MSG_task_send_with_timeout(task, mailbox, timeout);
+
+ task = MSG_task_create("finalize", task_comp_size, task_comm_size, NULL);
+ MSG_task_send_with_timeout(task, mailbox, timeout);
+
+ XBT_INFO("Goodbye now!");
+ return 0;
+} /* end_of_master */
+
+static int worker_main(int argc, char *argv[])
+{
+ msg_task_t task = MSG_process_get_data(MSG_process_self());
+ XBT_INFO("Start %s", task->name);
+ MSG_task_execute(task);
+ XBT_INFO("Task done");
+ return 0;
+}
+
+/** Receiver function */
+int slave(int argc, char *argv[])
+{
+ msg_task_t task = NULL;
+ _XBT_GNUC_UNUSED int res;
+ int id = -1;
+ char mailbox[80];
+ _XBT_GNUC_UNUSED int read;
+ double duration, start, end;
+ sprintf(mailbox, "jupi");
+
+ while (1) {
+ res = MSG_task_receive(&(task), mailbox);
+ xbt_assert(res == MSG_OK, "MSG_task_get failed");
+ XBT_INFO("Handleling task \"%s\"", MSG_task_get_name(task));
+
+ if (!strcmp(MSG_task_get_name(task), "finalize")) {
+ XBT_INFO("Destroying task \"%s\"", task->name);
+ MSG_task_destroy(task);
+ break;
+ }
+
+ if (!strcmp(MSG_task_get_name(task), "cancel")) {
+ MSG_process_create("worker1", worker_main, task, MSG_host_self());
+ XBT_INFO("Canceling task \"%s\"", task->name);
+ MSG_task_cancel(task);
+ continue;
+ }
+
+ duration = MSG_task_get_compute_duration(task);
+ start = MSG_get_clock();
+ MSG_task_execute(task);
+ end = MSG_get_clock();
+ XBT_INFO("Task \"%s\" done in %f (amount %f)"
+ , MSG_task_get_name(task)
+ , end - start
+ , MSG_task_get_remaining_computation(task));
+
+ MSG_task_destroy(task);
+ task = NULL;
+ id--;
+ }
+ XBT_INFO("I'm done. See you!");
+ return 0;
+} /* end_of_slave */
+
+/** Main function */
+int main(int argc, char *argv[])
+{
+ msg_error_t res;
+ const char *platform_file;
+ const char *application_file;
+
+ MSG_init(&argc, argv);
+ if (argc < 2) {
+ printf("Usage: %s platform_file deployment_file\n", argv[0]);
+ printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
+ exit(1);
+ }
+ platform_file = argv[1];
+ application_file = argv[1];
+
+ /* MSG_config("workstation/model","KCCFLN05"); */
+ { /* Simulation setting */
+ MSG_create_environment(platform_file);
+ }
+ { /* Application deployment */
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+
+ MSG_launch_application(application_file);
+ }
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
+
+ if (res == MSG_OK)
+ return 0;
+ else
+ return 1;
+} /* end_of_main */