X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6956c386f8489f3a713f20f67eb9bcb4e3941d80..07dd1c4f9a71f2f5ae8ac7235dd1066b135e5ae2:/src/smpi/internals/smpi_global.cpp diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index bdbb3f3423..59e5c6a693 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -25,6 +25,10 @@ #include #include +#if SIMGRID_HAVE_MC +#include "src/mc/mc_config.hpp" +#endif + #if SG_HAVE_SENDFILE #include #endif @@ -78,7 +82,6 @@ std::map units2papi_ std::unordered_map location2speedup; -static std::map process_data; static int smpi_exit_status = 0; extern double smpi_total_benched_time; xbt_os_timer_t global_timer; @@ -94,9 +97,6 @@ static std::vector privatize_libs_paths; * See smpi_comm.cpp and the functions therein for details. */ MPI_Comm MPI_COMM_WORLD = MPI_COMM_UNINITIALIZED; -MPI_Errhandler *MPI_ERRORS_RETURN = nullptr; -MPI_Errhandler *MPI_ERRORS_ARE_FATAL = nullptr; -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 tag is generated). static const std::string smpi_default_instance_name("smpirun"); @@ -113,12 +113,14 @@ simgrid::smpi::ActorExt* smpi_process() if (me == nullptr) // This happens sometimes (eg, when linking against NS3 because it pulls openMPI...) return nullptr; - return process_data.at(me.get()); + return me->extension(); } simgrid::smpi::ActorExt* smpi_process_remote(simgrid::s4u::ActorPtr actor) { - return process_data.at(actor.get()); + if (actor.get() == nullptr) + return nullptr; + return actor->extension(); } MPI_Comm smpi_process_comm_self(){ @@ -129,17 +131,12 @@ MPI_Info smpi_process_info_env(){ return smpi_process()->info_env(); } -void smpi_process_init(int*, char***) -{ - simgrid::smpi::ActorExt::init(); -} - void * smpi_process_get_user_data(){ - return simgrid::s4u::Actor::self()->get_impl()->get_user_data(); + return simgrid::s4u::Actor::self()->get_data(); } void smpi_process_set_user_data(void *data){ - simgrid::s4u::Actor::self()->get_impl()->set_user_data(data); + simgrid::s4u::Actor::self()->set_data(data); } void smpi_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, size_t)) @@ -162,6 +159,17 @@ static void check_blocks(std::vector> &private_blocks, xbt_assert(block.first <= block.second && block.second <= buff_size, "Oops, bug in shared malloc."); } +static void smpi_cleanup_comm_after_copy(simgrid::kernel::activity::CommImpl* comm, void* buff){ + if (comm->detached()) { + // if this is a detached send, the source buffer was duplicated by SMPI + // sender to make the original buffer available to the application ASAP + xbt_free(buff); + //It seems that the request is used after the call there this should be free somewhere else but where??? + //xbt_free(comm->comm.src_data);// inside SMPI the request is kept inside the user data and should be free + comm->src_buff_ = nullptr; + } +} + void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size) { size_t src_offset = 0; @@ -170,16 +178,24 @@ void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, v std::vector> dst_private_blocks; XBT_DEBUG("Copy the data over"); if(smpi_is_shared(buff, src_private_blocks, &src_offset)) { - XBT_DEBUG("Sender %p is shared. Let's ignore it.", buff); src_private_blocks = shift_and_frame_private_blocks(src_private_blocks, src_offset, buff_size); + if (src_private_blocks.size()==1 && (src_private_blocks[0].second - src_private_blocks[0].first)==buff_size){//simple shared malloc ... return. + XBT_DEBUG("Sender %p is shared. Let's ignore it.", buff); + smpi_cleanup_comm_after_copy(comm, buff); + return; + } } else { src_private_blocks.clear(); src_private_blocks.push_back(std::make_pair(0, buff_size)); } if (smpi_is_shared((char*)comm->dst_buff_, dst_private_blocks, &dst_offset)) { - XBT_DEBUG("Receiver %p is shared. Let's ignore it.", (char*)comm->dst_buff_); dst_private_blocks = shift_and_frame_private_blocks(dst_private_blocks, dst_offset, buff_size); + if (src_private_blocks.size()==1 && (src_private_blocks[0].second - src_private_blocks[0].first)==buff_size){//simple shared malloc ... return. + XBT_DEBUG("Receiver %p is shared. Let's ignore it.", (char*)comm->dst_buff_); + smpi_cleanup_comm_after_copy(comm, buff); + return; + } } else { dst_private_blocks.clear(); @@ -208,14 +224,7 @@ void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, v XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff, comm->dst_buff_); memcpy_private(comm->dst_buff_, tmpbuff, private_blocks); - if (comm->detached()) { - // if this is a detached send, the source buffer was duplicated by SMPI - // sender to make the original buffer available to the application ASAP - xbt_free(buff); - //It seems that the request is used after the call there this should be free somewhere else but where??? - //xbt_free(comm->comm.src_data);// inside SMPI the request is kept inside the user data and should be free - comm->src_buff_ = nullptr; - } + smpi_cleanup_comm_after_copy(comm,buff); if (tmpbuff != buff) xbt_free(tmpbuff); } @@ -227,9 +236,21 @@ void smpi_comm_null_copy_buffer_callback(simgrid::kernel::activity::CommImpl*, v static void smpi_check_options() { - //check correctness of MPI parameters +#if SIMGRID_HAVE_MC + if (MC_is_active()) { + if (_sg_mc_buffering == "zero") + simgrid::config::set_value("smpi/send-is-detached-thresh", 0); + else if (_sg_mc_buffering == "infty") + simgrid::config::set_value("smpi/send-is-detached-thresh", INT_MAX); + else + THROW_IMPOSSIBLE; + } +#endif xbt_assert(simgrid::config::get_value("smpi/async-small-thresh") <= + simgrid::config::get_value("smpi/send-is-detached-thresh"), + "smpi/async-small-thresh (=%d) should be smaller or equal to smpi/send-is-detached-thresh (=%d)", + simgrid::config::get_value("smpi/async-small-thresh"), simgrid::config::get_value("smpi/send-is-detached-thresh")); if (simgrid::config::is_default("smpi/host-speed") && not MC_is_active()) { @@ -247,35 +268,11 @@ static void smpi_check_options() } int smpi_enabled() { - return not process_data.empty(); + return MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED; } -void smpi_global_init() +static void smpi_init_papi() { - if (not MC_is_active()) { - global_timer = xbt_os_timer_new(); - xbt_os_walltimer_start(global_timer); - } - - std::string filename = simgrid::config::get_value("smpi/comp-adjustment-file"); - if (not filename.empty()) { - std::ifstream fstream(filename); - xbt_assert(fstream.is_open(), "Could not open file %s. Does it exist?", filename.c_str()); - - std::string line; - typedef boost::tokenizer< boost::escaped_list_separator> Tokenizer; - std::getline(fstream, line); // Skip the header line - while (std::getline(fstream, line)) { - Tokenizer tok(line); - Tokenizer::iterator it = tok.begin(); - Tokenizer::iterator end = std::next(tok.begin()); - - std::string location = *it; - boost::trim(location); - location2speedup.insert(std::pair(location, std::stod(*end))); - } - } - #if HAVE_PAPI // 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)) @@ -341,33 +338,12 @@ void smpi_global_init() #endif } -void smpi_global_destroy() -{ - smpi_bench_destroy(); - smpi_shared_destroy(); - smpi_deployment_cleanup_instances(); - - if (simgrid::smpi::Colls::smpi_coll_cleanup_callback != nullptr) - simgrid::smpi::Colls::smpi_coll_cleanup_callback(); - - MPI_COMM_WORLD = MPI_COMM_NULL; - - if (not MC_is_active()) { - xbt_os_timer_free(global_timer); - } - - if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) - smpi_destroy_global_memory_segments(); - if(simgrid::smpi::F2C::lookup() != nullptr) - simgrid::smpi::F2C::delete_lookup(); -} - static void smpi_init_options(){ // return if already called if (smpi_cpu_threshold > -1) return; - simgrid::smpi::Colls::set_collectives(); - simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr; + simgrid::smpi::colls::set_collectives(); + simgrid::smpi::colls::smpi_coll_cleanup_callback = nullptr; smpi_cpu_threshold = simgrid::config::get_value("smpi/cpu-threshold"); if (smpi_cpu_threshold < 0) smpi_cpu_threshold = DBL_MAX; @@ -430,7 +406,6 @@ static int smpi_run_entry_point(const F& entry_point, const std::string& executa args4argv->push_back(nullptr); char** argv = args4argv->data(); - simgrid::smpi::ActorExt::init(); #if SMPI_IFORT for_rtl_init_ (&argc, argv); #elif SMPI_FLANG @@ -656,10 +631,11 @@ int smpi_main(const char* executable, int argc, char* argv[]) TRACE_global_init(); SIMIX_global_init(&argc, argv); + auto engine = simgrid::s4u::Engine::get_instance(); SMPI_switch_data_segment = &smpi_switch_data_segment; sg_storage_file_system_init(); // parse the platform file: get the host list - simgrid::s4u::Engine::get_instance()->load_platform(argv[1]); + engine->load_platform(argv[1]); SIMIX_comm_set_copy_data_callback(smpi_comm_copy_buffer_callback); smpi_init_options(); @@ -669,9 +645,16 @@ int smpi_main(const char* executable, int argc, char* argv[]) smpi_init_privatization_no_dlopen(executable); SMPI_init(); - simgrid::s4u::Engine::get_instance()->load_deployment(argv[2]); - SMPI_app_instance_register(smpi_default_instance_name.c_str(), nullptr, - process_data.size()); // This call has a side effect on process_count... + + /* This is a ... heavy way to count the MPI ranks */ + int rank_counts = 0; + simgrid::s4u::Actor::on_creation.connect([&rank_counts](simgrid::s4u::Actor& actor) { + if (not actor.is_daemon()) + rank_counts++; + }); + engine->load_deployment(argv[2]); + + SMPI_app_instance_register(smpi_default_instance_name.c_str(), nullptr, rank_counts); MPI_COMM_WORLD = *smpi_deployment_comm_world(smpi_default_instance_name); /* Clean IO before the run */ @@ -697,7 +680,7 @@ int smpi_main(const char* executable, int argc, char* argv[]) "You may want to use sampling functions or trace replay to reduce this."); } } - smpi_global_destroy(); + SMPI_finalize(); return smpi_exit_status; } @@ -705,31 +688,65 @@ int smpi_main(const char* executable, int argc, char* argv[]) // Called either directly from the user code, or from the code called by smpirun void SMPI_init(){ simgrid::s4u::Actor::on_creation.connect([](simgrid::s4u::Actor& actor) { - if (not actor.is_daemon()) { - process_data.insert({&actor, new simgrid::smpi::ActorExt(&actor)}); - } - }); - simgrid::s4u::Actor::on_destruction.connect([](simgrid::s4u::Actor const& actor) { - auto it = process_data.find(&actor); - if (it != process_data.end()) { - delete it->second; - process_data.erase(it); - } + if (not actor.is_daemon()) + actor.extension_set(new simgrid::smpi::ActorExt(&actor)); }); simgrid::s4u::Host::on_creation.connect( [](simgrid::s4u::Host& host) { host.extension_set(new simgrid::smpi::Host(&host)); }); + for (auto const& host : simgrid::s4u::Engine::get_instance()->get_all_hosts()) + host->extension_set(new simgrid::smpi::Host(host)); smpi_init_options(); - smpi_global_init(); + if (not MC_is_active()) { + global_timer = xbt_os_timer_new(); + xbt_os_walltimer_start(global_timer); + } + + std::string filename = simgrid::config::get_value("smpi/comp-adjustment-file"); + if (not filename.empty()) { + std::ifstream fstream(filename); + xbt_assert(fstream.is_open(), "Could not open file %s. Does it exist?", filename.c_str()); + + std::string line; + typedef boost::tokenizer> Tokenizer; + std::getline(fstream, line); // Skip the header line + while (std::getline(fstream, line)) { + Tokenizer tok(line); + Tokenizer::iterator it = tok.begin(); + Tokenizer::iterator end = std::next(tok.begin()); + + std::string location = *it; + boost::trim(location); + location2speedup.insert(std::pair(location, std::stod(*end))); + } + } + smpi_init_papi(); smpi_check_options(); } -void SMPI_finalize(){ - smpi_global_destroy(); +void SMPI_finalize() +{ + smpi_bench_destroy(); + smpi_shared_destroy(); + smpi_deployment_cleanup_instances(); + + if (simgrid::smpi::colls::smpi_coll_cleanup_callback != nullptr) + simgrid::smpi::colls::smpi_coll_cleanup_callback(); + + MPI_COMM_WORLD = MPI_COMM_NULL; + + if (not MC_is_active()) { + xbt_os_timer_free(global_timer); + } + + if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) + smpi_destroy_global_memory_segments(); + if (simgrid::smpi::F2C::lookup() != nullptr) + simgrid::smpi::F2C::delete_lookup(); } void smpi_mpi_init() { smpi_init_fortran_types(); if(smpi_init_sleep > 0) - simcall_process_sleep(smpi_init_sleep); + simgrid::s4u::this_actor::sleep_for(smpi_init_sleep); }