#include "smpi_process.hpp"
#include "src/msg/msg_private.hpp"
#include "src/simix/smx_private.hpp"
#include "smpi_process.hpp"
#include "src/msg/msg_private.hpp"
#include "src/simix/smx_private.hpp"
using simgrid::s4u::Actor;
using simgrid::s4u::ActorPtr;
std::unordered_map<std::string, double> location2speedup;
using simgrid::s4u::Actor;
using simgrid::s4u::ActorPtr;
std::unordered_map<std::string, double> location2speedup;
MPI_Errhandler *MPI_ERRHANDLER_NULL = nullptr;
// No instance gets manually created; check also the smpirun.in script as
// this default name is used there as well (when the <actor> tag is generated).
MPI_Errhandler *MPI_ERRHANDLER_NULL = nullptr;
// No instance gets manually created; check also the smpirun.in script as
// this default name is used there as well (when the <actor> tag is generated).
static simgrid::config::Flag<double> smpi_wtime_sleep(
"smpi/wtime", "Minimum time to inject inside a call to MPI_Wtime", 0.0);
static simgrid::config::Flag<double> smpi_init_sleep(
static simgrid::config::Flag<double> smpi_wtime_sleep(
"smpi/wtime", "Minimum time to inject inside a call to MPI_Wtime", 0.0);
static simgrid::config::Flag<double> smpi_init_sleep(
ActorPtr me = Actor::self();
if (me == nullptr) // This happens sometimes (eg, when linking against NS3 because it pulls openMPI...)
return nullptr;
ActorPtr me = Actor::self();
if (me == nullptr) // This happens sometimes (eg, when linking against NS3 because it pulls openMPI...)
return nullptr;
auto private_blocks = merge_private_blocks(src_private_blocks, dst_private_blocks);
check_blocks(private_blocks, buff_size);
void* tmpbuff=buff;
auto private_blocks = merge_private_blocks(src_private_blocks, dst_private_blocks);
check_blocks(private_blocks, buff_size);
void* tmpbuff=buff;
(static_cast<char*>(buff) < smpi_data_exe_start + smpi_data_exe_size)) {
XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !");
(static_cast<char*>(buff) < smpi_data_exe_start + smpi_data_exe_size)) {
XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !");
tmpbuff = static_cast<void*>(xbt_malloc(buff_size));
memcpy_private(tmpbuff, buff, private_blocks);
}
tmpbuff = static_cast<void*>(xbt_malloc(buff_size));
memcpy_private(tmpbuff, buff, private_blocks);
}
((char*)comm->dst_buff < smpi_data_exe_start + smpi_data_exe_size)) {
XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment");
((char*)comm->dst_buff < smpi_data_exe_start + smpi_data_exe_size)) {
XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment");
}
XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff,comm->dst_buff);
memcpy_private(comm->dst_buff, tmpbuff, private_blocks);
}
XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff,comm->dst_buff);
memcpy_private(comm->dst_buff, tmpbuff, private_blocks);
- if (xbt_cfg_is_default_value("smpi/host-speed")) {
- XBT_INFO("You did not set the power of the host running the simulation. "
- "The timings will certainly not be accurate. "
- "Use the option \"--cfg=smpi/host-speed:<flops>\" to set its value."
- "Check http://simgrid.org/simgrid/latest/doc/options.html#options_smpi_bench for more information.");
- }
+ if (xbt_cfg_is_default_value("smpi/host-speed")) {
+ XBT_INFO("You did not set the power of the host running the simulation. "
+ "The timings will certainly not be accurate. "
+ "Use the option \"--cfg=smpi/host-speed:<flops>\" to set its value."
+ "Check http://simgrid.org/simgrid/latest/doc/options.html#options_smpi_bench for more information.");
+ }
- xbt_assert(xbt_cfg_get_double("smpi/cpu-threshold") >=0,
- "The 'smpi/cpu-threshold' option cannot have negative values [anymore]. If you want to discard "
- "the simulation of any computation, please use 'smpi/simulate-computation:no' instead.");
+ xbt_assert(xbt_cfg_get_double("smpi/cpu-threshold") >= 0,
+ "The 'smpi/cpu-threshold' option cannot have negative values [anymore]. If you want to discard "
+ "the simulation of any computation, please use 'smpi/simulate-computation:no' instead.");
simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
smpi_host_speed = xbt_cfg_get_double("smpi/host-speed");
simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
smpi_host_speed = xbt_cfg_get_double("smpi/host-speed");
std::string smpi_privatize_option = xbt_cfg_get_string("smpi/privatization");
if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
std::string smpi_privatize_option = xbt_cfg_get_string("smpi/privatization");
if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
- if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) {
- XBT_INFO("Mixing mmap privatization is broken on FreeBSD, switching to dlopen privatization instead.");
- smpi_privatize_global_variables = SMPI_PRIVATIZE_DLOPEN;
- }
+ if (smpi_privatize_global_variables == SmpiPrivStrategies::Mmap) {
+ XBT_INFO("mmap privatization is broken on FreeBSD, switching to dlopen privatization instead.");
+ smpi_privatize_global_variables = SmpiPrivStrategies::Dlopen;
+ }
int res = entry_point(argc, argv.get());
if (res != 0){
XBT_WARN("SMPI process did not return 0. Return value : %d", res);
int res = entry_point(argc, argv.get());
if (res != 0){
XBT_WARN("SMPI process did not return 0. Return value : %d", res);
+ "_" + std::to_string(rank++) + ".so";
int fdin = open(executable_copy.c_str(), O_RDONLY);
+ "_" + std::to_string(rank++) + ".so";
int fdin = open(executable_copy.c_str(), O_RDONLY);
- xbt_assert(fdin >= 0, "Cannot read from %s", executable_copy.c_str());
+ xbt_assert(fdin >= 0, "Cannot read from %s. Please make sure that the file exists and is executable.",
+ executable_copy.c_str());
int fdout = open(target_executable.c_str(), O_CREAT | O_RDWR, S_IRWXU);
xbt_assert(fdout >= 0, "Cannot write into %s", target_executable.c_str());
int fdout = open(target_executable.c_str(), O_CREAT | O_RDWR, S_IRWXU);
xbt_assert(fdout >= 0, "Cannot write into %s", target_executable.c_str());
#if HAVE_SENDFILE
ssize_t sent_size = sendfile(fdout, fdin, NULL, fdin_size);
xbt_assert(sent_size == fdin_size,
"Error while copying %s: only %zd bytes copied instead of %ld (errno: %d -- %s)",
target_executable.c_str(), sent_size, fdin_size, errno, strerror(errno));
#else
#if HAVE_SENDFILE
ssize_t sent_size = sendfile(fdout, fdin, NULL, fdin_size);
xbt_assert(sent_size == fdin_size,
"Error while copying %s: only %zd bytes copied instead of %ld (errno: %d -- %s)",
target_executable.c_str(), sent_size, fdin_size, errno, strerror(errno));
#else
const int bufsize = 1024 * 1024 * 4;
char buf[bufsize];
while (int got = read(fdin, buf, bufsize)) {
const int bufsize = 1024 * 1024 * 4;
char buf[bufsize];
while (int got = read(fdin, buf, bufsize)) {
// Load the copy and resolve the entry point:
void* handle = dlopen(target_executable.c_str(), RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
int saved_errno = errno;
// Load the copy and resolve the entry point:
void* handle = dlopen(target_executable.c_str(), RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
int saved_errno = errno;
unlink(target_executable.c_str());
if (handle == nullptr)
xbt_die("dlopen failed: %s (errno: %d -- %s)", dlerror(), saved_errno, strerror(saved_errno));
unlink(target_executable.c_str());
if (handle == nullptr)
xbt_die("dlopen failed: %s (errno: %d -- %s)", dlerror(), saved_errno, strerror(saved_errno));
if (handle == nullptr)
xbt_die("dlopen failed for %s: %s (errno: %d -- %s)", executable, 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);
if (handle == nullptr)
xbt_die("dlopen failed for %s: %s (errno: %d -- %s)", executable, 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);
// Execute the same entry point for each simulated process:
simix_global->default_function = [entry_point](std::vector<std::string> args) {
// Execute the same entry point for each simulated process:
simix_global->default_function = [entry_point](std::vector<std::string> args) {
process_data.size()); // This call has a side effect on process_count...
MPI_COMM_WORLD = *smpi_deployment_comm_world(smpi_default_instance_name);
smpi_universe_size = process_count;
process_data.size()); // This call has a side effect on process_count...
MPI_COMM_WORLD = *smpi_deployment_comm_world(smpi_default_instance_name);
smpi_universe_size = process_count;
double global_time = xbt_os_timer_elapsed(global_timer);
XBT_INFO("Simulated time: %g seconds. \n\n"
"The simulation took %g seconds (after parsing and platform setup)\n"
double global_time = xbt_os_timer_elapsed(global_timer);
XBT_INFO("Simulated time: %g seconds. \n\n"
"The simulation took %g seconds (after parsing and platform setup)\n"
- simgrid::s4u::Actor::onCreation.connect([](simgrid::s4u::ActorPtr actor) {
- if (not actor->isDaemon()) {
+ simgrid::s4u::Actor::on_creation.connect([](simgrid::s4u::ActorPtr actor) {
+ if (not actor->is_daemon()) {
- TRACE_smpi_alloc();
- simgrid::surf::surfExitCallbacks.connect(TRACE_smpi_release);
- if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP)
- smpi_backup_global_memory_segment();
+ simgrid::s4u::onSimulationEnd.connect(TRACE_smpi_release);