Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / c / comm-waitall / comm-waitall.c
index 1992205..c4a8173 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2022. 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. */
@@ -9,9 +9,9 @@
 #include "simgrid/host.h"
 #include "simgrid/mailbox.h"
 
-#include "xbt/asserts.h"
 #include "xbt/log.h"
 #include "xbt/str.h"
+#include "xbt/sysdep.h"
 
 #include <stdio.h> /* snprintf */
 
@@ -20,9 +20,10 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(comm_waitall, "Messages specific for this msg examp
 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: %s");
-  long message_size    = xbt_str_parse_int(argv[2], "Invalid message size: %s");
-  long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers: %s");
+  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));
@@ -38,9 +39,9 @@ static void sender(int argc, char* argv[])
   }
 
   /* Start dispatching all messages to receivers, in a round robin fashion */
-  for (int i = 0; i < messages_count; i++) {
+  for (long i = 0; i < messages_count; i++) {
     char msg_content[80];
-    snprintf(msg_content, 79, "Message %d", i);
+    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 */
@@ -48,8 +49,8 @@ static void sender(int argc, char* argv[])
   }
 
   /* 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);
+  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);
@@ -69,7 +70,7 @@ static void sender(int argc, char* argv[])
 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 = xbt_str_parse_int(argv[1], "ID should be numerical, not %s");
+  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);
@@ -90,7 +91,7 @@ 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",
+             "\tExample: %s platform.xml deployment.xml\n",
              argv[0], argv[0]);
 
   simgrid_load_platform(argv[1]);