#include <cfloat> /* DBL_MAX */
#include <dlfcn.h>
#include <fcntl.h>
+#include <fstream>
+
#if not defined(__APPLE__)
#include <link.h>
#endif
-#include <fstream>
+
+#if defined(__APPLE__)
+# include <AvailabilityMacros.h>
+# ifndef MAC_OS_X_VERSION_10_12
+# define MAC_OS_X_VERSION_10_12 101200
+# endif
+# define HAVE_WORKING_MMAP (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
+#elif defined(__FreeBSD__)
+# define HAVE_WORKING_MMAP 0
+#else
+# define HAVE_WORKING_MMAP 1
+#endif
#if HAVE_SENDFILE
#include <sys/sendfile.h>
#if HAVE_PAPI
#include "papi.h"
-const char* papi_default_config_name = "default";
-
-struct papi_process_data {
- papi_counter_t counter_data;
- int event_set;
-};
+std::string papi_default_config_name = "default";
+std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
#endif
using simgrid::s4u::Actor;
ActorPtr me = Actor::self();
if (me == nullptr) // This happens sometimes (eg, when linking against NS3 because it pulls openMPI...)
return nullptr;
- simgrid::msg::ActorExt* msgExt = static_cast<simgrid::msg::ActorExt*>(me->get_impl()->getUserData());
+ simgrid::msg::ActorExt* msgExt = static_cast<simgrid::msg::ActorExt*>(me->get_impl()->get_user_data());
return static_cast<simgrid::smpi::Process*>(msgExt->data);
}
// This map holds for each computation unit (such as "default" or "process1" etc.)
// the configuration as given by the user (counter data as a pair of (counter_name, counter_counter))
// and the (computed) event_set.
- std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
if (not simgrid::config::get_value<std::string>("smpi/papi-events").empty()) {
if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
XBT_ERROR("Could not initialize PAPI library; is it correctly installed and linked?"
- " Expected version is %i",
- PAPI_VER_CURRENT);
+ " Expected version is %u", PAPI_VER_CURRENT);
typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
boost::char_separator<char> separator_units(";");
simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
smpi_cpu_threshold = simgrid::config::get_value<double>("smpi/cpu-threshold");
smpi_host_speed = simgrid::config::get_value<double>("smpi/host-speed");
- xbt_assert(smpi_host_speed >= 0, "You're trying to set the host_speed to a negative value (%f)", smpi_host_speed);
+ xbt_assert(smpi_host_speed > 0.0, "You're trying to set the host_speed to a non-positive value (given: %f)", smpi_host_speed);
std::string smpi_privatize_option = simgrid::config::get_value<std::string>("smpi/privatization");
if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
smpi_privatize_global_variables = SmpiPrivStrategies::NONE;
XBT_DEBUG("Running without smpi_main(); disable smpi/privatization.");
smpi_privatize_global_variables = SmpiPrivStrategies::NONE;
}
-#if defined(__FreeBSD__)
+#if !HAVE_WORKING_MMAP
if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) {
- XBT_INFO("mmap privatization is broken on FreeBSD, switching to dlopen privatization instead.");
+ XBT_INFO("mmap privatization is broken on this platform, switching to dlopen privatization instead.");
smpi_privatize_global_variables = SmpiPrivStrategies::DLOPEN;
}
#endif
}
#endif
-static void smpi_init_privatization_dlopen(const char* executable)
+static void smpi_init_privatization_dlopen(std::string executable)
{
- std::string executable_copy = executable;
-
// Prepare the copy of the binary (get its size)
struct stat fdin_stat;
- stat(executable_copy.c_str(), &fdin_stat);
+ stat(executable.c_str(), &fdin_stat);
off_t fdin_size = fdin_stat.st_size;
static std::size_t rank = 0;
}
}
- simix_global->default_function = [executable_copy, fdin_size](std::vector<std::string> args) {
- return std::function<void()>([executable_copy, fdin_size, args] {
+ simix_global->default_function = [executable, fdin_size](std::vector<std::string> args) {
+ return std::function<void()>([executable, fdin_size, args] {
// Copy the dynamic library:
std::string target_executable =
- executable_copy + "_" + std::to_string(getpid()) + "_" + std::to_string(rank) + ".so";
+ executable + "_" + std::to_string(getpid()) + "_" + std::to_string(rank) + ".so";
- smpi_copy_file(executable_copy, target_executable, fdin_size);
+ smpi_copy_file(executable, target_executable, fdin_size);
// if smpi/privatize-libs is set, duplicate pointed lib and link each executable copy to a different one.
std::string target_lib;
for (auto const& libpath : privatize_libs_paths) {
};
}
-static void smpi_init_privatization_no_dlopen(const char* executable)
+static void smpi_init_privatization_no_dlopen(std::string executable)
{
if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP)
smpi_prepare_global_memory_segment();
// Load the dynamic library and resolve the entry point:
- void* handle = dlopen(executable, RTLD_LAZY | RTLD_LOCAL);
+ void* handle = dlopen(executable.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (handle == nullptr)
- xbt_die("dlopen failed for %s: %s (errno: %d -- %s)", executable, dlerror(), errno, strerror(errno));
+ xbt_die("dlopen failed for %s: %s (errno: %d -- %s)", executable.c_str(), dlerror(), errno, strerror(errno));
smpi_entry_point_type entry_point = smpi_resolve_function(handle);
if (not entry_point)
- xbt_die("main not found in %s", executable);
+ xbt_die("main not found in %s", executable.c_str());
if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP)
smpi_backup_global_memory_segment();
TRACE_global_init();
SIMIX_global_init(&argc, argv);
- MSG_init(&argc, argv);
+ MSG_init(&argc, argv); // FIXME Remove this MSG call. Once it's removed, we can remove the msg header include as well
SMPI_switch_data_segment = &smpi_switch_data_segment;