Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate sg_comm_wait_all in C
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 25 Jul 2023 15:47:12 +0000 (17:47 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 25 Jul 2023 15:48:11 +0000 (17:48 +0200)
MANIFEST.in
examples/c/CMakeLists.txt
examples/c/app-chainsend/broadcaster.c
examples/c/app-chainsend/chainsend.h
examples/c/app-chainsend/peer.c
examples/c/comm-waitall/comm-waitall.c [deleted file]
examples/c/comm-waitall/comm-waitall.tesh [deleted file]
examples/c/comm-waitall/comm-waitall_d.xml [deleted file]
include/simgrid/comm.h

index 5a99b93..0814d5f 100644 (file)
@@ -73,9 +73,6 @@ include examples/c/comm-wait/comm-wait2_d.xml
 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
index 13349f7..86e764c 100644 (file)
@@ -6,7 +6,7 @@ foreach(x
         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
@@ -86,7 +86,6 @@ set(xml_files     ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/actor-cr
                                ${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
@@ -99,7 +98,7 @@ foreach(x
         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
index 3e71581..7133408 100644 (file)
@@ -36,16 +36,14 @@ static void broadcaster_build_chain(broadcaster_t bc)
 
 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)
@@ -56,7 +54,7 @@ static broadcaster_t broadcaster_init(sg_mailbox_t* mailboxes, unsigned int host
   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);
 
@@ -65,7 +63,7 @@ static broadcaster_t broadcaster_init(sg_mailbox_t* mailboxes, unsigned int host
 
 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);
 }
index 8bbe961..86a86aa 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef CHAINSEND_H
 #define CHAINSEND_H
 
+#include "simgrid/activity_set.h"
 #include "simgrid/actor.h"
 #include "simgrid/comm.h"
 #include "simgrid/engine.h"
@@ -30,7 +31,7 @@ typedef struct s_broadcaster {
   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;
@@ -54,8 +55,8 @@ typedef struct s_peer {
   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;
index 513c123..f4591f8 100644 (file)
@@ -1,5 +1,4 @@
-/* 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. */
@@ -22,26 +21,21 @@ static void peer_join_chain(peer_t p)
 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);
 
@@ -53,7 +47,7 @@ static void peer_forward_file(peer_t p)
       }
     }
   }
-  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[])
@@ -63,8 +57,8 @@ 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());
 
@@ -73,8 +67,8 @@ static peer_t peer_init(int argc, char* argv[])
 
 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);
 }
diff --git a/examples/c/comm-waitall/comm-waitall.c b/examples/c/comm-waitall/comm-waitall.c
deleted file mode 100644 (file)
index 4477c68..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/* 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;
-}
diff --git a/examples/c/comm-waitall/comm-waitall.tesh b/examples/c/comm-waitall/comm-waitall.tesh
deleted file mode 100644 (file)
index 1c3cfe6..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/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!
diff --git a/examples/c/comm-waitall/comm-waitall_d.xml b/examples/c/comm-waitall/comm-waitall_d.xml
deleted file mode 100644 (file)
index 8f9d88b..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?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>
index 8490a27..55769e7 100644 (file)
@@ -18,10 +18,12 @@ XBT_PUBLIC void sg_comm_detach(sg_comm_t comm, void (*clean_function)(void*));
 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