Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'operation-python' into 'master'
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 31 May 2023 12:30:47 +0000 (12:30 +0000)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 31 May 2023 12:30:47 +0000 (12:30 +0000)
add python bindings for operations

See merge request simgrid/simgrid!153

34 files changed:
.github/workflows/ci-batsim.yml
.github/workflows/ci-bigdft.yml
.github/workflows/ci-starpu.yml
.github/workflows/ci-wrench.yml
.github/workflows/docker-stable.yml
.github/workflows/docker.yml
.github/workflows/git.yml
ChangeLog
MANIFEST.in
docs/source/Plugins.rst
examples/cpp/CMakeLists.txt
examples/cpp/dag-comm/s4u-dag-comm.tesh
examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.cpp [new file with mode: 0644]
examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.tesh [new file with mode: 0644]
examples/cpp/trace-process-migration/s4u-trace-process-migration.tesh
examples/platforms/photovoltaic_platform.xml [new file with mode: 0644]
include/simgrid/kernel/resource/Action.hpp
include/simgrid/plugins/ProducerConsumer.hpp
include/simgrid/plugins/photovoltaic.hpp [new file with mode: 0644]
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
src/dag/loaders.cpp
src/instr/instr_platform.cpp
src/kernel/activity/CommImpl.cpp
src/kernel/resource/WifiLinkImpl.cpp
src/kernel/resource/WifiLinkImpl.hpp
src/plugins/host_energy.cpp
src/plugins/link_energy.cpp
src/plugins/link_energy_wifi.cpp
src/plugins/link_load.cpp
src/plugins/photovoltaic.cpp [new file with mode: 0644]
src/s4u/s4u_Comm.cpp
tools/address_sanitizer.supp
tools/cmake/DefinePackages.cmake

index 78ac347..f519b1e 100644 (file)
@@ -12,7 +12,7 @@ jobs:
     container: simgrid/unstable
 
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: Build and test BatSim
         run: |
           set -e
index 581e733..bb44643 100644 (file)
@@ -14,7 +14,7 @@ jobs:
       options: --user 0
 
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: Build and test BigDFT
         run: |
           set -e
index 6b63238..fbca937 100644 (file)
@@ -12,7 +12,7 @@ jobs:
     container: simgrid/unstable
 
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: Build and test StarPU
         run: |
           set -e
index 224b03e..1a580b4 100644 (file)
@@ -12,7 +12,7 @@ jobs:
     container: simgrid/unstable
 
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v3
       - name: Build and test WRENCH
         run: |
           set -e
index 68a4ec3..c0a0ea8 100644 (file)
@@ -24,7 +24,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       # Login against a Docker registry except on PR
       # https://github.com/docker/login-action
@@ -65,7 +65,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       # Login against a Docker registry except on PR
       # https://github.com/docker/login-action
@@ -104,7 +104,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       # Login against a Docker registry except on PR
       # https://github.com/docker/login-action
index 17f6084..5471cea 100644 (file)
@@ -20,7 +20,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       # Login against a Docker registry except on PR
       # https://github.com/docker/login-action
@@ -59,7 +59,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       # Login against a Docker registry except on PR
       # https://github.com/docker/login-action
index 3bb8225..6a907d5 100644 (file)
@@ -22,7 +22,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
       - name: Init options
         run: |
           echo "CC=${{ matrix.config.cc }}"   >> $GITHUB_ENV
@@ -68,7 +68,7 @@ jobs:
 
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
 
       - name: build
         run: |
index a90cc35..ba67d90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -38,6 +38,8 @@ New S4U plugins:
    See the examples under examples/cpp/operation-* and the documentation in the Plugins page.
  - Battery: Enable the management of batteries on hosts.
    See the examples under examples/cpp/battery-* and the documentation in the Plugins page.
+ - Photovoltaic: Enable the management of photovoltaic panels on hosts.
+   See the examples under examples/cpp/photovoltaic-* and the documentation in the Plugins page.
 
 Kernel:
  - optimize an internal datastructure (use a set instead of a list for ongoing activities),
index a43cae6..f4fe53a 100644 (file)
@@ -358,6 +358,8 @@ include examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp
 include examples/cpp/operation-switch-host/s4u-operation-switch-host.tesh
 include examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp
 include examples/cpp/operation-variable-load/s4u-operation-variable-load.tesh
+include examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.cpp
+include examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.tesh
 include examples/cpp/platform-comm-serialize/s4u-platform-comm-serialize.cpp
 include examples/cpp/platform-comm-serialize/s4u-platform-comm-serialize.tesh
 include examples/cpp/platform-failures/s4u-platform-failures.cpp
@@ -1842,6 +1844,7 @@ include examples/platforms/onelink.xml
 include examples/platforms/optorsim/gridpp_grid_2004.conf
 include examples/platforms/optorsim/lcg_sept2004_grid.conf
 include examples/platforms/optorsim/transform_optorsim_platform.pl
+include examples/platforms/photovoltaic_platform.xml
 include examples/platforms/profiles/fafard_state.profile
 include examples/platforms/profiles/faulty_host.profile
 include examples/platforms/profiles/ginette_state.profile
@@ -1942,6 +1945,7 @@ include include/simgrid/plugins/live_migration.h
 include include/simgrid/plugins/load.h
 include include/simgrid/plugins/ns3.hpp
 include include/simgrid/plugins/operation.hpp
+include include/simgrid/plugins/photovoltaic.hpp
 include include/simgrid/s4u.hpp
 include include/simgrid/s4u/Activity.hpp
 include include/simgrid/s4u/Actor.hpp
@@ -2300,6 +2304,7 @@ include src/plugins/link_energy.cpp
 include src/plugins/link_energy_wifi.cpp
 include src/plugins/link_load.cpp
 include src/plugins/operation.cpp
+include src/plugins/photovoltaic.cpp
 include src/plugins/vm/VmLiveMigration.cpp
 include src/plugins/vm/VmLiveMigration.hpp
 include src/plugins/vm/dirty_page_tracking.cpp
index bee80bc..a0a4f48 100644 (file)
@@ -134,20 +134,17 @@ Partial list of existing signals in s4u:
 
   - :cpp:func:`Comm::on_send <simgrid::s4u::Comm::on_send_cb>`
     :cpp:func:`Comm::on_recv <simgrid::s4u::Comm::on_recv_cb>`
