From 9e4c9f802f80a611c7b9c3bccbd0a14a138e2ef2 Mon Sep 17 00:00:00 2001
From: Millian Poquet <millian.poquet@irit.fr>
Date: Sun, 13 Nov 2022 18:05:30 +0100
Subject: [PATCH] update simgrid simulator

---
 simgrid-simulator/meson.build          |  6 +++++-
 simgrid-simulator/src/compute.cpp      |  6 ++++++
 simgrid-simulator/src/compute.hpp      |  3 +++
 simgrid-simulator/src/orchestrator.cpp | 25 +++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 simgrid-simulator/src/compute.cpp
 create mode 100644 simgrid-simulator/src/compute.hpp

diff --git a/simgrid-simulator/meson.build b/simgrid-simulator/meson.build
index 451f2db..6de2734 100644
--- a/simgrid-simulator/meson.build
+++ b/simgrid-simulator/meson.build
@@ -15,7 +15,11 @@ deps = [
   protocol_dep
 ]
 
-simulator = executable('simulator', ['src/main.cpp', 'src/orchestrator.cpp', 'src/orchestrator.hpp'],
+simulator = executable('simulator', [
+    'src/main.cpp',
+    'src/orchestrator.cpp', 'src/orchestrator.hpp',
+    'src/compute.cpp', 'src/compute.hpp'
+  ],
   include_directories: 'src',
   dependencies: deps,
   install: true
diff --git a/simgrid-simulator/src/compute.cpp b/simgrid-simulator/src/compute.cpp
new file mode 100644
index 0000000..49f3463
--- /dev/null
+++ b/simgrid-simulator/src/compute.cpp
@@ -0,0 +1,6 @@
+#include <simgrid/s4u.hpp>
+
+float desired_flops_to_simulated_flops(float flops)
+{
+    return flops * 1.0f;
+}
diff --git a/simgrid-simulator/src/compute.hpp b/simgrid-simulator/src/compute.hpp
new file mode 100644
index 0000000..a10f160
--- /dev/null
+++ b/simgrid-simulator/src/compute.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+float desired_flops_to_simulated_flops(float flops);
diff --git a/simgrid-simulator/src/orchestrator.cpp b/simgrid-simulator/src/orchestrator.cpp
index 703fe93..ca453e5 100644
--- a/simgrid-simulator/src/orchestrator.cpp
+++ b/simgrid-simulator/src/orchestrator.cpp
@@ -3,6 +3,8 @@
 
 #include <protocol/hello.pb.h>
 
+#include "compute.hpp"
+
 XBT_LOG_NEW_DEFAULT_CATEGORY(orchestrator, "The logging channel used by this module");
 
 const char * orchestrator_name(void)
@@ -41,6 +43,29 @@ void orchestrator(void)
         zmq_msg_init(&msg);
         if (zmq_msg_recv(&msg, socket, 0) == -1)
             throw std::runtime_error(std::string("cannot read message on socket (errno=") + strerror(errno) + ")");
+
+        hello::Order order;
+        if (order.ParseFromArray(zmq_msg_data(&msg), zmq_msg_size(&msg)) != true)
+            throw std::runtime_error("cannot parse received message as an Order");
+
+        switch (order.order_case())
+        {
+        case hello::Order::kHello:
+            XBT_INFO("received hello from %s", order.hello().name().c_str());
+            break;
+        case hello::Order::kBye:
+            XBT_INFO("received bye");
+            bye_received = true;
+            break;
+        case hello::Order::kComputeFlops: {
+            float desired_flops = order.compute_flops().flop_amount();
+            float actual_flops = desired_flops_to_simulated_flops(desired_flops);
+            XBT_INFO("computing %g flops", actual_flops);
+            simgrid::s4u::this_actor::execute(actual_flops);
+        } break;
+        default:
+            throw std::runtime_error("unhandled order case received");
+        }
     }
 
     zmq_close(socket);
-- 
GitLab