Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'framagit/master'
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 22 Nov 2019 06:35:12 +0000 (07:35 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 22 Nov 2019 06:35:12 +0000 (07:35 +0100)
.mailmap
include/simgrid/Exception.hpp
include/smpi/smpi.h
src/plugins/host_energy.cpp
src/plugins/link_energy.cpp
src/smpi/internals/smpi_shared.cpp
src/surf/xml/platf.hpp
src/surf/xml/surfxml_sax_cb.cpp
src/xbt/exception.cpp
src/xbt/random_test.cpp
tools/cmake/MakeLib.cmake

index 3539f67..c166857 100644 (file)
--- a/.mailmap
+++ b/.mailmap
@@ -46,6 +46,7 @@ Jean-Emile Dartois <jean-emile.dartois@b-com.com>
 Jean-Emile Dartois <jean-emile.dartois@b-com.com> <jedartois@gmail.com>
 Darina Dimitrova <dimitrov@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
 Bruno Donassolo <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
+Yann Duplouy <yann.duplouy@inria.fr> <duplouy@crans.org>
 Pierre-François Dutot <dutot@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
 Julien Emmanuel <julien.emmanuel@atos.net>
 Lionel Eyraud-Dubois <lionel.eyraud-dubois@inria.fr>
index ad3498a..785a9f1 100644 (file)
@@ -64,6 +64,12 @@ public:
   ~ImpossibleError();
 };
 
+class XBT_PUBLIC InitializationError : public std::logic_error {
+public:
+  explicit InitializationError(const std::string& arg) : std::logic_error(arg) {}
+  ~InitializationError();
+};
+
 class XBT_PUBLIC UnimplementedError : public std::logic_error {
 public:
   explicit UnimplementedError(const std::string& arg) : std::logic_error(arg) {}
@@ -158,21 +164,13 @@ public:
   }
 };
 
