From 165f0d8397015d910184a9869d045037af0b2edc Mon Sep 17 00:00:00 2001 From: degomme Date: Tue, 11 Apr 2017 15:22:41 +0200 Subject: [PATCH 1/1] Yet another dlopen merge --- CMakeLists.txt | 2 + include/smpi/smpi.h | 5 +- src/mc/Process.cpp | 6 +- src/mc/Session.cpp | 3 +- src/mc/remote/Client.cpp | 2 +- src/simgrid/sg_config.cpp | 7 +- src/simix/ActorImpl.cpp | 4 +- src/simix/smx_global.cpp | 2 +- src/smpi/private.h | 8 +- src/smpi/smpi_bench.cpp | 2 +- src/smpi/smpi_comm.cpp | 8 +- src/smpi/smpi_datatype.cpp | 2 +- src/smpi/smpi_global.cpp | 197 +++++++++++++++++++++++++++++-------- src/smpi/smpi_memory.cpp | 2 +- src/smpi/smpi_process.cpp | 4 +- src/smpi/smpi_request.cpp | 4 +- src/smpi/smpicc.in | 5 +- src/smpi/smpicxx.in | 5 +- src/smpi/smpif90.in | 4 +- src/smpi/smpiff.in | 4 +- src/smpi/smpirun.in | 8 +- tools/cmake/Distrib.cmake | 1 + tools/cmake/MakeLib.cmake | 9 ++ 23 files changed, 216 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 382a88e2e1..ab63f19171 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -690,6 +690,7 @@ if(NS3_LIBRARY_PATH) set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}") endif() set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"") +set(SMPIMAIN smpimain) configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/mpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/mpif.h @ONLY) foreach(script cc cxx ff f90 run) @@ -707,6 +708,7 @@ if(NS3_LIBRARY_PATH) set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}") endif() set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"") +set(SMPIMAIN ${CMAKE_BINARY_DIR}/bin/smpimain) foreach(script cc cxx ff f90 run) configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpi${script}.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpi${script} @ONLY) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 502c6ae6f8..2d8e740c1e 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -912,10 +912,7 @@ XBT_PUBLIC(void*) smpi_shared_set_call(const char* func, const char* input, void /* Fortran specific stuff */ -XBT_PUBLIC(int) __attribute__((weak)) smpi_simulated_main_(int argc, char** argv); -XBT_PUBLIC(int) __attribute__((weak)) MAIN__(); -XBT_PUBLIC(int) smpi_main(int (*realmain) (int argc, char *argv[]),int argc, char *argv[]); -XBT_PUBLIC(void) __attribute__((weak)) user_main_(); +XBT_PUBLIC(int) smpi_main(const char* program, int argc, char *argv[]); XBT_PUBLIC(int) smpi_process_index(); XBT_PUBLIC(void) smpi_process_init(int *argc, char ***argv); diff --git a/src/mc/Process.cpp b/src/mc/Process.cpp index 7ffd7b3f99..5b1f3c9314 100644 --- a/src/mc/Process.cpp +++ b/src/mc/Process.cpp @@ -248,8 +248,10 @@ Process::~Process() close(this->memory_file); if (this->unw_underlying_addr_space != unw_local_addr_space) { - unw_destroy_addr_space(this->unw_underlying_addr_space); - _UPT_destroy(this->unw_underlying_context); + if (this->unw_underlying_addr_space) + unw_destroy_addr_space(this->unw_underlying_addr_space); + if (this->unw_underlying_context) + _UPT_destroy(this->unw_underlying_context); } unw_destroy_addr_space(this->unw_addr_space); diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index f08f806a6c..8195c5c24b 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -85,8 +85,7 @@ Session::Session(pid_t pid, int socket) { std::unique_ptr process(new simgrid::mc::Process(pid, socket)); // TODO, automatic detection of the config from the process - process->privatized( - xbt_cfg_get_boolean("smpi/privatize-global-variables")); + process->privatized(smpi_privatize_global_variables != SMPI_PRIVATIZE_NONE); modelChecker_ = std::unique_ptr( new simgrid::mc::ModelChecker(std::move(process))); xbt_assert(mc_model_checker == nullptr); diff --git a/src/mc/remote/Client.cpp b/src/mc/remote/Client.cpp index 7cc5127094..9759c215e6 100644 --- a/src/mc/remote/Client.cpp +++ b/src/mc/remote/Client.cpp @@ -232,7 +232,7 @@ void Client::declareStack(void* stack, size_t size, smx_actor_t process, ucontex region.size = size; region.block = ((char*)stack - (char*)heap->heapbase) / BLOCKSIZE + 1; #if HAVE_SMPI - if (smpi_privatize_global_variables && process) + if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP && process) region.process_index = smpi_process_index_of_smx_process(process); else #endif diff --git a/src/simgrid/sg_config.cpp b/src/simgrid/sg_config.cpp index dd0df36f20..a5eba59bdf 100644 --- a/src/simgrid/sg_config.cpp +++ b/src/simgrid/sg_config.cpp @@ -499,7 +499,12 @@ void sg_config_init(int *argc, char **argv) xbt_cfg_register_alias("smpi/send-is-detached-thresh","smpi/send_is_detached_thresh"); xbt_cfg_register_alias("smpi/send-is-detached-thresh","smpi/send_is_detached_thres"); - xbt_cfg_register_boolean("smpi/privatize-global-variables", "no", nullptr, "Whether we should privatize global variable at runtime."); + const char* default_privatization = std::getenv("SMPI_PRIVATIZATION"); + if (default_privatization == nullptr) + default_privatization = "no"; + + xbt_cfg_register_string("smpi/privatize-global-variables", default_privatization, nullptr, "Whether we should privatize global variable at runtime (no, yes, mmap, dlopen)."); + xbt_cfg_register_alias("smpi/privatize-global-variables", "smpi/privatize_global_variables"); xbt_cfg_register_boolean("smpi/grow-injected-times", "yes", nullptr, "Whether we want to make the injected time in MPI_Iprobe and MPI_Test grow, to allow faster simulation. This can make simulation less precise, though."); diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 9e256c9b72..43944d041a 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -262,7 +262,7 @@ smx_actor_t SIMIX_process_create(const char* name, std::function code, v process->ppid = parent_process->pid; /* SMPI process have their own data segment and each other inherit from their father */ #if HAVE_SMPI - if (smpi_privatize_global_variables) { + if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) { if (parent_process->pid != 0) { SIMIX_segment_index_set(process, parent_process->segment_index); } else { @@ -327,7 +327,7 @@ smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostn process->ppid = parent_process->pid; /* SMPI process have their own data segment and each other inherit from their father */ #if HAVE_SMPI - if (smpi_privatize_global_variables) { + if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) { if (parent_process->pid != 0) { SIMIX_segment_index_set(process, parent_process->segment_index); } else { diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 787d58f460..341c3e3573 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -94,7 +94,7 @@ static void segvhandler(int signum, siginfo_t *siginfo, void *context) } else if (siginfo->si_signo == SIGSEGV) { fprintf(stderr, "Segmentation fault.\n"); #if HAVE_SMPI - if (smpi_enabled() && !smpi_privatize_global_variables) { + if (smpi_enabled() && smpi_privatize_global_variables == SMPI_PRIVATIZE_NONE) { #if HAVE_PRIVATIZATION fprintf(stderr, "Try to enable SMPI variable privatization with --cfg=smpi/privatize-global-variables:yes.\n"); #else diff --git a/src/smpi/private.h b/src/smpi/private.h index 2fed1121fe..a01bc88bce 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -95,7 +95,13 @@ XBT_PRIVATE void smpi_mpi_init(); // utilities extern XBT_PRIVATE double smpi_cpu_threshold; extern XBT_PRIVATE double smpi_host_speed; -extern XBT_PRIVATE bool smpi_privatize_global_variables; + +#define SMPI_PRIVATIZE_NONE 0 +#define SMPI_PRIVATIZE_MMAP 1 +#define SMPI_PRIVATIZE_DLOPEN 2 +#define SMPI_PRIVATIZE_DEFAULT SMPI_PRIVATIZE_MMAP +extern XBT_PRIVATE int smpi_privatize_global_variables; + extern XBT_PRIVATE char* smpi_start_data_exe; //start of the data+bss segment of the executable extern XBT_PRIVATE int smpi_size_data_exe; //size of the data+bss segment of the executable diff --git a/src/smpi/smpi_bench.cpp b/src/smpi/smpi_bench.cpp index b8d2d4b73f..b925281d80 100644 --- a/src/smpi/smpi_bench.cpp +++ b/src/smpi/smpi_bench.cpp @@ -91,7 +91,7 @@ void smpi_execute(double duration) void smpi_bench_begin() { - if (smpi_privatize_global_variables) { + if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) { smpi_switch_data_segment(smpi_process()->index()); } diff --git a/src/smpi/smpi_comm.cpp b/src/smpi/smpi_comm.cpp index d4941e40a1..9bb515e123 100644 --- a/src/smpi/smpi_comm.cpp +++ b/src/smpi/smpi_comm.cpp @@ -73,7 +73,7 @@ void Comm::destroy(Comm* comm) } int Comm::dup(MPI_Comm* newcomm){ - if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables smpi_switch_data_segment(smpi_process()->index()); } MPI_Group cp = new Group(this->group()); @@ -328,7 +328,7 @@ void Comm::init_smp(){ smpi_process()->set_replaying(false); } - if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables smpi_switch_data_segment(smpi_process()->index()); } //identify neighbours in comm @@ -370,7 +370,7 @@ void Comm::init_smp(){ Coll_allgather_mpich::allgather(&leader, 1, MPI_INT , leaders_map, 1, MPI_INT, this); - if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables smpi_switch_data_segment(smpi_process()->index()); } @@ -444,7 +444,7 @@ void Comm::init_smp(){ } Coll_bcast_mpich::bcast(&(is_uniform_),1, MPI_INT, 0, comm_intra ); - if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables smpi_switch_data_segment(smpi_process()->index()); } // Are the ranks blocked ? = allocated contiguously on the SMP nodes diff --git a/src/smpi/smpi_datatype.cpp b/src/smpi/smpi_datatype.cpp index 52ca497300..4ce49854c2 100644 --- a/src/smpi/smpi_datatype.cpp +++ b/src/smpi/smpi_datatype.cpp @@ -277,7 +277,7 @@ int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, XBT_DEBUG("Copy output buf %p is shared. Let's ignore it.", recvbuf); } - if(smpi_privatize_global_variables){ + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ smpi_switch_data_segment(smpi_process()->index()); } /* First check if we really have something to do */ diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index 9ce3361fcb..7d5fa45b96 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -3,6 +3,11 @@ /* 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 +#include +#include +#include + #include "mc/mc.h" #include "private.h" #include "private.hpp" @@ -24,12 +29,25 @@ #include #include #include +#include #include +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_kernel, smpi, "Logging specific to SMPI (kernel)"); #include #include /* trim_right / trim_left */ +#ifndef RTLD_DEEPBIND +/* RTLD_DEEPBIND is a bad idea of GNU ld that obviously does not exist on other platforms + * See https://www.akkadia.org/drepper/dsohowto.pdf + * and https://lists.freebsd.org/pipermail/freebsd-current/2016-March/060284.html +*/ +#define RTLD_DEEPBIND 0 +#endif + +/* Mac OSX does not have any header file providing that definition so we have to duplicate it here. Bummers. */ +extern char** environ; /* we use it in posix_spawnp below */ + #if HAVE_PAPI #include "papi.h" const char* papi_default_config_name = "default"; @@ -115,7 +133,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b XBT_DEBUG("Receiver %p is shared. Let's ignore it.", (char*)comm->dst_buff); }else{ void* tmpbuff=buff; - if((smpi_privatize_global_variables) && (static_cast(buff) >= smpi_start_data_exe) + if((smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) && (static_cast(buff) >= smpi_start_data_exe) && (static_cast(buff) < smpi_start_data_exe + smpi_size_data_exe ) ){ XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !"); @@ -126,7 +144,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b memcpy(tmpbuff, buff, buff_size); } - if((smpi_privatize_global_variables) && ((char*)comm->dst_buff >= smpi_start_data_exe) + if((smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) && ((char*)comm->dst_buff >= smpi_start_data_exe) && ((char*)comm->dst_buff < smpi_start_data_exe + smpi_size_data_exe )){ XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment"); smpi_switch_data_segment( @@ -341,43 +359,13 @@ void smpi_global_destroy() } xbt_free(index_to_process_data); - if(smpi_privatize_global_variables) + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) smpi_destroy_global_memory_segments(); smpi_free_static(); } extern "C" { -#ifndef WIN32 - -void __attribute__ ((weak)) user_main_() -{ - xbt_die("Should not be in this smpi_simulated_main"); -} - -int __attribute__ ((weak)) smpi_simulated_main_(int argc, char **argv) -{ - simgrid::smpi::Process::init(&argc, &argv); - user_main_(); - return 0; -} - -inline static int smpi_main_wrapper(int argc, char **argv){ - int ret = smpi_simulated_main_(argc,argv); - if(ret !=0){ - XBT_WARN("SMPI process did not return 0. Return value : %d", ret); - smpi_process()->set_return_value(ret); - } - return 0; -} - -int __attribute__ ((weak)) main(int argc, char **argv) -{ - return smpi_main(smpi_main_wrapper, argc, argv); -} - -#endif - static void smpi_init_logs(){ /* Connect log categories. See xbt/log.c */ @@ -411,7 +399,26 @@ static void smpi_init_options(){ 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"); - smpi_privatize_global_variables = xbt_cfg_get_boolean("smpi/privatize-global-variables"); + const char* smpi_privatize_option = xbt_cfg_get_string("smpi/privatize-global-variables"); + if (std::strcmp(smpi_privatize_option, "no") == 0) + smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE; + else if (std::strcmp(smpi_privatize_option, "yes") == 0) + smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT; + else if (std::strcmp(smpi_privatize_option, "mmap") == 0) + smpi_privatize_global_variables = SMPI_PRIVATIZE_MMAP; + else if (std::strcmp(smpi_privatize_option, "dlopen") == 0) + smpi_privatize_global_variables = SMPI_PRIVATIZE_DLOPEN; + + // Some compatibility stuff: + else if (std::strcmp(smpi_privatize_option, "1") == 0) + smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT; + else if (std::strcmp(smpi_privatize_option, "0") == 0) + smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE; + + else + xbt_die("Invalid value for smpi/privatize-global-variables: %s", + smpi_privatize_option); + if (smpi_cpu_threshold < 0) smpi_cpu_threshold = DBL_MAX; @@ -428,7 +435,61 @@ static void smpi_init_options(){ } } -int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[]) +static int execute_command(const char * const argv[]) +{ + pid_t pid; + int status; + if (posix_spawnp(&pid, argv[0], nullptr, nullptr, (char* const*) argv, environ) != 0) + return 127; + if (waitpid(pid, &status, 0) != pid) + return 127; + return status; +} + +typedef std::function smpi_entry_point_type; +typedef int (* smpi_c_entry_point_type)(int argc, char **argv); +typedef void (* smpi_fortran_entry_point_type)(void); + +static int smpi_run_entry_point(smpi_entry_point_type entry_point, std::vector args) +{ + const int argc = args.size(); + std::unique_ptr argv(new char*[argc + 1]); + for (int i = 0; i != argc; ++i) + argv[i] = args[i].empty() ? const_cast(""): &args[i].front(); + argv[argc] = nullptr; + + int res = entry_point(argc, argv.get()); + if (res != 0){ + XBT_WARN("SMPI process did not return 0. Return value : %d", res); + smpi_process()->set_return_value(res); + } + return 0; +} + +// TODO, remove the number of functions involved here +static smpi_entry_point_type smpi_resolve_function(void* handle) +{ + smpi_fortran_entry_point_type entry_point2 = + (smpi_fortran_entry_point_type) dlsym(handle, "user_main_"); + if (entry_point2 != nullptr) { + // fprintf(stderr, "EP user_main_=%p\n", entry_point2); + return [entry_point2](int argc, char** argv) { + smpi_process_init(&argc, &argv); + entry_point2(); + return 0; + }; + } + + smpi_c_entry_point_type entry_point = (smpi_c_entry_point_type) dlsym(handle, "main"); + if (entry_point != nullptr) { + // fprintf(stderr, "EP main=%p\n", entry_point); + return entry_point; + } + + return smpi_entry_point_type(); +} + +int smpi_main(const char* executable, int argc, char *argv[]) { srand(SMPI_RAND_SEED); @@ -452,15 +513,73 @@ int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[]) // parse the platform file: get the host list SIMIX_create_environment(argv[1]); - SIMIX_comm_set_copy_data_callback(smpi_comm_copy_data_callback); - SIMIX_function_register_default(realmain); + SIMIX_comm_set_copy_data_callback(smpi_comm_copy_buffer_callback); + + static std::size_t rank = 0; + + if (smpi_privatize_global_variables == SMPI_PRIVATIZE_DLOPEN) { + + std::string executable_copy = executable; + simix_global->default_function = [executable_copy](std::vector args) { + return std::function([executable_copy, args] { + + // Copy the dynamic library: + std::string target_executable = executable_copy + + "_" + std::to_string(getpid()) + + "_" + std::to_string(rank++) + ".so"; + // TODO, execute directly instead of relying on cp + const char* command1 [] = { + "cp", "--reflink=auto", "--", executable_copy.c_str(), target_executable.c_str(), + nullptr + }; + const char* command2 [] = { + "cp", "--", executable_copy.c_str(), target_executable.c_str(), + nullptr + }; + if (execute_command(command1) != 0 && execute_command(command2) != 0) + xbt_die("copy failed"); + + // Load the copy and resolve the entry point: + void* handle = dlopen(target_executable.c_str(), RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); + unlink(target_executable.c_str()); + if (handle == nullptr) + xbt_die("dlopen failed"); + smpi_entry_point_type entry_point = smpi_resolve_function(handle); + if (!entry_point) + xbt_die("Could not resolve entry point"); + + smpi_run_entry_point(entry_point, args); + }); + }; + + } + else { + + // Load the dynamic library and resolve the entry point: + void* handle = dlopen(executable, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); + if (handle == nullptr) + xbt_die("dlopen failed for %s", executable); + smpi_entry_point_type entry_point = smpi_resolve_function(handle); + if (!entry_point) + xbt_die("main not found in %s", executable); + // TODO, register the executable for SMPI privatization + + // Execute the same entry point for each simulated process: + simix_global->default_function = [entry_point](std::vector args) { + return std::function([entry_point, args] { + smpi_run_entry_point(entry_point, args); + }); + }; + + } + SIMIX_launch_application(argv[2]); smpi_global_init(); smpi_check_options(); - if(smpi_privatize_global_variables) + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) smpi_initialize_global_memory_segments(); /* Clean IO before the run */ @@ -510,7 +629,7 @@ void SMPI_init(){ smpi_check_options(); if (TRACE_is_enabled() && TRACE_is_configured()) TRACE_smpi_alloc(); - if(smpi_privatize_global_variables) + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) smpi_initialize_global_memory_segments(); } diff --git a/src/smpi/smpi_memory.cpp b/src/smpi/smpi_memory.cpp index a2fd3c114b..f21f5dcfaa 100644 --- a/src/smpi/smpi_memory.cpp +++ b/src/smpi/smpi_memory.cpp @@ -31,7 +31,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SM int smpi_loaded_page = -1; char* smpi_start_data_exe = nullptr; int smpi_size_data_exe = 0; -bool smpi_privatize_global_variables; +int smpi_privatize_global_variables; static const int PROT_RWX = (PROT_READ | PROT_WRITE | PROT_EXEC); static const int PROT_RW = (PROT_READ | PROT_WRITE ); diff --git a/src/smpi/smpi_process.cpp b/src/smpi/smpi_process.cpp index 918b6888e1..143a9a5786 100644 --- a/src/smpi/smpi_process.cpp +++ b/src/smpi/smpi_process.cpp @@ -90,7 +90,7 @@ void Process::set_data(int* argc, char*** argv) void Process::destroy() { - if(smpi_privatize_global_variables){ + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ smpi_switch_data_segment(index_); } state_ = SMPI_FINALIZED; @@ -279,7 +279,7 @@ void Process::init(int *argc, char ***argv){ int rank = xbt_str_parse_int((*argv)[2], "Invalid rank: %s"); smpi_deployment_register_process(instance_id, rank, index); - if(smpi_privatize_global_variables){ + if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ /* Now using segment index of the process */ index = proc->segment_index; /* Done at the process's creation */ diff --git a/src/smpi/smpi_request.cpp b/src/smpi/smpi_request.cpp index 33eaa9a483..2ff10a2790 100644 --- a/src/smpi/smpi_request.cpp +++ b/src/smpi/smpi_request.cpp @@ -472,7 +472,7 @@ void Request::start() if(!(old_type_->flags() & DT_FLAG_DERIVED)){ oldbuf = buf_; if (!process->replaying() && oldbuf != nullptr && size_!=0){ - if((smpi_privatize_global_variables != 0) + if((smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) && (static_cast(buf_) >= smpi_start_data_exe) && (static_cast(buf_) < smpi_start_data_exe + smpi_size_data_exe )){ XBT_DEBUG("Privatization : We are sending from a zone inside global memory. Switch data segment "); @@ -766,7 +766,7 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status) if((((req->flags_ & ACCUMULATE) != 0) || (datatype->flags() & DT_FLAG_DERIVED)) && (!smpi_is_shared(req->old_buf_))){ if (!smpi_process()->replaying()){ - if( smpi_privatize_global_variables != 0 && (static_cast(req->old_buf_) >= smpi_start_data_exe) + if( smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP && (static_cast(req->old_buf_) >= smpi_start_data_exe) && ((char*)req->old_buf_ < smpi_start_data_exe + smpi_size_data_exe )){ XBT_VERB("Privatization : We are unserializing to a zone in global memory Switch data segment "); smpi_switch_data_segment(smpi_process()->index()); diff --git a/src/smpi/smpicc.in b/src/smpi/smpicc.in index 8667c84dbe..fa5c02e33c 100755 --- a/src/smpi/smpicc.in +++ b/src/smpi/smpicc.in @@ -19,8 +19,9 @@ CMAKE_LINKARGS="-L@libdir@" list_set CFLAGS list_set LINKARGS if [ "@WIN32@" != "1" ]; then - list_add CFLAGS "-Dmain=smpi_simulated_main_" - list_add LINKARGS "-lsimgrid" + # list_add CFLAGS "-Dmain=smpi_simulated_main_" + list_add CFLAGS "-fpic" + list_add LINKARGS "-shared" "-lsimgrid" else list_add CFLAGS "-include" "@includedir@/smpi/smpi_main.h" list_add LINKARGS "@libdir@\libsimgrid.dll" diff --git a/src/smpi/smpicxx.in b/src/smpi/smpicxx.in index 9e8ab98372..886a8dd3f8 100755 --- a/src/smpi/smpicxx.in +++ b/src/smpi/smpicxx.in @@ -19,8 +19,9 @@ CMAKE_LINKARGS="-L@libdir@" list_set CXXFLAGS list_set LINKARGS if [ "@WIN32@" != "1" ]; then - list_add CXXFLAGS "-Dmain=smpi_simulated_main_" - list_add LINKARGS "-lsimgrid" + # list_add CXXFLAGS "-Dmain=smpi_simulated_main_" + list_add CXXFLAGS "-fpic" + list_add LINKARGS "-shared" "-lsimgrid" else list_add CXXFLAGS "-include" "@includedir@/smpi/smpi_main.h" list_add LINKARGS "@libdir@\libsimgrid.dll" diff --git a/src/smpi/smpif90.in b/src/smpi/smpif90.in index 1a54f16bba..459cac3a0f 100644 --- a/src/smpi/smpif90.in +++ b/src/smpi/smpif90.in @@ -16,8 +16,8 @@ CMAKE_LINKARGS="-L@libdir@" @SMPITOOLS_SH@ -list_set FFLAGS "-ff2c" "-fno-second-underscore" -list_set LINKARGS "-lsimgrid" "-lm" "-lgfortran" +list_set FFLAGS "-fpic" "-ff2c" "-fno-second-underscore" +list_set LINKARGS "-shared" "-lsimgrid" "-lm" "-lgfortran" list_set TMPFILES main_name=main diff --git a/src/smpi/smpiff.in b/src/smpi/smpiff.in index 75bbdba92c..f78ffbda4d 100644 --- a/src/smpi/smpiff.in +++ b/src/smpi/smpiff.in @@ -16,8 +16,8 @@ CMAKE_LINKARGS="-L@libdir@" @SMPITOOLS_SH@ -list_set FFLAGS "-ff2c" "-fno-second-underscore" -list_set LINKARGS "-lsimgrid" "-lm" "-lgfortran" +list_set FFLAGS "-fpic" "-ff2c" "-fno-second-underscore" +list_set LINKARGS "-shared" "-lsimgrid" "-lm" "-lgfortran" list_set TMPFILES main_name=main diff --git a/src/smpi/smpirun.in b/src/smpi/smpirun.in index b6f0d93ace..b6a7ec5339 100755 --- a/src/smpi/smpirun.in +++ b/src/smpi/smpirun.in @@ -249,11 +249,7 @@ then exit fi -if [ -n "$WRAPPER" ]; then - EXEC="$WRAPPER $1" -else - EXEC="$1" -fi +EXEC="$1" shift # steel --cfg and --logs options @@ -513,7 +509,7 @@ fi # * The FD 3 is used to temporarily store FD 1. This is because the shell connects FD 1 to /dev/null when the command # is launched in the background: this can be overriden in bash but not in standard bourne shell. exec 3<&0 -${EXEC} ${PRIVATIZE} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP} <&3 3>&- & +${WRAPPER} "@SMPIMAIN@" ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PLATFORMTMP} ${APPLICATIONTMP} <&3 3>&- & pid=$! exec 3>&- wait $pid diff --git a/tools/cmake/Distrib.cmake b/tools/cmake/Distrib.cmake index 485cadb428..43e867b648 100644 --- a/tools/cmake/Distrib.cmake +++ b/tools/cmake/Distrib.cmake @@ -13,6 +13,7 @@ if(enable_smpi) ${CMAKE_BINARY_DIR}/bin/smpicc ${CMAKE_BINARY_DIR}/bin/smpicxx ${CMAKE_BINARY_DIR}/bin/smpirun + ${CMAKE_BINARY_DIR}/bin/smpimain DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/) if(SMPI_FORTRAN) install(PROGRAMS diff --git a/tools/cmake/MakeLib.cmake b/tools/cmake/MakeLib.cmake index 0d157fe851..4594264c5b 100644 --- a/tools/cmake/MakeLib.cmake +++ b/tools/cmake/MakeLib.cmake @@ -97,6 +97,15 @@ endif() # Compute the dependencies of SMPI ################################## + +if(enable_smpi) + set(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}") # for privatization + add_executable(smpimain src/smpi/smpi_main.c) + target_link_libraries(smpimain simgrid) + set_target_properties(smpimain + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +endif() + if(enable_smpi AND APPLE) set(SIMGRID_DEP "${SIMGRID_DEP} -Wl,-U -Wl,_smpi_simulated_main") endif() -- 2.20.1