+  - :cpp:func:`Comm::on_start <simgrid::s4u::Comm::on_start_cb>`
     :cpp:func:`Comm::on_completion <simgrid::s4u::Comm::on_completion_cb>`
     :cpp:func:`Comm::on_suspend <simgrid::s4u::Comm::on_suspend_cb>`
     :cpp:func:`Comm::on_resume <simgrid::s4u::Comm::on_resume_cb>`
     :cpp:func:`Comm::on_veto <simgrid::s4u::Comm::on_veto_cb>`
-  - :cpp:func:`CommImpl::on_start <simgrid::s4u::CommImpl::on_start_cb>`
-    :cpp:func:`CommImpl::on_completion <simgrid::s4u::CommImpl::on_completion_cb>`
   - :cpp:func:`Exec::on_start <simgrid::s4u::Exec::on_start_cb>`
-    :cpp:func:`Exec::on_completion <simgrid::s4u::Exec::on_completion_cb>`
     :cpp:func:`Exec::on_completion <simgrid::s4u::Exec::on_completion_cb>`
     :cpp:func:`Exec::on_suspend <simgrid::s4u::Exec::on_suspend_cb>`
     :cpp:func:`Exec::on_resume <simgrid::s4u::Exec::on_resume_cb>`
     :cpp:func:`Exec::on_veto <simgrid::s4u::Exec::on_veto_cb>`
   - :cpp:func:`Io::on_start <simgrid::s4u::Io::on_start_cb>`
-    :cpp:func:`Io::on_completion <simgrid::s4u::Io::on_completion_cb>`
     :cpp:func:`Io::on_completion <simgrid::s4u::Io::on_completion_cb>`
     :cpp:func:`Io::on_suspend <simgrid::s4u::Io::on_suspend_cb>`
     :cpp:func:`Io::on_resume <simgrid::s4u::Io::on_resume_cb>`
@@ -214,4 +211,11 @@ Operation
 
 .. doxygengroup:: plugin_operation
 
+.. _plugin_photovoltaic:
+
+Photovoltaic
+===========
+
+.. doxygengroup:: plugin_photovoltaic
+
 ..  LocalWords:  SimGrid