-class XBT_PUBLIC ParseError : public Exception, public std::invalid_argument {
-  int line_;
-  std::string file_;
-  std::string msg_;
-  char* rendered_what = nullptr;
-
+/** Exception raised when something is going wrong during the parsing of XML files */
+class ParseError : public Exception {
 public:
-  ParseError(int line, std::string& file, std::string&& msg)
-      : Exception(XBT_THROW_POINT, std::move(msg)), std::invalid_argument(msg), line_(line), file_(file), msg_(msg)
+  ParseError(const std::string& file, int line, const std::string& msg)
+      : Exception(XBT_THROW_POINT, xbt::string_printf("Parse error at %s:%d: %s", file.c_str(), line, msg.c_str()))
   {
-    rendered_what = bprintf("Parse error at %s:%d: %s", file_.c_str(), line_, msg_.c_str());
   }
-  ~ParseError() { free(rendered_what); }
-
-  const char* what() const noexcept override { return rendered_what; }
 };
 
 class XBT_PUBLIC ForcefulKillException {
index 3407cc7..282452f 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <simgrid/forward.h>
 #include <smpi/forward.hpp>
+#include <smpi/smpi_helpers_internal.h>
 #include <xbt/function_types.h>
 
 #include <stddef.h>
index bd348e2..175c455 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/Exception.hpp"
 #include "simgrid/plugins/energy.h"
 #include "simgrid/s4u/Engine.hpp"
 #include "simgrid/s4u/Exec.hpp"
@@ -584,8 +585,8 @@ void sg_host_energy_update_all()
 static void ensure_plugin_inited()
 {
   if (not HostEnergy::EXTENSION_ID.valid())
-    throw std::logic_error("The Energy plugin is not active. Please call sg_host_energy_plugin_init() before calling "
-                           "any function related to that plugin.");
+    throw simgrid::xbt::InitializationError("The Energy plugin is not active. Please call sg_host_energy_plugin_init() "
+                                            "before calling any function related to that plugin.");
 }
 
 /** @ingroup plugin_host_energy
index b2b5e10..3a81581 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/Exception.hpp"
 #include "simgrid/plugins/energy.h"
 #include "simgrid/s4u/Engine.hpp"
 #include "src/surf/network_interface.hpp"
@@ -229,7 +230,7 @@ void sg_link_energy_plugin_init()
 double sg_link_get_consumed_energy(sg_link_t link)
 {
   if (not LinkEnergy::EXTENSION_ID.valid())
-    throw std::logic_error("The Energy plugin is not active. Please call sg_link_energy_plugin_init() before calling "
-                           "sg_link_get_consumed_energy().");
+    throw simgrid::xbt::InitializationError("The Energy plugin is not active. Please call sg_link_energy_plugin_init() "
+                                            "before calling sg_link_get_consumed_energy().");
   return link->extension<LinkEnergy>()->get_consumed_energy();
 }
index 2fb5a57..15fa823 100644 (file)
@@ -435,10 +435,7 @@ void smpi_shared_free(void *ptr)
     snprintf(loc, PTR_STRLEN, "%p", ptr);
     auto meta = allocs_metadata.find(ptr);
     if (meta == allocs_metadata.end()) {
-      if (simgrid::config::get_value<double>("smpi/auto_shared_malloc_thresh") > 0)//this free belongs to a malloc under the threshold.
-        ::operator delete(ptr);
-      else
-        XBT_WARN("Cannot free: %p was not shared-allocated by SMPI - maybe its size was 0?", ptr);
+      ::operator delete(ptr);
       return;
     }
     shared_data_t* data = &meta->second.data->second;
@@ -459,11 +456,17 @@ void smpi_shared_free(void *ptr)
     auto meta = allocs_metadata.find(ptr);
     if (meta != allocs_metadata.end()){
       meta->second.data->second.count--;
-      if(meta->second.data->second.count==0)
+      if(meta->second.data->second.count==0){
         delete meta->second.data;
+        allocs_metadata.erase(ptr);
+      }
+      XBT_DEBUG("Shared free - Global - of %p", ptr);
+      munmap(ptr, meta->second.size);
+    }else{
+      ::operator delete(ptr);
+      return;
     }
-    XBT_DEBUG("Shared free - Global - of %p", ptr);
-    munmap(ptr, meta->second.size);
+
   } else {
     XBT_DEBUG("Classic deallocation of %p", ptr);
     ::operator delete(ptr);
index d488e55..6c8b9d0 100644 (file)
@@ -16,11 +16,8 @@ XBT_PUBLIC void sg_platf_exit();
 
 XBT_PUBLIC void surf_parse_open(const std::string& file);
 XBT_PUBLIC void surf_parse_close();
-XBT_PUBLIC void surf_parse_assert(bool cond, std::string&& msg);
-SG_BEGIN_DECL
-XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(const char* msg);
-SG_END_DECL
-XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(std::string&& msg);
+XBT_PUBLIC void surf_parse_assert(bool cond, const std::string& msg);
+XBT_ATTRIB_NORETURN XBT_PUBLIC void surf_parse_error(const std::string& msg);
 XBT_PUBLIC void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre,
                                            const std::string& post);
 
index 0b49682..c73780d 100644 (file)
@@ -34,19 +34,15 @@ std::vector<simgrid::kernel::resource::DiskImpl*> parsed_disk_list; /* temporary
 /*
  * Helping functions
  */
-void surf_parse_assert(bool cond, std::string&& msg)
+void surf_parse_assert(bool cond, const std::string& msg)
 {
   if (not cond)
-    surf_parse_error(std::move(msg));
+    surf_parse_error(msg);
 }
 
-void surf_parse_error(const char* msg) {
-  throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::string(msg));
-}
-
-void surf_parse_error(std::string&& msg)
+void surf_parse_error(const std::string& msg)
 {
-  throw simgrid::ParseError(surf_parse_lineno, surf_parsed_filename, std::move(msg));
+  throw simgrid::ParseError(surf_parsed_filename, surf_parse_lineno, msg);
 }
 
 void surf_parse_assert_netpoint(const std::string& hostname, const std::string& pre, const std::string& post)
index 7e4366a..2d0748a 100644 (file)
@@ -27,8 +27,9 @@ void _xbt_throw(char* message, int value, const char* file, int line, const char
 namespace simgrid {
 namespace xbt {
 
-ImpossibleError::~ImpossibleError()       = default;
-UnimplementedError::~UnimplementedError() = default;
+ImpossibleError::~ImpossibleError()         = default;
+InitializationError::~InitializationError() = default;
+UnimplementedError::~UnimplementedError()   = default;
 
 void log_exception(e_xbt_log_priority_t prio, const char* context, std::exception const& exception)
 {
index d8cee22..c35943e 100644 (file)
@@ -7,17 +7,19 @@
 #include "xbt/log.h"
 #include "xbt/random.hpp"
 #include <random>
+#include <cmath>
+
+#define EPSILON (100*std::numeric_limits<double>::epsilon())
 
 TEST_CASE("xbt::random: Random Number Generation")
 {
   SECTION("Using XBT_RNG_xbt")
   {
     simgrid::xbt::random::set_mersenne_seed(12345);
-
-    REQUIRE(simgrid::xbt::random::exponential(25) == 0.00291934351538427348);
+    REQUIRE(simgrid::xbt::random::exponential(25) == Approx(0.00291934351538427348).epsilon(EPSILON));
     REQUIRE(simgrid::xbt::random::uniform_int(1, 6) == 4);
-    REQUIRE(simgrid::xbt::random::uniform_real(0, 1) == 0.31637556043369124970);
-    REQUIRE(simgrid::xbt::random::normal(0, 2) == 1.62746784745133976635);
+    REQUIRE(simgrid::xbt::random::uniform_real(0, 1) == Approx(0.31637556043369124970).epsilon(EPSILON));
+    REQUIRE(simgrid::xbt::random::normal(0, 2) == Approx(1.62746784745133976635).epsilon(EPSILON));
   }
 
   SECTION("Using XBT_RNG_std")
@@ -33,9 +35,9 @@ TEST_CASE("xbt::random: Random Number Generation")
     std::uniform_real_distribution<> distC(0, 1);
     std::normal_distribution<> distD(0, 2);
 
-    REQUIRE(simgrid::xbt::random::exponential(25) == distA(gen));
+    REQUIRE(simgrid::xbt::random::exponential(25) == Approx(distA(gen)).epsilon(EPSILON));
     REQUIRE(simgrid::xbt::random::uniform_int(1, 6) == distB(gen));
-    REQUIRE(simgrid::xbt::random::uniform_real(0, 1) == distC(gen));
-    REQUIRE(simgrid::xbt::random::normal(0, 2) == distD(gen));
+    REQUIRE(simgrid::xbt::random::uniform_real(0, 1) == Approx(distC(gen)).epsilon(EPSILON));
+    REQUIRE(simgrid::xbt::random::normal(0, 2) == Approx(distD(gen)).epsilon(EPSILON));
   }
 }
index 480b934..3ddbb8e 100644 (file)
@@ -60,7 +60,7 @@ if (HAVE_BOOST_ADDR2LINE_BACKTRACE)
 endif()
 
 if(CMAKE_USE_PTHREADS_INIT)
-  set(SIMGRID_DEP "${SIMGRID_DEP} ${CMAKE_THREAD_LIBS_INIT}")
+  target_link_libraries(simgrid ${CMAKE_THREAD_LIBS_INIT})
 endif()
 
 if(SIMGRID_HAVE_LUA)