Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert a msg test to C-s4u (borken for now)
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 3 Feb 2020 15:09:30 +0000 (16:09 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 3 Feb 2020 15:21:08 +0000 (16:21 +0100)
MANIFEST.in
teshsuite/c/CMakeLists.txt [new file with mode: 0644]
teshsuite/c/async-waitany/async-waitany.c [new file with mode: 0644]
teshsuite/c/async-waitany/async-waitany.tesh [new file with mode: 0644]
teshsuite/c/async-waitany/async-waitany_d.xml [new file with mode: 0644]
teshsuite/msg/CMakeLists.txt
tools/cmake/DefinePackages.cmake

index c31b506..8be325c 100644 (file)
@@ -561,6 +561,8 @@ include examples/smpi/trace_call_location/trace_call_location.c
 include examples/smpi/trace_call_location/trace_call_location.tesh
 include examples/smpi/trace_simple/trace_simple.c
 include examples/smpi/trace_simple/trace_simple.tesh
+include teshsuite/c/async-waitany/async-waitany.c
+include teshsuite/c/async-waitany/async-waitany_d.xml
 include teshsuite/java/semaphoregc/SemaphoreGC.java
 include teshsuite/java/semaphoregc/semaphoregc.tesh
 include teshsuite/java/sleephostoff/SleepHostOff.java
@@ -616,9 +618,6 @@ include teshsuite/msg/async-wait/async-wait_d.xml
 include teshsuite/msg/async-waitall/async-waitall.c
 include teshsuite/msg/async-waitall/async-waitall.tesh
 include teshsuite/msg/async-waitall/async-waitall_d.xml
-include teshsuite/msg/async-waitany/async-waitany.c
-include teshsuite/msg/async-waitany/async-waitany.tesh
-include teshsuite/msg/async-waitany/async-waitany_d.xml
 include teshsuite/msg/cloud-capping/cloud-capping.c
 include teshsuite/msg/cloud-capping/cloud-capping.tesh
 include teshsuite/msg/cloud-migration/cloud-migration.c
@@ -1962,6 +1961,7 @@ include include/simgrid/Exception.hpp
 include include/simgrid/actor.h
 include include/simgrid/barrier.h
 include include/simgrid/chrono.hpp
+include include/simgrid/comm.h
 include include/simgrid/cond.h
 include include/simgrid/config.h.in
 include include/simgrid/engine.h
@@ -2660,6 +2660,7 @@ include src/xbt/xbt_str.cpp
 include src/xbt/xbt_str_test.cpp
 include src/xbt/xbt_virtu.cpp
 include src/xbt_modinter.h
+include teshsuite/c/CMakeLists.txt
 include teshsuite/java/CMakeLists.txt
 include teshsuite/lua/CMakeLists.txt
 include teshsuite/lua/lua_platforms.tesh
diff --git a/teshsuite/c/CMakeLists.txt b/teshsuite/c/CMakeLists.txt
new file mode 100644 (file)
index 0000000..cf5815f
--- /dev/null
@@ -0,0 +1,20 @@
+foreach(x async-waitany)
+  add_executable       (${x} EXCLUDE_FROM_ALL ${x}/${x}.c)
+  target_link_libraries(${x} simgrid)
+  set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
+  add_dependencies(tests ${x})
+
+  set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
+  set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.c)
+endforeach()
+
+set(teshsuite_src ${teshsuite_src}  PARENT_SCOPE)
+set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml    PARENT_SCOPE)
+
+foreach(x async-waitany)
+  ADD_TESH_FACTORIES(tesh-msg-${x} "raw" 
+                                   --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
+                                   --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/c/${x}
+                                   --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x} 
+                                   ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x}/${x}.tesh)
+endforeach()
diff --git a/teshsuite/c/async-waitany/async-waitany.c b/teshsuite/c/async-waitany/async-waitany.c
new file mode 100644 (file)
index 0000000..04ac7e4
--- /dev/null
@@ -0,0 +1,122 @@
+/* Copyright (c) 2010-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(async_waitany, "Messages specific for this example");
+
+static int sender(int argc, char* argv[])
+{
+  xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc);
+  long messages_count  = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  long msg_size        = xbt_str_parse_int(argv[2], "Invalid communication size: %s");
+  long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers: %s");
+
+  /* Dynar in which we store all ongoing communications */
+  xbt_dynar_t pending_comms = xbt_dynar_new(sizeof(sg_comm_t), NULL);
+  ;
+
+  /* Make a dynar of the mailboxes to use */
+  xbt_dynar_t mboxes = xbt_dynar_new(sizeof(sg_mailbox_t), NULL);
+  for (long i = 0; i < receivers_count; i++) {
+    char mailbox_name[80];
+    snprintf(mailbox_name, 79, "receiver-%ld", (i));
+    xbt_dynar_push_as(mboxes, sg_mailbox_t, sg_mailbox_by_name(mailbox_name));
+  }
+
+  /* Start dispatching all messages to receivers, in a round robin fashion */
+  for (int i = 0; i < messages_count; i++) {
+    char msg_content[80];
+    snprintf(msg_content, 79, "Message_%d", i);
+    sg_mailbox_t mbox = (sg_mailbox_t)xbt_dynar_get_ptr(mboxes, i % receivers_count);
+
+    XBT_INFO("Send '%s' to '%s'", msg_content, sg_mailbox_get_name(mbox));
+
+    sg_comm_t comm = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), msg_size);
+    xbt_dynar_push_as(pending_comms, sg_comm_t, comm);
+  }
+  /* Start sending messages to let the workers know that they should stop */
+  for (int i = 0; i < receivers_count; i++) {
+    XBT_INFO("Send 'finalize' to 'receiver-%d'", i);
+    char* end_msg  = xbt_strdup("finalize");
+    sg_comm_t comm = sg_mailbox_put_async((sg_mailbox_t)xbt_dynar_get_ptr(mboxes, i % receivers_count), end_msg, 0);
+    xbt_dynar_push_as(pending_comms, sg_comm_t, comm);
+    xbt_free(end_msg);
+  }
+
+  XBT_INFO("Done dispatching all messages");
+
+  /* Now that all message exchanges were initiated, wait for their completion, in order of termination.
+   *
+   * This loop waits for first terminating message with wait_any() and remove it with erase(), until all comms are
+   * terminated
+   * Even in this simple example, the pending comms do not terminate in the exact same order of creation.
+   */
+  while (!xbt_dynar_is_empty(pending_comms)) {
+    int changed_pos = sg_comm_wait_any_for(pending_comms, -1);
+    xbt_dynar_remove_at(pending_comms, changed_pos, NULL);
+    if (changed_pos != 0)
+      XBT_INFO("Remove the %dth pending comm: it terminated earlier than another comm that was initiated first.",
+               changed_pos);
+  }
+
+  xbt_dynar_free(&pending_comms);
+  xbt_dynar_free(&mboxes);
+
+  XBT_INFO("Goodbye now!");
+  return 0;
+}
+
+static int receiver(int argc, char* argv[])
+{
+  xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc);
+  int id = xbt_str_parse_int(argv[1], "ID should be numerical, not %s");
+  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 on '%s'", mailbox_name);
+  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);
+  }
+
+  XBT_INFO("I'm done. See you!");
+  return 0;
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid_init(&argc, argv);
+  xbt_assert(argc > 2,
+             "Usage: %s platform_file deployment_file\n"
+             "\tExample: %s msg_platform.xml msg_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();
+
+  XBT_INFO("Simulation time %g", simgrid_get_clock());
+
+  return 0;
+}
diff --git a/teshsuite/c/async-waitany/async-waitany.tesh b/teshsuite/c/async-waitany/async-waitany.tesh
new file mode 100644 (file)
index 0000000..4027e42
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env tesh
+
+p Testing the MSG_comm_waitany function
+
+! output sort 19
+$ ${bindir:=.}/async-waitany ${platfdir:=.}/small_platform.xml ${srcdir:=.}/async-waitany_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:sender@Tremblay) Send to receiver-0 Task_0 comm_size 1000000.000000
+> [  0.000000] (1:sender@Tremblay) Send to receiver-1 Task_1 comm_size 1000000.000000
+> [  0.000000] (1:sender@Tremblay) Send to receiver-0 Task_2 comm_size 1000000.000000
+> [  0.000000] (1:sender@Tremblay) Send to receiver-1 Task_3 comm_size 1000000.000000
+> [  0.000000] (1:sender@Tremblay) Send to receiver-0 Task_4 comm_size 1000000.000000
+> [  0.000000] (1:sender@Tremblay) Send to receiver-1 Task_5 comm_size 1000000.000000
+> [ 10.000000] (2:receiver@Fafard) Wait to receive task 0
+> [ 10.000000] (2:receiver@Fafard) Wait to receive task 1
+> [ 10.000000] (2:receiver@Fafard) Wait to receive task 2
+> [ 10.000000] (3:receiver@Jupiter) Wait to receive task 0
+> [ 10.000000] (3:receiver@Jupiter) Wait to receive task 1
+> [ 10.000000] (3:receiver@Jupiter) Wait to receive task 2
+> [ 10.423774] (2:receiver@Fafard) Processing "Task_4"
+> [ 10.469435] (3:receiver@Jupiter) Processing "Task_5"
+> [ 11.079116] (2:receiver@Fafard) "Task_4" done
+> [ 11.079116] (2:receiver@Fafard) Processing "Task_0"
+> [ 11.124778] (3:receiver@Jupiter) "Task_5" done
+> [ 11.124778] (3:receiver@Jupiter) Processing "Task_1"
+> [ 11.734459] (2:receiver@Fafard) "Task_0" done
+> [ 11.734459] (2:receiver@Fafard) Processing "Task_2"
+> [ 11.780120] (3:receiver@Jupiter) "Task_1" done
+> [ 11.780120] (3:receiver@Jupiter) Processing "Task_3"
+> [ 12.389801] (2:receiver@Fafard) "Task_2" done
+> [ 12.415509] (2:receiver@Fafard) I'm done. See you!
+> [ 12.435462] (3:receiver@Jupiter) "Task_3" done
+> [ 12.454477] (0:maestro@) Simulation time 12.4545
+> [ 12.454477] (1:sender@Tremblay) Goodbye now!
+> [ 12.454477] (3:receiver@Jupiter) I'm done. See you!
diff --git a/teshsuite/c/async-waitany/async-waitany_d.xml b/teshsuite/c/async-waitany/async-waitany_d.xml
new file mode 100644 (file)
index 0000000..03c240a
--- /dev/null
@@ -0,0 +1,17 @@
+<?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="6"/>       <!-- Number of tasks -->
+    <argument value="1000000"/>      <!-- Communication size of tasks -->
+    <argument value="2"/>         <!-- Number of receivers -->
+  </actor>
+  <!-- The receiver processes -->
+  <actor host="Fafard" function="receiver">
+    <argument value="0"/>
+  </actor>
+  <actor host="Jupiter" function="receiver">
+    <argument value="1"/>
+  </actor>
+</platform>
index 827914f..f42e401 100644 (file)
@@ -1,6 +1,6 @@
 # C examples
 foreach(x app-pingpong app-token-ring
-          async-wait async-waitall async-waitany
+          async-wait async-waitall
           cloud-capping cloud-migration cloud-two-tasks cloud-simple
           get_sender host_on_off host_on_off_recv
           process-daemon process-kill process-join process-lifetime process-migration process-suspend process-yield
@@ -67,7 +67,6 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/ap
                                    ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/async-wait3_d.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/async-wait4_d.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/async-waitall_d.xml
-                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/io-file-remote/io-file-remote_d.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/platform-properties/platform-properties_d.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/process-lifetime/baseline_d.xml
@@ -91,7 +90,7 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/ap
 
 if(enable_msg)
   foreach(x 
-    async-wait async-waitall async-waitany
+    async-wait async-waitall
     app-bittorrent app-chainsend app-pingpong app-token-ring
     cloud-capping cloud-migration cloud-two-tasks cloud-simple
     energy-pstate
index c88566a..0a1c3b4 100644 (file)
@@ -1015,6 +1015,7 @@ set(CMAKEFILES_TXT
   examples/deprecated/msg/mc/CMakeLists.txt
   examples/deprecated/simdag/CMakeLists.txt
 
+  teshsuite/c/CMakeLists.txt
   teshsuite/java/CMakeLists.txt
   teshsuite/lua/CMakeLists.txt
   teshsuite/mc/CMakeLists.txt