include examples/c/actor-create/actor-create.c
include examples/c/actor-create/actor-create.tesh
include examples/c/actor-create/actor-create_d.xml
+include examples/c/app-pingpong/app-pingpong.c
+include examples/c/app-pingpong/app-pingpong.tesh
+include examples/c/app-pingpong/app-pingpong_d.xml
include examples/c/async-waitany/async-waitany.c
include examples/c/async-waitany/async-waitany.tesh
include examples/c/async-waitany/async-waitany_d.xml
include teshsuite/msg/app-chainsend/messages.h
include teshsuite/msg/app-chainsend/peer.c
include teshsuite/msg/app-chainsend/peer.h
-include teshsuite/msg/app-pingpong/app-pingpong.c
-include teshsuite/msg/app-pingpong/app-pingpong.tesh
include teshsuite/msg/app-pingpong/app-pingpong_d.xml
include teshsuite/msg/app-token-ring/app-token-ring.c
include teshsuite/msg/app-token-ring/app-token-ring.tesh
-foreach(x actor-create async-waitany)
+foreach(x actor-create app-pingpong async-waitany)
add_executable (${x}-c EXCLUDE_FROM_ALL ${x}/${x}.c)
target_link_libraries(${x}-c simgrid)
set_target_properties(${x}-c PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
set(tesh_files ${tesh_files} PARENT_SCOPE)
set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/actor-create_d.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml
- PARENT_SCOPE)
+ ${CMAKE_CURRENT_SOURCE_DIR}/app-pingpong/app-pingpong_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml
+ PARENT_SCOPE)
-foreach(x async-waitany)
+foreach(x app-pingpong async-waitany)
ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
--setenv bindir=${CMAKE_BINARY_DIR}/examples/c/${x}
--cd ${CMAKE_HOME_DIRECTORY}/examples/c/${x}
--- /dev/null
+/* Copyright (c) 2007-2020. 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 "simgrid/actor.h"
+#include "simgrid/comm.h"
+#include "simgrid/engine.h"
+#include "simgrid/forward.h"
+#include "simgrid/mailbox.h"
+#include "xbt/asserts.h"
+#include "xbt/log.h"
+#include "xbt/str.h"
+
+#include <stdio.h> /* snprintf */
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(app_pingpong, "Messages specific for this example");
+
+static void pinger(int argc, char* argv[])
+{
+ sg_mailbox_t mailbox_in = sg_mailbox_by_name("Mailbox 1");
+ sg_mailbox_t mailbox_out = sg_mailbox_by_name("Mailbox 2");
+
+ XBT_INFO("Ping from mailbox %s to mailbox %s", sg_mailbox_get_name(mailbox_in), sg_mailbox_get_name(mailbox_out));
+
+ /* - Do the ping with a 1-Byte task (latency bound) ... */
+ double* now = (double*)xbt_malloc(sizeof(double));
+ *now = simgrid_get_clock();
+ sg_mailbox_put(mailbox_out, now, 1);
+
+ /* - ... then wait for the (large) pong */
+ double* sender_time = (double*)sg_mailbox_get(mailbox_in);
+
+ double communication_time = simgrid_get_clock() - *sender_time;
+ XBT_INFO("Task received : large communication (bandwidth bound)");
+ XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
+ xbt_free(sender_time);
+}
+
+static void ponger(int argc, char* argv[])
+{
+ sg_mailbox_t mailbox_in = sg_mailbox_by_name("Mailbox 2");
+ sg_mailbox_t mailbox_out = sg_mailbox_by_name("Mailbox 1");
+
+ XBT_INFO("Pong from mailbox %s to mailbox %s", sg_mailbox_get_name(mailbox_in), sg_mailbox_get_name(mailbox_out));
+
+ /* - Receive the (small) ping first ....*/
+ double* sender_time = (double*)sg_mailbox_get(mailbox_in);
+ double communication_time = simgrid_get_clock() - *sender_time;
+ XBT_INFO("Task received : small communication (latency bound)");
+ XBT_INFO(" Ping time (latency bound) %f", communication_time);
+ xbt_free(sender_time);
+
+ /* - ... Then send a 1GB pong back (bandwidth bound) */
+ double* payload = (double*)xbt_malloc(sizeof(double));
+ *payload = simgrid_get_clock();
+ XBT_INFO("task_bw->data = %.3f", *payload);
+ sg_mailbox_put(mailbox_out, payload, 1e9);
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid_init(&argc, argv);
+ xbt_assert(argc > 2,
+ "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s ../../platforms/small_platform.xml app-pingpong_d.xml\n",
+ argv[0], argv[0]);
+
+ simgrid_load_platform(argv[1]);
+
+ simgrid_register_function("pinger", pinger);
+ simgrid_register_function("ponger", ponger);
+ simgrid_load_deployment(argv[2]);
+
+ simgrid_run();
+
+ XBT_INFO("Total simulation time: %.3f", simgrid_get_clock());
+
+ return 0;
+}
p Testing with default compound
-$ ${bindir:=.}/app-pingpong ${platfdir}/small_platform.xml app-pingpong_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter
-> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay
+$ ${bindir:=.}/app-pingpong-c ${platfdir}/small_platform.xml app-pingpong_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2
+> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1
> [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound)
> [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014
> [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019
p Testing with default compound and Full network optimization
-$ ${bindir:=.}/app-pingpong ${platfdir}/small_platform.xml app-pingpong_d.xml "--cfg=network/optim:Full" "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ ${bindir:=.}/app-pingpong-c ${platfdir}/small_platform.xml app-pingpong_d.xml "--cfg=network/optim:Full" "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:maestro@) Configuration change: Set 'network/optim' to 'Full'
-> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter
-> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay
+> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2
+> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1
> [ 0.019014] (2:ponger@Jupiter) Task received : small communication (latency bound)
> [ 0.019014] (2:ponger@Jupiter) Ping time (latency bound) 0.019014
> [ 0.019014] (2:ponger@Jupiter) task_bw->data = 0.019
p Testing the deprecated CM02 network model
-$ ${bindir:=.}/app-pingpong ${platfdir}/small_platform.xml app-pingpong_d.xml --cfg=cpu/model:Cas01 --cfg=network/model:CM02 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ ${bindir:=.}/app-pingpong-c ${platfdir}/small_platform.xml app-pingpong_d.xml --cfg=cpu/model:Cas01 --cfg=network/model:CM02 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01'
> [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'CM02'
-> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter
-> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay
+> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2
+> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1
> [ 0.001462] (2:ponger@Jupiter) Task received : small communication (latency bound)
> [ 0.001462] (2:ponger@Jupiter) Ping time (latency bound) 0.001462
> [ 0.001462] (2:ponger@Jupiter) task_bw->data = 0.001
p Testing the surf network constant model
-$ ${bindir:=.}/app-pingpong ${platfdir}/small_platform_constant.xml app-pingpong_d.xml "--cfg=host/model:compound cpu/model:Cas01 network/model:Constant" "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+$ ${bindir:=.}/app-pingpong-c ${platfdir}/small_platform_constant.xml app-pingpong_d.xml "--cfg=host/model:compound cpu/model:Cas01 network/model:Constant" "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:maestro@) Configuration change: Set 'host/model' to 'compound'
> [ 0.000000] (0:maestro@) Configuration change: Set 'cpu/model' to 'Cas01'
> [ 0.000000] (0:maestro@) Configuration change: Set 'network/model' to 'Constant'
-> [ 0.000000] (1:pinger@Tremblay) Ping -> Jupiter
-> [ 0.000000] (2:ponger@Jupiter) Pong -> Tremblay
+> [ 0.000000] (1:pinger@Tremblay) Ping from mailbox Mailbox 1 to mailbox Mailbox 2
+> [ 0.000000] (2:ponger@Jupiter) Pong from mailbox Mailbox 2 to mailbox Mailbox 1
> [ 13.010000] (2:ponger@Jupiter) Task received : small communication (latency bound)
> [ 13.010000] (2:ponger@Jupiter) Ping time (latency bound) 13.010000
> [ 13.010000] (2:ponger@Jupiter) task_bw->data = 13.010
<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
<platform version="4.1">
<!-- For using with ping_pong, platform_sendrecv.xml -->
- <actor host="Tremblay" function="pinger">
- <argument value="Jupiter"/>
- </actor>
- <actor host="Jupiter" function="ponger">
- <argument value="Tremblay"/>
- </actor>
+ <actor host="Tremblay" function="pinger"/>
+ <actor host="Jupiter" function="ponger"/>
</platform>
# C examples
-foreach(x app-pingpong app-token-ring
+foreach(x app-token-ring
async-wait async-waitall async-waitany
cloud-capping cloud-migration cloud-two-tasks cloud-simple
get_sender host_on_off host_on_off_recv
if(enable_msg)
foreach(x
async-wait async-waitall
- app-bittorrent app-chainsend app-pingpong app-token-ring
+ app-bittorrent app-chainsend app-token-ring
cloud-capping cloud-migration cloud-two-tasks cloud-simple
energy-pstate
host_on_off host_on_off_processes host_on_off_recv
+++ /dev/null
-/* Copyright (c) 2007-2020. 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 "simgrid/msg.h"
-
-#include <stdio.h> /* snprintf */
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_app_pingpong, "Messages specific for this msg example");
-
-static int pinger(int argc, char* argv[])
-{
- xbt_assert(argc == 2, "The pinger function one argument from the XML deployment file");
- XBT_INFO("Ping -> %s", argv[1]);
- xbt_assert(MSG_host_by_name(argv[1]) != NULL, "Unknown host %s. Stopping Now! ", argv[1]);
-
- /* - Do the ping with a 1-Byte task (latency bound) ... */
- double now = MSG_get_clock();
- msg_task_t ping_task = MSG_task_create("small communication (latency bound)", 0.0, 1, &now);
- MSG_task_send(ping_task, argv[1]);
-
- /* - ... then wait for the (large) pong */
- msg_task_t pong_task = NULL;
- int a = MSG_task_receive(&pong_task, MSG_host_get_name(MSG_host_self()));
- xbt_assert(a == MSG_OK, "Unexpected behavior");
-
- double sender_time = *((double*)(MSG_task_get_data(pong_task)));
- double communication_time = MSG_get_clock() - sender_time;
- XBT_INFO("Task received : %s", MSG_task_get_name(pong_task));
- MSG_task_destroy(pong_task);
- XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
-
- return 0;
-}
-
-static int ponger(int argc, char* argv[])
-{
- xbt_assert(argc == 2, "The ponger function one argument from the XML deployment file");
- XBT_INFO("Pong -> %s", argv[1]);
- xbt_assert(MSG_host_by_name(argv[1]) != NULL, "Unknown host %s. Stopping Now! ", argv[1]);
-
- /* - Receive the (small) ping first ....*/
- msg_task_t ping_task = NULL;
- int a = MSG_task_receive(&ping_task, MSG_host_get_name(MSG_host_self()));
- xbt_assert(a == MSG_OK, "Unexpected behavior");
-
- double sender_time = *((double*)(MSG_task_get_data(ping_task)));
- double communication_time = MSG_get_clock() - sender_time;
- XBT_INFO("Task received : %s", MSG_task_get_name(ping_task));
- MSG_task_destroy(ping_task);
- XBT_INFO(" Ping time (latency bound) %f", communication_time);
-
- /* - ... Then send a 1GB pong back (bandwidth bound) */
- double now = MSG_get_clock();
- msg_task_t pong_task = MSG_task_create("large communication (bandwidth bound)", 0.0, 1e9, &now);
- XBT_INFO("task_bw->data = %.3f", *((double*)MSG_task_get_data(pong_task)));
- MSG_task_send(pong_task, argv[1]);
-
- return 0;
-}
-
-int main(int argc, char* argv[])
-{
- MSG_init(&argc, argv);
-
- xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
- "\tExample: %s ../../platforms/small_platform.xml app-pingpong_d.xml\n",
- argv[0], argv[0]);
-
- MSG_create_environment(argv[1]); /* - Load the platform description */
-
- MSG_function_register("pinger", pinger); /* - Register the functions to be executed by the processes */
- MSG_function_register("ponger", ponger);
-
- MSG_launch_application(argv[2]); /* - Deploy the application */
-
- msg_error_t res = MSG_main(); /* - Run the simulation */
-
- XBT_INFO("Total simulation time: %.3f", MSG_get_clock());
- return res != MSG_OK;
-}