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>
~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) {}
}
};
-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 {
#include <simgrid/forward.h>
#include <smpi/forward.hpp>
+#include <smpi/smpi_helpers_internal.h>
#include <xbt/function_types.h>
#include <stddef.h>
/* 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"
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
/* 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"
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();
}
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;
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);
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);
/*
* 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)
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)
{
#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")
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));
}
}
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)