index 5e15581..10f6d58 100644 (file)
@@ -169,6 +169,7 @@ foreach (example activity-testany activity-waitany
                  network-ns3 network-ns3-wifi network-wifi
                  io-async io-priority io-degradation io-file-system io-file-remote io-disk-raw io-dependent
                  operation-io operation-simple operation-variable-load operation-switch-host
+                 photovoltaic-simple
                  platform-comm-serialize platform-failures platform-profile platform-properties
                  plugin-host-load plugin-link-load plugin-prodcons
                  replay-comm replay-io
index 0024dd2..abe40f4 100644 (file)
@@ -11,8 +11,8 @@ $ ${bindir:=.}/s4u-dag-comm ${platfdir}/two_hosts.xml --log=s4u_activity.t:verbo
 > [  1.000000] (0:maestro@) Exec 'parent' is complete (start time: 0.000000, finish time: 1.000000)
 > [  1.000000] (0:maestro@) Remove a dependency from 'parent' on 'transfer'
 > [  1.000000] (0:maestro@) 'transfer' is assigned to a resource and all dependencies are solved. Let's start
-> [  2.083775] (0:maestro@) Comm 'transfer' is complete
 > [  2.083775] (0:maestro@) Remove a dependency from 'transfer' on 'child'
 > [  2.083775] (0:maestro@) 'child' is assigned to a resource and all dependencies are solved. Let's start
+> [  2.083775] (0:maestro@) Comm 'transfer' is complete
 > [  3.083775] (0:maestro@) Exec 'child' is complete (start time: 2.083775, finish time: 3.083775)
 > [  3.083775] (0:maestro@) Simulation time 3.08378
diff --git a/examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.cpp b/examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.cpp
new file mode 100644 (file)
index 0000000..eb18645
--- /dev/null
@@ -0,0 +1,30 @@
+/* Copyright (c) 2003-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/plugins/photovoltaic.hpp"
+#include "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(photovoltaic_simple, "Messages specific for this s4u example");
+
+static void manager()
+{
+  auto pv_panel = simgrid::s4u::Engine::get_instance()->host_by_name("pv_panel");
+  std::vector<std::pair<double, double>> solar_irradiance = {{1, 10}, {100, 5}, {200, 20}};
+  for (auto [t, s] : solar_irradiance) {
+    simgrid::s4u::this_actor::sleep_until(t);
+    sg_photovoltaic_set_solar_irradiance(pv_panel, s);
+    XBT_INFO("%s power: %f", pv_panel->get_cname(), sg_photovoltaic_get_power(pv_panel));
+  }
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.load_platform(argv[1]);
+  sg_photovoltaic_plugin_init();
+  simgrid::s4u::Actor::create("manager", e.host_by_name("pv_panel"), manager);
+  e.run();
+  return 0;
+}
diff --git a/examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.tesh b/examples/cpp/photovoltaic-simple/s4u-photovoltaic-simple.tesh
new file mode 100644 (file)
index 0000000..1146cc8
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-photovoltaic-simple ${platfdir}/photovoltaic_platform.xml
+> [pv_panel:manager:(1) 1.000000] [photovoltaic_simple/INFO] pv_panel power: 8.000000
+> [pv_panel:manager:(1) 100.000000] [photovoltaic_simple/INFO] pv_panel power: 4.000000
+> [pv_panel:manager:(1) 200.000000] [photovoltaic_simple/INFO] pv_panel power: 16.000000
index 42fcd20..99d6865 100644 (file)
@@ -262,8 +262,8 @@ $ tail -n +3 procmig.trace
 > 13 2.000000 11 32
 > 12 2.000000 11 32 14
 > 13 2.025708 11 33
-> 12 2.025708 11 33 15
 > 13 2.025708 11 32
+> 12 2.025708 11 33 15
 > 15 2.025708 17 0 M 32 0
 > 7 2.025708 10 32
 > 6 2.025708 34 10 1 "emigrant-1"
@@ -272,8 +272,8 @@ $ tail -n +3 procmig.trace
 > 13 4.025708 11 34
 > 12 4.025708 11 34 14
 > 13 4.025903 11 33
-> 12 4.025903 11 33 15
 > 13 4.025903 11 34
+> 12 4.025903 11 33 15
 > 15 4.025903 17 0 M 34 1
 > 7 4.025903 10 34
 > 6 4.025903 35 10 2 "emigrant-1"
@@ -282,8 +282,8 @@ $ tail -n +3 procmig.trace
 > 13 6.025903 11 35
 > 12 6.025903 11 35 14
 > 13 6.044918 11 33
-> 12 6.044918 11 33 15
 > 13 6.044918 11 35
+> 12 6.044918 11 33 15
 > 15 6.044918 17 0 M 35 2
 > 7 6.044918 10 35
 > 6 6.044918 36 10 3 "emigrant-1"
@@ -292,8 +292,8 @@ $ tail -n +3 procmig.trace
 > 13 8.044918 11 36
 > 12 8.044918 11 36 14
 > 13 8.070626 11 33
-> 12 8.070626 11 33 15
 > 13 8.070626 11 36
+> 12 8.070626 11 33 15
 > 15 8.070626 17 0 M 36 3
 > 7 8.070626 10 36
 > 6 8.070626 37 10 4 "emigrant-1"
@@ -302,8 +302,8 @@ $ tail -n +3 procmig.trace
 > 13 10.070626 11 37
 > 12 10.070626 11 37 14
 > 13 10.087178 11 33
-> 12 10.087178 11 33 15
 > 13 10.087178 11 37
+> 12 10.087178 11 33 15
 > 15 10.087178 17 0 M 37 4
 > 7 10.087178 10 37
 > 6 10.087178 38 10 5 "emigrant-1"
@@ -312,8 +312,8 @@ $ tail -n +3 procmig.trace
 > 13 12.087178 11 38
 > 12 12.087178 11 38 14
 > 13 12.112617 11 33
-> 12 12.112617 11 33 15
 > 13 12.112617 11 38
+> 12 12.112617 11 33 15
 > 15 12.112617 17 0 M 38 5
 > 7 12.112617 10 38
 > 6 12.112617 39 10 3 "emigrant-1"
@@ -322,8 +322,8 @@ $ tail -n +3 procmig.trace
 > 13 14.112617 11 39
 > 12 14.112617 11 39 14
 > 13 14.138325 11 33
-> 12 14.138325 11 33 15
 > 13 14.138325 11 39
+> 12 14.138325 11 33 15
 > 15 14.138325 17 0 M 39 6
 > 7 14.138325 10 39
 > 6 14.138325 40 10 1 "emigrant-1"
@@ -332,8 +332,8 @@ $ tail -n +3 procmig.trace
 > 13 16.138325 11 40
 > 12 16.138325 11 40 14
 > 13 16.138521 11 33
-> 12 16.138521 11 33 15
 > 13 16.138521 11 40
+> 12 16.138521 11 33 15
 > 15 16.138521 17 0 M 40 7
 > 7 16.138521 10 40
 > 6 16.138521 41 10 4 "emigrant-1"
diff --git a/examples/platforms/photovoltaic_platform.xml b/examples/platforms/photovoltaic_platform.xml
new file mode 100644 (file)
index 0000000..8e499e1
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
+<platform version="4.1">
+  <zone id="world" routing="Floyd">
+    <host id="pv_panel" speed="0f">
+      <prop id="photovoltaic_area" value="4" />
+      <prop id="photovoltaic_conversion_efficiency" value="0.2" />
+    </host>
+  </zone>
+</platform>
index 9524e89..b75750e 100644 (file)
@@ -13,6 +13,7 @@
 #include <boost/heap/pairing_heap.hpp>
 #include <boost/optional.hpp>
 #include <string>
+#include <string_view>
 
 static constexpr double NO_MAX_DURATION = -1.0;
 
@@ -225,7 +226,7 @@ public:
   /** @brief Get the tracing category associated to the current action */
   const std::string& get_category() const { return category_; }
   /** @brief Set the tracing category of the current Action */
-  void set_category(const std::string& category) { category_ = category; }
+  void set_category(std::string_view category) { category_ = category; }
 
   /** @brief Get the sharing_penalty (RTT or 1/thread_count) of the current Action */
   double get_sharing_penalty() const { return sharing_penalty_; };
index 87d4cfa..d4438e4 100644 (file)
@@ -140,7 +140,7 @@ public:
    */
   s4u::CommPtr put_async(T* data, size_t simulated_size_in_bytes)
   {
-    std::unique_lock<s4u::Mutex> lock(*mutex_);
+    std::unique_lock lock(*mutex_);
     s4u::CommPtr comm = nullptr;
     XBT_CVERB(producer_consumer, (size() < max_queue_size_) ? "can put" : "must wait");
 
@@ -177,7 +177,7 @@ public:
    */
   s4u::CommPtr get_async(T** data)
   {
-    std::unique_lock<s4u::Mutex> lock(*mutex_);
+    std::unique_lock lock(*mutex_);
     s4u::CommPtr comm = nullptr;
     XBT_CVERB(producer_consumer, empty() ? "must wait" : "can get");
     while (empty())
diff --git a/include/simgrid/plugins/photovoltaic.hpp b/include/simgrid/plugins/photovoltaic.hpp
new file mode 100644 (file)
index 0000000..7cc1f3b
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef SIMGRID_PLUGINS_PHOTOVOLTAIC_H_
+#define SIMGRID_PLUGINS_PHOTOVOLTAIC_H_
+
+#include <simgrid/config.h>
+#include <simgrid/forward.h>
+#include <xbt/base.h>
+
+SG_BEGIN_DECL
+
+XBT_PUBLIC void sg_photovoltaic_plugin_init();
+
+XBT_PUBLIC void sg_photovoltaic_set_solar_irradiance(const_sg_host_t host, double s);
+
+XBT_PUBLIC double sg_photovoltaic_get_power(const_sg_host_t host);
+
+SG_END_DECL
+
+#endif
index 0dade94..fb157dd 100644 (file)
@@ -12,6 +12,7 @@
 #include <simgrid/forward.h>
 #include <stdexcept>
 #include <string>
+#include <string_view>
 #include <vector>
 #include <xbt/Extendable.hpp>
 #include <xbt/asserts.h>
@@ -74,8 +75,8 @@ protected:
   {
     if(this == a)
       throw std::invalid_argument("Cannot be its own successor");
-    auto p = std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i){ return i.get() == a.get(); });
-    if (p != successors_.end())
+
+    if (std::any_of(begin(successors_), end(successors_), [a](ActivityPtr const& i) { return i.get() == a.get(); }))
       throw std::invalid_argument("Dependency already exists");
 
     successors_.push_back(a);
@@ -87,12 +88,13 @@ protected:
     if(this == a)
       throw std::invalid_argument("Cannot ask to remove itself from successors list");
 
-    auto p = std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i){ return i.get() == a.get(); });
-    if (p != successors_.end()){
-      successors_.erase(p);
-      a->dependencies_.erase({this});
-    } else
+    auto p =
+        std::find_if(successors_.begin(), successors_.end(), [a](ActivityPtr const& i) { return i.get() == a.get(); });
+    if (p == successors_.end())
       throw std::invalid_argument("Dependency does not exist. Can not be removed.");
