1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/actor.h"
7 #include "simgrid/comm.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/forward.h"
10 #include "simgrid/mailbox.h"
11 #include "xbt/asserts.h"
15 #include <stdio.h> /* snprintf */
17 XBT_LOG_NEW_DEFAULT_CATEGORY(app_pingpong, "Messages specific for this example");
19 static void pinger(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
21 sg_mailbox_t mailbox_in = sg_mailbox_by_name("Mailbox 1");
22 sg_mailbox_t mailbox_out = sg_mailbox_by_name("Mailbox 2");
24 XBT_INFO("Ping from mailbox %s to mailbox %s", sg_mailbox_get_name(mailbox_in), sg_mailbox_get_name(mailbox_out));
26 /* - Do the ping with a 1-Byte task (latency bound) ... */
27 double* now = (double*)xbt_malloc(sizeof(double));
28 *now = simgrid_get_clock();
29 sg_mailbox_put(mailbox_out, now, 1);
31 /* - ... then wait for the (large) pong */
32 double* sender_time = (double*)sg_mailbox_get(mailbox_in);
34 double communication_time = simgrid_get_clock() - *sender_time;
35 XBT_INFO("Task received : large communication (bandwidth bound)");
36 XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
37 xbt_free(sender_time);
40 static void ponger(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
42 sg_mailbox_t mailbox_in = sg_mailbox_by_name("Mailbox 2");
43 sg_mailbox_t mailbox_out = sg_mailbox_by_name("Mailbox 1");
45 XBT_INFO("Pong from mailbox %s to mailbox %s", sg_mailbox_get_name(mailbox_in), sg_mailbox_get_name(mailbox_out));
47 /* - Receive the (small) ping first ....*/
48 double* sender_time = (double*)sg_mailbox_get(mailbox_in);
49 double communication_time = simgrid_get_clock() - *sender_time;
50 XBT_INFO("Task received : small communication (latency bound)");
51 XBT_INFO(" Ping time (latency bound) %f", communication_time);
52 xbt_free(sender_time);
54 /* - ... Then send a 1GB pong back (bandwidth bound) */
55 double* payload = (double*)xbt_malloc(sizeof(double));
56 *payload = simgrid_get_clock();
57 XBT_INFO("task_bw->data = %.3f", *payload);
58 sg_mailbox_put(mailbox_out, payload, 1e9);
61 int main(int argc, char* argv[])
63 simgrid_init(&argc, argv);
65 "Usage: %s platform_file deployment_file\n"
66 "\tExample: %s ../../platforms/small_platform.xml app-pingpong_d.xml\n",
69 simgrid_load_platform(argv[1]);
71 simgrid_register_function("pinger", pinger);
72 simgrid_register_function("ponger", ponger);
73 simgrid_load_deployment(argv[2]);
77 XBT_INFO("Total simulation time: %.3f", simgrid_get_clock());