include examples/c/comm-wait/comm-wait3_d.xml
include examples/c/comm-wait/comm-wait4_d.xml
include examples/c/comm-wait/comm-wait_d.xml
-include examples/c/comm-waitall/comm-waitall.c
-include examples/c/comm-waitall/comm-waitall.tesh
-include examples/c/comm-waitall/comm-waitall_d.xml
include examples/c/comm-waitany/comm-waitany.c
include examples/c/comm-waitany/comm-waitany.tesh
include examples/c/comm-waitany/comm-waitany_d.xml
actor-suspend actor-yield
activityset-testany activityset-waitall activityset-waitallfor activityset-waitany
app-masterworker app-token-ring
- comm-pingpong comm-wait comm-waitall comm-waitany
+ comm-pingpong comm-wait comm-waitany
cloud-capping cloud-masterworker cloud-migration cloud-simple
dht-pastry
exec-async exec-basic exec-dvfs exec-remote
${CMAKE_CURRENT_SOURCE_DIR}/comm-wait/comm-wait2_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/comm-wait/comm-wait3_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/comm-wait/comm-wait4_d.xml
- ${CMAKE_CURRENT_SOURCE_DIR}/comm-waitall/comm-waitall_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/comm-waitany/comm-waitany_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-kademlia_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/dht-pastry/dht-pastry_d.xml
actor-suspend actor-yield
activityset-testany activityset-waitall activityset-waitallfor activityset-waitany
app-bittorrent app-chainsend app-masterworker app-token-ring
- comm-pingpong comm-wait comm-waitall comm-waitany
+ comm-pingpong comm-wait comm-waitany
cloud-capping cloud-masterworker cloud-migration cloud-simple
dht-kademlia dht-pastry
exec-async exec-basic exec-dvfs exec-remote
static void broadcaster_send_file(const_broadcaster_t bc)
{
- int nb_pending_sends = 0;
-
for (unsigned int current_piece = 0; current_piece < bc->piece_count; current_piece++) {
XBT_DEBUG("Sending (send) piece %u from %s into mailbox %s", current_piece, sg_host_self_get_name(),
sg_mailbox_get_name(bc->first));
char* file_piece = bprintf("piece-%u", current_piece);
sg_comm_t comm = sg_mailbox_put_async(bc->first, file_piece, MESSAGE_SEND_DATA_HEADER_SIZE + PIECE_SIZE);
- bc->pending_sends[nb_pending_sends++] = comm;
+ sg_activity_set_push(bc->pending_sends, (sg_activity_t)comm);
}
- sg_comm_wait_all(bc->pending_sends, nb_pending_sends);
+ sg_activity_set_wait_all(bc->pending_sends);
}
static broadcaster_t broadcaster_init(sg_mailbox_t* mailboxes, unsigned int host_count, unsigned int piece_count)
bc->host_count = host_count;
bc->piece_count = piece_count;
bc->mailboxes = mailboxes;
- bc->pending_sends = xbt_malloc(sizeof(sg_comm_t) * MAX_PENDING_COMMS);
+ bc->pending_sends = sg_activity_set_init();
broadcaster_build_chain(bc);
static void broadcaster_destroy(broadcaster_t bc)
{
- xbt_free(bc->pending_sends);
+ sg_activity_set_delete(bc->pending_sends);
xbt_free(bc->mailboxes);
xbt_free(bc);
}
#ifndef CHAINSEND_H
#define CHAINSEND_H
+#include "simgrid/activity_set.h"
#include "simgrid/actor.h"
#include "simgrid/comm.h"
#include "simgrid/engine.h"
unsigned int piece_count;
sg_mailbox_t first;
sg_mailbox_t* mailboxes;
- sg_comm_t* pending_sends;
+ sg_activity_set_t pending_sends;
} s_broadcaster_t;
typedef s_broadcaster_t* broadcaster_t;
unsigned long long received_bytes;
unsigned int received_pieces;
unsigned int total_pieces;
- sg_comm_t* pending_recvs;
- sg_comm_t* pending_sends;
+ sg_activity_set_t pending_recvs;
+ sg_activity_set_t pending_sends;
} s_peer_t;
typedef s_peer_t* peer_t;
-/* Copyright (c) 2012-2023. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2012-2023. 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. */
static void peer_forward_file(peer_t p)
{
void* received;
- int done = 0;
- size_t nb_pending_sends = 0;
- size_t nb_pending_recvs = 0;
+ int done = 0;
while (!done) {
- p->pending_recvs[nb_pending_recvs] = sg_mailbox_get_async(p->me, &received);
- nb_pending_recvs++;
+ sg_activity_set_push(p->pending_recvs, (sg_activity_t)sg_mailbox_get_async(p->me, &received));
- ssize_t idx = sg_comm_wait_any(p->pending_recvs, nb_pending_recvs);
- if (idx != -1) {
+ sg_activity_t acti = sg_activity_set_wait_any(p->pending_recvs);
+ if (acti != NULL) {
+ sg_comm_unref((sg_comm_t)acti);
XBT_DEBUG("Peer %s got a 'SEND_DATA' message", sg_mailbox_get_name(p->me));
- /* move the last pending comm where the finished one was, and decrement */
- p->pending_recvs[idx] = p->pending_recvs[--nb_pending_recvs];
if (p->next != NULL) {
XBT_DEBUG("Sending %s (asynchronously) from %s to %s", (char*)received, sg_mailbox_get_name(p->me),
sg_mailbox_get_name(p->next));
sg_comm_t send = sg_mailbox_put_async(p->next, received, MESSAGE_SEND_DATA_HEADER_SIZE + PIECE_SIZE);
- p->pending_sends[nb_pending_sends] = send;
- nb_pending_sends++;
+ sg_activity_set_push(p->pending_sends, (sg_activity_t)send);
} else
free(received);
}
}
}
- sg_comm_wait_all(p->pending_sends, nb_pending_sends);
+ sg_activity_set_wait_all(p->pending_sends);
}
static peer_t peer_init(int argc, char* argv[])
p->next = NULL;
p->received_pieces = 0;
p->received_bytes = 0;
- p->pending_recvs = xbt_malloc(sizeof(sg_comm_t) * MAX_PENDING_COMMS);
- p->pending_sends = xbt_malloc(sizeof(sg_comm_t) * MAX_PENDING_COMMS);
+ p->pending_recvs = sg_activity_set_init();
+ p->pending_sends = sg_activity_set_init();
p->me = sg_mailbox_by_name(sg_host_self_get_name());
static void peer_delete(peer_t p)
{
- xbt_free(p->pending_recvs);
- xbt_free(p->pending_sends);
+ sg_activity_set_delete(p->pending_recvs);
+ sg_activity_set_delete(p->pending_sends);
xbt_free(p);
}
+++ /dev/null
-/* Copyright (c) 2010-2023. 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/host.h"
-#include "simgrid/mailbox.h"
-
-#include "xbt/log.h"
-#include "xbt/str.h"
-#include "xbt/sysdep.h"
-
-#include <stdio.h> /* snprintf */
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(comm_waitall, "Messages specific for this example");
-
-static void sender(int argc, char* argv[])
-{
- xbt_assert(argc == 4, "This function expects 3 parameters from the XML deployment file");
- long messages_count = xbt_str_parse_int(argv[1], "Invalid message count");
- long message_size = xbt_str_parse_int(argv[2], "Invalid message size");
- long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers");
- xbt_assert(receivers_count > 0);
-
- /* Array in which we store all ongoing communications */
- sg_comm_t* pending_comms = xbt_malloc(sizeof(sg_comm_t) * (messages_count + receivers_count));
- int pending_comms_count = 0;
-
- /* Make an array of the mailboxes to use */
- sg_mailbox_t* mboxes = xbt_malloc(sizeof(sg_mailbox_t) * receivers_count);
- for (long i = 0; i < receivers_count; i++) {
- char mailbox_name[80];
- snprintf(mailbox_name, 79, "receiver-%ld", i);
- sg_mailbox_t mbox = sg_mailbox_by_name(mailbox_name);
- mboxes[i] = mbox;
- }
-
- /* Start dispatching all messages to receivers, in a round robin fashion */
- for (long i = 0; i < messages_count; i++) {
- char msg_content[80];
- snprintf(msg_content, 79, "Message %ld", i);
- sg_mailbox_t mbox = mboxes[i % receivers_count];
- XBT_INFO("Send '%s' to '%s'", msg_content, sg_mailbox_get_name(mbox));
- /* Create a communication representing the ongoing communication, and store it in pending_comms */
- pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), message_size);
- }
-
- /* Start sending messages to let the workers know that they should stop */
- for (long i = 0; i < receivers_count; i++) {
- XBT_INFO("Send 'finalize' to 'receiver-%ld'", i);
- char* end_msg = xbt_strdup("finalize");
- sg_mailbox_t mbox = mboxes[i % receivers_count];
- pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, end_msg, 0);
- }
-
- XBT_INFO("Done dispatching all messages");
-
- /* Now that all message exchanges were initiated, wait for their completion in one single call */
- sg_comm_wait_all(pending_comms, pending_comms_count);
-
- xbt_free(pending_comms);
- xbt_free(mboxes);
-
- XBT_INFO("Goodbye now!");
-}
-
-static void receiver(int argc, char* argv[])
-{
- xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc);
- int id = (int)xbt_str_parse_int(argv[1], "ID should be numerical");
- char mailbox_name[80];
- snprintf(mailbox_name, 79, "receiver-%d", id);
- sg_mailbox_t mbox = sg_mailbox_by_name(mailbox_name);
- XBT_INFO("Wait for my first message");
- while (1) {
- char* received = (char*)sg_mailbox_get(mbox);
- XBT_INFO("I got a '%s'.", received);
- if (!strcmp(received, "finalize")) { // If it's a finalize message, we're done
- xbt_free(received);
- break;
- }
- xbt_free(received);
- }
-}
-
-int main(int argc, char* argv[])
-{
- simgrid_init(&argc, argv);
- xbt_assert(argc > 2,
- "Usage: %s platform_file deployment_file\n"
- "\tExample: %s platform.xml deployment.xml\n",
- argv[0], argv[0]);
-
- simgrid_load_platform(argv[1]);
-
- simgrid_register_function("sender", sender);
- simgrid_register_function("receiver", receiver);
- simgrid_load_deployment(argv[2]);
-
- simgrid_run();
-
- return 0;
-}
+++ /dev/null
-#!/usr/bin/env tesh
-
-! output sort 19
-$ ${bindir:=.}/c-comm-waitall ${platfdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/comm-waitall_d.xml "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 0' to 'receiver-0'
-> [ 0.000000] (2:receiver@Ruby) Wait for my first message
-> [ 0.000000] (3:receiver@Perl) Wait for my first message
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 1' to 'receiver-1'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 2' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 3' to 'receiver-1'
-> [ 0.000000] (1:sender@Tremblay) Send 'Message 4' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'finalize' to 'receiver-0'
-> [ 0.000000] (1:sender@Tremblay) Send 'finalize' to 'receiver-1'
-> [ 0.000000] (1:sender@Tremblay) Done dispatching all messages
-> [ 0.004022] (2:receiver@Ruby) I got a 'Message 0'.
-> [ 0.004022] (3:receiver@Perl) I got a 'Message 1'.
-> [ 0.008043] (2:receiver@Ruby) I got a 'Message 2'.
-> [ 0.008043] (3:receiver@Perl) I got a 'Message 3'.
-> [ 0.009995] (3:receiver@Perl) I got a 'finalize'.
-> [ 0.012065] (2:receiver@Ruby) I got a 'Message 4'.
-> [ 0.014016] (2:receiver@Ruby) I got a 'finalize'.
-> [ 0.014016] (1:sender@Tremblay) Goodbye now!
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
-<platform version="4.1">
- <!-- The master actor (with some arguments) -->
- <actor host="Tremblay" function="sender">
- <argument value="5"/> <!-- Number of messages -->
- <argument value="1000000"/> <!-- Size of messages -->
- <argument value="2"/> <!-- Number of receivers -->
- </actor>
- <!-- The receiver actors -->
- <actor host="Ruby" function="receiver">
- <argument value="0"/>
- </actor>
- <actor host="Perl" function="receiver">
- <argument value="1"/>
- </actor>
-</platform>
XBT_PUBLIC int sg_comm_test(sg_comm_t comm);
XBT_PUBLIC sg_error_t sg_comm_wait(sg_comm_t comm);
XBT_PUBLIC sg_error_t sg_comm_wait_for(sg_comm_t comm, double timeout);
-XBT_PUBLIC void sg_comm_wait_all(sg_comm_t* comms, size_t count);
+XBT_PUBLIC void sg_comm_unref(sg_comm_t comm);
+
+XBT_ATTRIB_DEPRECATED_v339("Please use sg_activity_set_t instead") XBT_PUBLIC
+ void sg_comm_wait_all(sg_comm_t* comms, size_t count);
XBT_PUBLIC ssize_t sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout);
XBT_PUBLIC ssize_t sg_comm_wait_any(sg_comm_t* comms, size_t count);
-XBT_PUBLIC void sg_comm_unref(sg_comm_t comm);
SG_END_DECL