+
+    successors_.erase(p);
+    a->dependencies_.erase({this});
   }
 
   static std::set<Activity*>* vetoed_activities_;
@@ -262,7 +264,7 @@ public:
     Activity::remove_successor(a);
     return static_cast<AnyActivity*>(this);
   }
-  AnyActivity* set_name(const std::string& name)
+  AnyActivity* set_name(std::string_view name)
   {
     name_ = name;
     return static_cast<AnyActivity*>(this);
@@ -270,7 +272,7 @@ public:
   const std::string& get_name() const override { return name_; }
   const char* get_cname() const override { return name_.c_str(); }
 
-  AnyActivity* set_tracing_category(const std::string& category)
+  AnyActivity* set_tracing_category(std::string_view category)
   {
     xbt_assert(get_state() == State::INITED || get_state() == State::STARTING,
                "Cannot change the tracing category of an activity after its start");
index 1a3488c..2577c88 100644 (file)
@@ -19,6 +19,7 @@ namespace simgrid::s4u {
  */
 class XBT_PUBLIC Comm : public Activity_T<Comm> {
   friend Mailbox; // Factory of comms
+  friend kernel::activity::CommImpl;
   /* specified for normal mailbox-based communications*/
   Mailbox* mailbox_                   = nullptr;
   kernel::actor::ActorImpl* sender_   = nullptr;
@@ -38,12 +39,12 @@ class XBT_PUBLIC Comm : public Activity_T<Comm> {
   Comm() = default;
   Comm* do_start() override;
 
+protected:
   static xbt::signal<void(Comm const&)> on_send;
   static xbt::signal<void(Comm const&)> on_recv;
   static xbt::signal<void(Comm const&)> on_start;
 
-protected:
-  void fire_on_completion() const override { on_completion(*this); }
+  void fire_on_completion() const override { /* Do nothing */ }
   void fire_on_veto() const override { on_veto(const_cast<Comm&>(*this)); }
   void fire_on_suspend() const override { on_suspend(*this); }
   void fire_on_resume() const override { on_resume(*this); }
@@ -150,6 +151,7 @@ public:
 
   bool is_assigned() const override;
   Actor* get_sender() const;
+  Actor* get_receiver() const;
 
   /* Comm life cycle */
   /** Start the comm, and ignore its result. It can be completely forgotten after that. */
index f0d1826..218aa71 100644 (file)
 #include "dax_dtd.c"
 
 #if SIMGRID_HAVE_JSON
+// Disable implicit conversions. See https://github.com/nlohmann/json#implicit-conversions
+#ifdef JSON_USE_IMPLICIT_CONVERSIONS
+#undef JSON_USE_IMPLICIT_CONVERSIONS
+#endif
+#define JSON_USE_IMPLICIT_CONVERSIONS 0
 #include <nlohmann/json.hpp>
 #include <sstream>
 #endif
@@ -101,14 +106,19 @@ std::vector<ActivityPtr> create_DAG_from_json(const std::string& filename)
   
   for (auto const& task: data["workflow"]["tasks"]) {
     if (task["type"] == "compute") {
-      current = Exec::init()->set_name(task["name"])->set_flops_amount(task["runtime"]);
+      current =
+          Exec::init()->set_name(task["name"].get<std::string>())->set_flops_amount(task["runtime"].get<double>());
       if (task.contains("machine"))
-        dynamic_cast<Exec*>(current.get())->set_host(simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"]));
+        dynamic_cast<Exec*>(current.get())
+            ->set_host(simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"].get<std::string>()));
     }
     else if (task["type"] == "transfer"){
-      current = Comm::sendto_init()->set_name(task["name"])->set_payload_size(task["bytesWritten"]);
+      current = Comm::sendto_init()
+                    ->set_name(task["name"].get<std::string>())
+                    ->set_payload_size(task["bytesWritten"].get<double>());
       if (task.contains("machine"))
-        comms_destinations[current] = simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"]);
+        comms_destinations[current] =
+            simgrid::s4u::Engine::get_instance()->host_by_name(task["machine"].get<std::string>());
       if (task["parents"].size() == 1) {
         ActivityPtr parent_activity;
         for (auto const& activity: dag) {
@@ -130,7 +140,7 @@ std::vector<ActivityPtr> create_DAG_from_json(const std::string& filename)
 
     dag.push_back(current);
     for (auto const& parent : task["parents"])
-      successors[parent].push_back(current);
+      successors[parent.get<std::string>()].push_back(current);
   }
   // Assign successors
   for (auto const& [parent, successors_list] : successors)
index 540a8dd..5ea76ef 100644 (file)
@@ -517,12 +517,13 @@ void define_callbacks()
     });
 
     s4u::Comm::on_completion_cb([](const s4u::Comm& c) {
-      std::string pid = instr_pid(*s4u::Actor::self());
-      if (pid == "-0") { //Comm is launched directly by Maestro, use the host as container
-          Container::by_name(c.get_source()->get_name())->get_state("HOST_STATE")->pop_event();
-          Container::by_name(c.get_destination()->get_name())->get_state("HOST_STATE")->pop_event();
-      } else
-        Container::by_name(pid)->get_state("ACTOR_STATE")->pop_event();
+      if (c.get_sender()) {
+        Container::by_name(instr_pid(*c.get_sender()))->get_state("ACTOR_STATE")->pop_event();
+        Container::by_name(instr_pid(*c.get_receiver()))->get_state("ACTOR_STATE")->pop_event();
+      } else {
+        Container::by_name(c.get_source()->get_name())->get_state("HOST_STATE")->pop_event();
+        Container::by_name(c.get_destination()->get_name())->get_state("HOST_STATE")->pop_event();
+      }
     });
     s4u::Comm::on_send_cb([](s4u::Comm const& c) {
       std::string pid = instr_pid(*s4u::Actor::self());
index 44ec50b..7a9ef04 100644 (file)
@@ -133,7 +133,6 @@ CommImpl* CommImpl::start()
     model_action_->set_category(get_tracing_category());
     set_start_time(model_action_->get_start_time());
     set_state(State::RUNNING);
-    on_start(*this);
 
     XBT_DEBUG("Starting communication %p from '%s' to '%s' (model action: %p; state: %s)", this, from_->get_cname(),
               to_->get_cname(), model_action_, get_state_str());
@@ -471,7 +470,7 @@ void CommImpl::finish()
   XBT_DEBUG("CommImpl::finish() comm %p, state %s, src_proc %p, dst_proc %p, detached: %d", this, get_state_str(),
             src_actor_.get(), dst_actor_.get(), detached_);
 
-  on_completion(*this);
+  s4u::Comm::on_completion(static_cast<const s4u::Comm&>(*this->get_iface()));
 
   /* Update synchro state */
   if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FINISHED)
index 0d5ed17..b0abe21 100644 (file)
@@ -3,6 +3,7 @@
 /* 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/s4u/Comm.hpp>
 #include <simgrid/s4u/Host.hpp>
 
 #include "src/kernel/activity/CommImpl.hpp"
@@ -15,6 +16,21 @@ namespace simgrid::kernel::resource {
 /************
  * Resource *
  ************/
+static void update_bw_comm_start(const s4u::Comm& comm)
+{
+  auto* pimpl = static_cast<activity::CommImpl*>(comm.get_impl());
+
+  auto const* actionWifi = dynamic_cast<const kernel::resource::WifiLinkAction*>(pimpl->model_action_);
+  if (actionWifi == nullptr)
+    return;
+
+  if (auto* link_src = actionWifi->get_src_link()) {
+    link_src->inc_active_flux();
+  }
+  if (auto* link_dst = actionWifi->get_dst_link()) {
+    link_dst->inc_active_flux();
+  }
+}
 
 WifiLinkImpl::WifiLinkImpl(const std::string& name, const std::vector<double>& bandwidths, lmm::System* system)
     : StandardLinkImpl(name)
@@ -22,7 +38,7 @@ WifiLinkImpl::WifiLinkImpl(const std::string& name, const std::vector<double>& b
   this->set_constraint(system->constraint_new(this, 1));
   for (auto bandwidth : bandwidths)
     bandwidths_.push_back({bandwidth, 1.0, nullptr});
-  kernel::activity::CommImpl::on_start.connect(&update_bw_comm_start);
+  s4u::Comm::on_start_cb(&update_bw_comm_start);
   s4u::Link::on_communication_state_change_cb(&update_bw_comm_end);
 }
 
@@ -79,20 +95,6 @@ void WifiLinkImpl::dec_active_flux()
   nb_active_flux_--;
 }
 
-void WifiLinkImpl::update_bw_comm_start(const kernel::activity::CommImpl& comm)
-{
-  auto const* actionWifi = dynamic_cast<const simgrid::kernel::resource::WifiLinkAction*>(comm.model_action_);
-  if (actionWifi == nullptr)
-    return;
-
-  if (auto* link_src = actionWifi->get_src_link()) {
-    link_src->inc_active_flux();
-  }
-  if (auto* link_dst = actionWifi->get_dst_link()) {
-    link_dst->inc_active_flux();
-  }
-}
-
 void WifiLinkImpl::update_bw_comm_end(const simgrid::kernel::resource::NetworkAction& action,
                                       simgrid::kernel::resource::Action::State /*state*/)
 {
index cd08f6d..969eeeb 100644 (file)
@@ -53,9 +53,7 @@ public:
   void set_latency(double) override;
   bool toggle_callback();
 
-  static void update_bw_comm_start(const kernel::activity::CommImpl&);
-  static void update_bw_comm_end(const simgrid::kernel::resource::NetworkAction& action,
-                                 simgrid::kernel::resource::Action::State state);
+  static void update_bw_comm_end(const NetworkAction& action, Action::State state);
   void inc_active_flux();
   void dec_active_flux();
   static double wifi_link_dynamic_sharing(const WifiLinkImpl& link, double capacity, int n);
index 47bfda4..d2f5dc8 100644 (file)
@@ -514,6 +514,7 @@ void sg_host_energy_plugin_init()
       simgrid::s4u::Host* host = activity.get_host();
       if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host))
         host = vm->get_pm();
+      xbt_assert(host != nullptr);
       host->extension<HostEnergy>()->update();
     }
   });
index dd1e53b..66ab5d3 100644 (file)
@@ -6,6 +6,7 @@
 #include "simgrid/Exception.hpp"
 #include "simgrid/host.h"
 #include "simgrid/plugins/energy.h"
+#include "simgrid/s4u/Comm.hpp"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Link.hpp"
 #include "src/kernel/activity/CommImpl.hpp"
@@ -161,15 +162,17 @@ static void on_simulation_end()
   XBT_INFO("Total energy over all links: %f", total_energy);
 }
 
-static void on_communication(const simgrid::kernel::activity::CommImpl& comm)
+static void on_communication(const simgrid::s4u::Comm& comm)
 {
-  for (auto const* link : comm.get_traversed_links()) {
+  auto* pimpl = static_cast<simgrid::kernel::activity::CommImpl*>(comm.get_impl());
+  for (auto const* link : pimpl->get_traversed_links()) {
     if (link != nullptr && link->get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) {
       XBT_DEBUG("Update %s on Comm Start/End", link->get_cname());
       link->extension<LinkEnergy>()->update();
     }
   }
 }
+
 /* **************************** Public interface *************************** */
 
 int sg_link_energy_is_inited()
@@ -209,8 +212,8 @@ void sg_link_energy_plugin_init()
                link.extension<LinkEnergy>()->get_consumed_energy());
   });
 
-  simgrid::kernel::activity::CommImpl::on_start.connect(&on_communication);
-  simgrid::kernel::activity::CommImpl::on_completion.connect(&on_communication);
+  simgrid::s4u::Comm::on_start_cb(&on_communication);
+  simgrid::s4u::Comm::on_completion_cb(&on_communication);
 
   simgrid::s4u::Engine::on_simulation_end_cb(&on_simulation_end);
 }
