From: Christian Heinrich Date: Thu, 11 Jan 2018 16:19:47 +0000 (+0100) Subject: [SMPI] Program against s4u::Actor and not smx_actor_t X-Git-Tag: v3.19~312^2~50 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/dbcf720995035476f8fda570bd5ab0926cacc799 [SMPI] Program against s4u::Actor and not smx_actor_t --- diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index 2eb7847f7c..ade674e6fb 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -432,7 +432,7 @@ XBT_PRIVATE int smpi_process_papi_event_set(); extern std::unordered_map location2speedup; // TODO: Move this to the right location (if we keep this...) -void smpi_add_process(int adjusted_proc_id); +void smpi_add_process(simgrid::s4u::ActorPtr actor); /** @brief Returns the last call location (filename, linenumber). Process-specific. */ extern "C" { diff --git a/src/smpi/include/smpi_process.hpp b/src/smpi/include/smpi_process.hpp index 0b11c1fcd7..f6bfa80176 100644 --- a/src/smpi/include/smpi_process.hpp +++ b/src/smpi/include/smpi_process.hpp @@ -36,7 +36,7 @@ class Process { msg_bar_t finalization_barrier_; int return_value_ = 0; smpi_trace_call_location_t trace_call_loc_; - smx_actor_t process_ = nullptr; + simgrid::s4u::ActorPtr process_ = nullptr; smpi_privatization_region_t privatized_region_; #if HAVE_PAPI /** Contains hardware data as read by PAPI **/ @@ -44,7 +44,7 @@ class Process { papi_counter_t papi_counter_data_; #endif public: - explicit Process(int index, msg_bar_t barrier); + explicit Process(simgrid::s4u::ActorPtr actor, msg_bar_t barrier); void set_data(int index, int* argc, char*** argv); void finalize(); int finalized(); @@ -78,7 +78,7 @@ class Process { int return_value(); void set_return_value(int val); static void init(int *argc, char ***argv); - smx_actor_t process(); + simgrid::s4u::ActorPtr process(); }; diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index 8077214243..c067ad93ea 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -44,7 +44,7 @@ void smpi_execute_(double *duration) void smpi_execute_flops(double flops) { XBT_DEBUG("Handle real computation time: %f flops", flops); - smx_activity_t action = simcall_execution_start("computation", flops, 1, 0, smpi_process()->process()->host); + smx_activity_t action = simcall_execution_start("computation", flops, 1, 0, smpi_process()->process()->getImpl()->host); simcall_set_category (action, TRACE_internal_smpi_get_category()); simcall_execution_wait(action); smpi_switch_data_segment(smpi_process()->index()); diff --git a/src/smpi/internals/smpi_deployment.cpp b/src/smpi/internals/smpi_deployment.cpp index 7a75f15f26..7d61374e39 100644 --- a/src/smpi/internals/smpi_deployment.cpp +++ b/src/smpi/internals/smpi_deployment.cpp @@ -23,12 +23,7 @@ public: , present_processes(0) , comm_world(comm) , finalization_barrier(finalization_barrier) - { - int cur_process_count = smpi_process_count(); - for (int i = 0; i < max_no_processes; i++) { - smpi_add_process(cur_process_count + i); - } - } + { } const char* name; int size; diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index c9e5e7b24e..70dc1e3406 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -50,6 +50,8 @@ struct papi_process_data { }; #endif +using simgrid::s4u::Actor; +using simgrid::s4u::ActorPtr; std::unordered_map location2speedup; static std::map process_data; @@ -81,10 +83,10 @@ static simgrid::config::Flag smpi_init_sleep( void (*smpi_comm_copy_data_callback) (smx_activity_t, void*, size_t) = &smpi_comm_copy_buffer_callback; -void smpi_add_process(int smx_process) +void smpi_add_process(ActorPtr actor) { process_data.insert( - std::pair(smx_process, new simgrid::smpi::Process(smx_process, nullptr))); + {actor->getPid()-1, new simgrid::smpi::Process(actor, nullptr)}); } int smpi_process_count() @@ -94,10 +96,10 @@ int smpi_process_count() simgrid::smpi::Process* smpi_process() { - smx_actor_t me = SIMIX_process_self(); + 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(me->userdata); + simgrid::msg::ActorExt* msgExt = static_cast(me->getImpl()->userdata); return static_cast(msgExt->data); } @@ -624,6 +626,9 @@ 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::onCreation.connect([](simgrid::s4u::ActorPtr actor) { + smpi_add_process(actor); + }); smpi_init_options(); smpi_global_init(); smpi_check_options(); diff --git a/src/smpi/internals/smpi_process.cpp b/src/smpi/internals/smpi_process.cpp index 2ed9958cf6..280e5e94ac 100644 --- a/src/smpi/internals/smpi_process.cpp +++ b/src/smpi/internals/smpi_process.cpp @@ -31,10 +31,14 @@ static char *get_mailbox_name_small(char *str, int index) namespace simgrid{ namespace smpi{ -Process::Process(int index, msg_bar_t finalization_barrier) +using simgrid::s4u::ActorPtr; + +Process::Process(ActorPtr actor, msg_bar_t finalization_barrier) : finalization_barrier_(finalization_barrier) { char name[MAILBOX_NAME_MAXLEN]; + process_ = actor; + int index = actor->getPid() - 1; // TODO cheinrich: This needs to be removed! Just a quick hack to make the following 2 lines work mailbox_ = simgrid::s4u::Mailbox::byName(get_mailbox_name(name, index)); mailbox_small_ = simgrid::s4u::Mailbox::byName(get_mailbox_name_small(name, index)); mailboxes_mutex_ = xbt_mutex_init(); @@ -71,8 +75,8 @@ void Process::set_data(int index, int* argc, char*** argv) instance_id_ = instance_id; index_ = index; - process_ = SIMIX_process_self(); - static_cast(process_->userdata)->data = this; + process_ = simgrid::s4u::Actor::self(); + static_cast(process_->getImpl()->userdata)->data = this; if (*argc > 3) { memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2)); @@ -146,7 +150,7 @@ void *Process::get_user_data() return data_; } -smx_actor_t Process::process(){ +ActorPtr Process::process(){ return process_; } @@ -270,10 +274,10 @@ void Process::init(int *argc, char ***argv){ xbt_die("SimGrid was not initialized properly before entering MPI_Init. Aborting, please check compilation process and use smpirun\n"); } if (argc != nullptr && argv != nullptr) { - smx_actor_t proc = SIMIX_process_self(); - proc->context->set_cleanup(&MSG_process_cleanup_from_SIMIX); + simgrid::s4u::ActorPtr proc = simgrid::s4u::Actor::self(); + proc->getImpl()->context->set_cleanup(&MSG_process_cleanup_from_SIMIX); - int index = proc->pid - 1; // The maestro process has always ID 0 but we don't need that process here + int index = proc->getPid() - 1; // The maestro process has always ID 0 but we don't need that process here char* instance_id = (*argv)[1]; try { @@ -288,7 +292,7 @@ void Process::init(int *argc, char ***argv){ Process* process = smpi_process_remote(index); if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ /* Now using the segment index of this process */ - index = proc->segment_index; + index = proc->getImpl()->segment_index; process->set_privatized_region(smpi_init_global_memory_segment_process()); /* Done at the process's creation */ SMPI_switch_data_segment(index); diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index ad6d8e09b1..57e5a6bd35 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -378,7 +378,7 @@ void Request::start() // we make a copy here, as the size is modified by simix, and we may reuse the request in another receive later real_size_=size_; action_ = simcall_comm_irecv( - process->process(), mailbox, buf_, &real_size_, &match_recv, + process->process()->getImpl(), mailbox, buf_, &real_size_, &match_recv, process->replaying() ? &smpi_comm_null_copy_buffer_callback : smpi_comm_copy_data_callback, this, -1.0); XBT_DEBUG("recv simcall posted"); @@ -632,7 +632,7 @@ void Request::iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* if (smpi_iprobe_sleep > 0) { smx_activity_t iprobe_sleep = simcall_execution_start( "iprobe", /* flops to executek*/ nsleeps * smpi_iprobe_sleep * speed * maxrate, /* priority */ 1.0, - /* performance bound */ maxrate * speed, smpi_process()->process()->host); + /* performance bound */ maxrate * speed, smpi_process()->process()->getImpl()->host); simcall_execution_wait(iprobe_sleep); } // behave like a receive, but don't do it