index 0eb9cf0..3912fc9 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <simgrid/plugins/energy.h>
+#include <simgrid/s4u/Comm.hpp>
 #include <simgrid/s4u/Engine.hpp>
 #include <simgrid/s4u/Link.hpp>
 
@@ -265,9 +266,10 @@ void LinkEnergyWifi::init_watts_range_list()
 
 using simgrid::plugin::LinkEnergyWifi;
 /* **************************** events  callback *************************** */
-static void on_communication(const simgrid::kernel::activity::CommImpl& comm)
+static void on_communication(const simgrid::s4u::Comm& comm)
 {
-  for (const auto* link : comm.get_traversed_links()) {
+  auto* pimpl = static_cast<simgrid::kernel::activity::CommImpl*>(comm.get_impl());
+  for (auto const* link : pimpl->get_traversed_links()) {
     if (link != nullptr && link->get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) {
       auto* link_energy = link->extension<LinkEnergyWifi>();
       XBT_DEBUG("Update %s on Comm Start/End", link->get_cname());
@@ -324,6 +326,6 @@ void sg_wifi_energy_plugin_init()
     }
   });
 
-  simgrid::kernel::activity::CommImpl::on_start.connect(&on_communication);
-  simgrid::kernel::activity::CommImpl::on_completion.connect(&on_communication);
+  simgrid::s4u::Comm::on_start_cb(&on_communication);
+  simgrid::s4u::Comm::on_completion_cb(&on_communication);
 }
index d502cec..8f0937d 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <simgrid/plugins/load.h>
+#include <simgrid/s4u/Comm.hpp>
 #include <simgrid/s4u/Engine.hpp>
 
 #include "src/kernel/activity/CommImpl.hpp"
@@ -161,9 +162,10 @@ double LinkLoad::get_average_bytes()
 using simgrid::plugin::LinkLoad;
 
 /* **************************** events  callback *************************** */
-static void on_communication(const simgrid::kernel::activity::CommImpl& comm)
+static void on_communication(const simgrid::s4u::Comm& comm)
 {
-  for (const auto* link : comm.get_traversed_links()) {
+  auto* pimpl = static_cast<simgrid::kernel::activity::CommImpl*>(comm.get_impl());
+  for (auto const* link : pimpl->get_traversed_links()) {
     if (link != nullptr && link->get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) {
       auto* link_load = link->extension<LinkLoad>();
       XBT_DEBUG("Update %s on Comm Start/End", link->get_cname());
@@ -199,8 +201,8 @@ void sg_link_load_plugin_init()
   });
 
   // Call this plugin on some of the links' events.
-  simgrid::kernel::activity::CommImpl::on_start.connect(&on_communication);
-  simgrid::kernel::activity::CommImpl::on_completion.connect(&on_communication);
+  simgrid::s4u::Comm::on_start_cb(&on_communication);
+  simgrid::s4u::Comm::on_completion_cb(&on_communication);
 
   simgrid::s4u::Link::on_onoff_cb([](simgrid::s4u::Link const& link) {
     if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) {
diff --git a/src/plugins/photovoltaic.cpp b/src/plugins/photovoltaic.cpp
new file mode 100644 (file)
index 0000000..5131dd5
--- /dev/null
@@ -0,0 +1,287 @@
+#include <simgrid/Exception.hpp>
+#include <simgrid/plugins/photovoltaic.hpp>
+#include <simgrid/s4u/Actor.hpp>
+#include <simgrid/s4u/Engine.hpp>
+#include <simgrid/s4u/Host.hpp>
+#include <simgrid/s4u/VirtualMachine.hpp>
+#include <simgrid/simix.hpp>
+
+#include "src/kernel/resource/CpuImpl.hpp"
+#include "src/simgrid/module.hpp"
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+
+SIMGRID_REGISTER_PLUGIN(photovoltaic, "Photovoltaic management", &sg_photovoltaic_plugin_init)
+
+/** @defgroup plugin_photovoltaic plugin_photovoltaic Plugin photovoltaic
+
+  @beginrst
+
+This is the photovoltaic plugin, enabling management of photovoltaic panels on hosts.
+To activate this plugin, first call :cpp:func:`sg_photovoltaic_plugin_init()`.
+
+This plugin allows evaluation of photovoltaic panels power generation during simulation depending on size, solar
+irradiance and conversion factor.
+
+Photovoltaic Panel properties
+....................
+
+Properties of panels are defined as properties of hosts in the platform XML file.
+
+Here is an example of XML declaration where we consider a host as a photovoltaic panel:
+
+.. code-block:: xml
+
+   <host id="pv_panel" speed="0f">
+      <prop id="photovoltaic_area" value="4" />
+      <prop id="photovoltaic_conversion_efficiency" value="0.2" />
+    </host>
+
+The different properties are:
+
+- ``photovoltaic_area``: Set the area of the panel in m² (default=0)
+- ``photovoltaic_conversion_efficiency``: Set the conversion efficiency of the panel (default=0)
+- ``photovoltaic_solar_irradiance``: Set the initial solar irradiance in W/m² (default=0)
+- ``photovoltaic_min_power``: Set the minimum power of the panel in W (default=-1). Power generation below this value is automatically 0. Value is ignored if negative
+- ``photovoltaic_max_power``: Set the maximal power of the panel in W (default=-1). Power generation above this value is automatically truncated. Value is ignored if negative
+- ``photovoltaic_eval_cost``: Evaluate the cost of the panel during the simulation if set to 1 (defaulf=0)
+- ``photovoltaic_lifespan``: Set the lifespan of the panel in years (default=0)
+- ``photovoltaic_investment_cost``: Set the investment cost of the panel (default=0)
+- ``photovoltaic_maintenance_cost``: Set the maintenance cost of the panel (default=0)
+
+  @endrst
+ */
+
+/*These equations are taken from  the paper "Reinforcement Learning Based Load Balancing for
+Geographically Distributed Data Centres"  of Max Mackie et. al
+https://dro.dur.ac.uk/33395/1/33395.pdf?DDD280+kkgc95+vbdv77
+*/
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(photovoltaic, kernel, "Logging specific to the photovoltaic plugin");
+
+namespace simgrid::plugin {
+class Photovoltaic {
+private:
+  simgrid::s4u::Host* host_ = nullptr;
+
+  double area_m2_                   = 0;
+  double conversion_efficiency_     = 0;
+  double solar_irradiance_w_per_m2_ = 0;
+  double min_power_w_               = -1;
+  double max_power_w_               = -1;
+
+  double power_w_      = 0;
+  double last_updated_ = 0;
+
+  // Calculation of costs from Bei Li thesis (link :https://tel.archives-ouvertes.fr/tel-02077668/document) (chapter 4)
+  bool eval_cost_                 = false;
+  double cumulative_cost_         = 0;
+  int lifespan_years_             = 0;
+  double investment_cost_per_w_   = 0;
+  double maintenance_cost_per_wh_ = 0;
+
+  void init_photovoltaic_params();
+  void init_cost_params();
+  void update();
+
+  Photovoltaic* set_area(double a);
+  Photovoltaic* set_conversion_efficiency(double e);
+  Photovoltaic* set_min_power(double p);
+  Photovoltaic* set_max_power(double p);
+  Photovoltaic* set_eval_cost(bool eval);
+  Photovoltaic* set_lifespan(int l);
+  Photovoltaic* set_investment_cost(double c);
+  Photovoltaic* set_maintenance_cost(double c);
+
+public:
+  static simgrid::xbt::Extension<simgrid::s4u::Host, Photovoltaic> EXTENSION_ID;
+
+  explicit Photovoltaic(simgrid::s4u::Host* host);
+  ~Photovoltaic();
+
+  Photovoltaic* set_solar_irradiance(double s);
+
+  double get_power();
+};
+
+Photovoltaic* Photovoltaic::set_area(double a)
+{
+  xbt_assert(a > 0, " : area should be > 0 (provided: %f)", a);
+  simgrid::kernel::actor::simcall_answered([this, a] { area_m2_ = a; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_conversion_efficiency(double e)
+{
+  xbt_assert(e > 0 and e <= 1, " : conversion efficiency should be in [0,1] (provided: %f)", e);
+  simgrid::kernel::actor::simcall_answered([this, e] { conversion_efficiency_ = e; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_solar_irradiance(double s)
+{
+  xbt_assert(s > 0, " : solar irradiance should be > 0 (provided: %f)", s);
+  simgrid::kernel::actor::simcall_answered([this, s] { solar_irradiance_w_per_m2_ = s; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_min_power(double p)
+{
+  simgrid::kernel::actor::simcall_answered([this, p] { min_power_w_ = p; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_max_power(double p)
+{
+  simgrid::kernel::actor::simcall_answered([this, p] { max_power_w_ = p; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_eval_cost(bool e)
+{
+  simgrid::kernel::actor::simcall_answered([this, e] { eval_cost_ = e; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_lifespan(int l)
+{
+  xbt_assert(l > 0, " : lifespan should be > 0 (provided: %d)", l);
+  simgrid::kernel::actor::simcall_answered([this, l] { lifespan_years_ = l; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_investment_cost(double c)
+{
+  xbt_assert(c > 0, " : investment cost should be > 0 (provided: %f)", c);
+  simgrid::kernel::actor::simcall_answered([this, c] { investment_cost_per_w_ = c; });
+  return this;
+}
+
+Photovoltaic* Photovoltaic::set_maintenance_cost(double c)
+{
+  xbt_assert(c > 0, " : maintenance cost hould be > 0 (provided: %f)", c);
+  simgrid::kernel::actor::simcall_answered([this, c] { maintenance_cost_per_wh_ = c; });
+  return this;
+}
+
+double Photovoltaic::get_power()
+{
+  update();
+  return power_w_;
+}
+
+simgrid::xbt::Extension<simgrid::s4u::Host, Photovoltaic> Photovoltaic::EXTENSION_ID;
+
+void Photovoltaic::init_photovoltaic_params()
+{
+  const char* prop_chars;
+  prop_chars = host_->get_property("photovoltaic_area");
+  if (prop_chars)
+    set_area(xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_conversion_efficiency");
+  if (prop_chars)
+    set_conversion_efficiency(
+        xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_solar_irradiance");
+  if (prop_chars)
+    set_solar_irradiance(xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_min_power");
+  if (prop_chars)
+    set_min_power(xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_max_power");
+  if (prop_chars)
+    set_max_power(xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_eval_cost");
+  if (prop_chars)
+    set_eval_cost(xbt_str_parse_int(prop_chars, ("cannot parse int: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_lifespan");
+  if (prop_chars)
+    set_lifespan(xbt_str_parse_int(prop_chars, ("cannot parse int: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_investment_cost");
+  if (prop_chars)
+    set_investment_cost(xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  prop_chars = host_->get_property("photovoltaic_maintenance_cost");
+  if (prop_chars)
+    set_maintenance_cost(xbt_str_parse_double(prop_chars, ("cannot parse double: " + std::string(prop_chars)).c_str()));
+  simgrid::kernel::actor::simcall_answered([this] { last_updated_ = simgrid::s4u::Engine::get_clock(); });
+}
+
+void Photovoltaic::update()
+{
+  simgrid::kernel::actor::simcall_answered([this] {
+    double now = simgrid::s4u::Engine::get_clock();
+    if (now <= last_updated_)
+      return;
+    double power_w = conversion_efficiency_ * area_m2_ * solar_irradiance_w_per_m2_;
+    if (min_power_w_ > 0 and power_w_ < min_power_w_)
+      power_w = 0;
+    if (max_power_w_ > 0 and power_w_ > max_power_w_)
+      power_w = max_power_w_;
+    power_w_ = power_w;
+    if (eval_cost_) {
+      xbt_assert(max_power_w_ > 0, " : max power must be > 0 (provided: %f)", max_power_w_);
+      cumulative_cost_ += max_power_w_ * (now - last_updated_) *
+                          (investment_cost_per_w_ / (lifespan_years_ * 8760 * 3600) + maintenance_cost_per_wh_ / 3600);
+    }
+    last_updated_ = now;
+  });
+}
+
+Photovoltaic::Photovoltaic(simgrid::s4u::Host* host) : host_(host)
+{
+  init_photovoltaic_params();
+}
+
+Photovoltaic::~Photovoltaic() = default;
+} // namespace simgrid::plugin
+
+using simgrid::plugin::Photovoltaic;
+
+/* **************************** events  callback *************************** */
+
+static void on_creation(simgrid::s4u::Host& host)
+{
+  if (dynamic_cast<simgrid::s4u::VirtualMachine*>(&host)) // Ignore virtual machines
+    return;
+  host.extension_set(new Photovoltaic(&host));
+}
+
+/* **************************** Public interface *************************** */
+
+static void ensure_plugin_inited()
+{
+  if (not Photovoltaic::EXTENSION_ID.valid())
+    throw simgrid::xbt::InitializationError(
+        "The Photovoltaic plugin is not active. Please call sg_photovoltaic_plugin_init() "
+        "before calling any function related to that plugin.");
+}
+
+/** @ingroup plugin_photovoltaic
+ *  @brief Enable photovoltaic plugin.
+ */
+void sg_photovoltaic_plugin_init()
+{
+  if (Photovoltaic::EXTENSION_ID.valid())
+    return;
+  Photovoltaic::EXTENSION_ID = simgrid::s4u::Host::extension_create<Photovoltaic>();
+  simgrid::s4u::Host::on_creation_cb(&on_creation);
+}
+
+/** @ingroup plugin_photovoltaic
+ *  @param s The solar irradiance to set in W/m².
+ */
+void sg_photovoltaic_set_solar_irradiance(const_sg_host_t host, double s)
+{
+  ensure_plugin_inited();
+  host->extension<Photovoltaic>()->set_solar_irradiance(s);
+}
+
+/** @ingroup plugin_photovoltaic
+ *  @return Power generation in W.
+ */
+double sg_photovoltaic_get_power(const_sg_host_t host)
+{
+  ensure_plugin_inited();
+  return host->extension<Photovoltaic>()->get_power();
+}
\ No newline at end of file
index 408d1a3..376d18d 100644 (file)
@@ -21,6 +21,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm, s4u_activity, "S4U asynchronous commun
 namespace simgrid::s4u {
 xbt::signal<void(Comm const&)> Comm::on_send;
 xbt::signal<void(Comm const&)> Comm::on_recv;
+xbt::signal<void(Comm const&)> Comm::on_start;
 
 CommPtr Comm::set_copy_data_callback(const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback)
 {
@@ -289,6 +290,14 @@ Actor* Comm::get_sender() const
   return sender ? sender->get_ciface() : nullptr;
 }
 
+Actor* Comm::get_receiver() const
+{
+  kernel::actor::ActorImplPtr receiver = nullptr;
+  if (pimpl_)
+    receiver = boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->dst_actor_;
+  return receiver ? receiver->get_ciface() : nullptr;
+}
+
 bool Comm::is_assigned() const
 {
   return (pimpl_ && boost::static_pointer_cast<kernel::activity::CommImpl>(pimpl_)->is_assigned()) ||
@@ -348,6 +357,9 @@ Comm* Comm::do_start()
   if (not detached_) {
     pimpl_->set_iface(this);
     pimpl_->set_actor(sender_);
+    // Only throw the signal when both sides are here and the status is READY
+    if (pimpl_->get_state() != kernel::activity::State::WAITING)
+      on_start(*this);
   }
 
   state_ = State::STARTED;
index c8ae30b..1572d22 100644 (file)
@@ -26,5 +26,11 @@ odr_violation:^cfg_bmf_max_iteration$
 # size=40 'cfg_bmf_precision' ../src/kernel/lmm/bmf.hpp:80:47
 odr_violation:^cfg_bmf_precision$
 
-# size=56 'on_completion' ../include/simgrid/s4u/Activity.hpp:242:55
+# size=56 'on_completion' ../include/simgrid/s4u/Activity.hpp:235:55
 odr_violation:^on_completion$
+# size=56 'on_veto' ../include/simgrid/s4u/Activity.hpp:236:49
+odr_violation:^on_veto$
+# size=56 'on_suspend' ../include/simgrid/s4u/Activity.hpp:237:55
+odr_violation:^on_suspend$
+# size=56 'on_resume' ../include/simgrid/s4u/Activity.hpp:238:55
+odr_violation:^on_resume$
index c7e01f7..d6d2a5b 100644 (file)
@@ -455,6 +455,7 @@ set(PLUGINS_SRC
   src/plugins/vm/dirty_page_tracking.cpp
   src/plugins/battery.cpp
   src/plugins/operation.cpp
+  src/plugins/photovoltaic.cpp
   )
 
 
@@ -646,6 +647,7 @@ set(headers_to_install
   include/simgrid/plugins/live_migration.h
   include/simgrid/plugins/load.h
   include/simgrid/plugins/operation.hpp
+  include/simgrid/plugins/photovoltaic.hpp
   include/simgrid/plugins/ProducerConsumer.hpp
   include/simgrid/instr.h
   include/simgrid/mailbox.h
@@ -1123,6 +1125,7 @@ set(PLATFORMS_EXAMPLES
   examples/platforms/optorsim/gridpp_grid_2004.conf
   examples/platforms/optorsim/lcg_sept2004_grid.conf
   examples/platforms/optorsim/transform_optorsim_platform.pl
+  examples/platforms/photovoltaic_platform.xml
   examples/platforms/profiles/fafard_state.profile
   examples/platforms/profiles/faulty_host.profile
   examples/platforms/profiles/ginette_state.profile