From a7c708d3570410ce5a1316a54f9dda55d2bb46ca Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 15 Mar 2018 21:53:17 +0100 Subject: [PATCH] Use an ActorPtr as parameter to smpi_switch_data_segemnt. --- src/mc/remote/Client.cpp | 4 ++-- src/simix/ActorImpl.cpp | 2 +- src/simix/ActorImpl.hpp | 2 +- src/simix/smx_global.cpp | 2 +- src/smpi/include/private.hpp | 4 ++-- src/smpi/internals/smpi_bench.cpp | 4 ++-- src/smpi/internals/smpi_global.cpp | 4 ++-- src/smpi/internals/smpi_memory.cpp | 15 ++++++++------- src/smpi/internals/smpi_process.cpp | 3 +-- src/smpi/mpi/smpi_comm.cpp | 10 +++++----- src/smpi/mpi/smpi_datatype.cpp | 4 ++-- src/smpi/mpi/smpi_op.cpp | 4 ++-- src/smpi/mpi/smpi_request.cpp | 6 +++--- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/mc/remote/Client.cpp b/src/mc/remote/Client.cpp index 6521d94201..f515ae41e9 100644 --- a/src/mc/remote/Client.cpp +++ b/src/mc/remote/Client.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2018. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -114,7 +114,7 @@ void Client::handleSimcall(s_mc_message_simcall_handle_t* message) void Client::handleRestore(s_mc_message_restore_t* message) { #if HAVE_SMPI - smpi_really_switch_data_segment(message->index); + smpi_really_switch_data_segment(simgrid::s4u::Actor::byPid(message->index)); #endif } void Client::handleActorEnabled(s_mc_message_actor_enabled_t* msg) diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 7bdaca7046..e7445fb24a 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -749,7 +749,7 @@ void SIMIX_process_yield(smx_actor_t self) } if (SMPI_switch_data_segment && not self->finished) { - SMPI_switch_data_segment(self->pid); + SMPI_switch_data_segment(self->iface()); } } diff --git a/src/simix/ActorImpl.hpp b/src/simix/ActorImpl.hpp index ad51e8bf69..942064c111 100644 --- a/src/simix/ActorImpl.hpp +++ b/src/simix/ActorImpl.hpp @@ -148,7 +148,7 @@ XBT_PRIVATE void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest); XBT_PRIVATE void SIMIX_process_auto_restart_set(smx_actor_t process, int auto_restart); -extern void (*SMPI_switch_data_segment)(int dest); +extern void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr actor); } XBT_PRIVATE void SIMIX_process_sleep_destroy(smx_activity_t synchro); diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 887a2fb4eb..f813a39ac7 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -68,7 +68,7 @@ public: s_smx_timer_t(double date, simgrid::xbt::Task callback) : date(date), callback(std::move(callback)) {} }; -void (*SMPI_switch_data_segment)(int) = nullptr; +void (*SMPI_switch_data_segment)(simgrid::s4u::ActorPtr) = nullptr; int _sg_do_verbose_exit = 1; static void inthandler(int) diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index ad5ae02cae..f0954541f9 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -89,8 +89,8 @@ extern XBT_PRIVATE int smpi_data_exe_size; // size of the data+bss segment of enum shared_malloc_type { shmalloc_none, shmalloc_local, shmalloc_global }; extern XBT_PRIVATE shared_malloc_type smpi_cfg_shared_malloc; // Whether to activate shared malloc -XBT_PRIVATE void smpi_switch_data_segment(int dest); -XBT_PRIVATE void smpi_really_switch_data_segment(int dest); +XBT_PRIVATE void smpi_switch_data_segment(simgrid::s4u::ActorPtr actor); +XBT_PRIVATE void smpi_really_switch_data_segment(simgrid::s4u::ActorPtr actor); XBT_PRIVATE int smpi_is_privatization_file(char* file); XBT_PRIVATE void smpi_get_executable_global_size(); diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index d0ccc26e96..b71adc7edd 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -47,7 +47,7 @@ void smpi_execute_flops(double flops) { smx_activity_t action = simcall_execution_start("computation", flops, 1, 0, smpi_process()->process()->getHost()); simcall_set_category (action, TRACE_internal_smpi_get_category()); simcall_execution_wait(action); - smpi_switch_data_segment(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } void smpi_execute(double duration) @@ -79,7 +79,7 @@ void smpi_execute_benched(double duration) void smpi_bench_begin() { if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) { - smpi_switch_data_segment(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } if (MC_is_active() || MC_record_replay_is_active()) diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index b3e4714a63..f75d237792 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -192,7 +192,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b if ((smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) && (static_cast(buff) >= smpi_data_exe_start) && (static_cast(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 !"); - smpi_switch_data_segment(comm->src_proc->pid); + smpi_switch_data_segment(comm->src_proc->iface()); tmpbuff = static_cast(xbt_malloc(buff_size)); memcpy_private(tmpbuff, buff, private_blocks); } @@ -200,7 +200,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b if ((smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) && ((char*)comm->dst_buff >= smpi_data_exe_start) && ((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"); - smpi_switch_data_segment(comm->dst_proc->pid); + smpi_switch_data_segment(comm->dst_proc->iface()); } XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff,comm->dst_buff); memcpy_private(comm->dst_buff, tmpbuff, private_blocks); diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index 461eab8432..be0e7da7b8 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -97,12 +97,13 @@ static void* asan_safe_memcpy(void* dest, void* src, size_t n) #endif /** Map a given SMPI privatization segment (make a SMPI process active) */ -void smpi_switch_data_segment(int dest) { - if (smpi_loaded_page == dest)//no need to switch, we've already loaded the one we want +void smpi_switch_data_segment(simgrid::s4u::ActorPtr actor) +{ + if (smpi_loaded_page == actor->getPid()) // no need to switch, we've already loaded the one we want return; // So the job: - smpi_really_switch_data_segment(dest); + smpi_really_switch_data_segment(actor); } /** Map a given SMPI privatization segment (make a SMPI process active) even if SMPI thinks it is already active @@ -110,21 +111,21 @@ void smpi_switch_data_segment(int dest) { * When doing a state restoration, the state of the restored variables might not be consistent with the state of the * virtual memory. In this case, we to change the data segment. */ -void smpi_really_switch_data_segment(int dest) +void smpi_really_switch_data_segment(simgrid::s4u::ActorPtr actor) { if (smpi_data_exe_size == 0) // no need to switch return; #if HAVE_PRIVATIZATION // FIXME, cross-process support (mmap across process when necessary) - XBT_DEBUG("Switching data frame to the one of process %d", dest); - simgrid::smpi::Process* process = smpi_process_remote(simgrid::s4u::Actor::byPid(dest)); + XBT_DEBUG("Switching data frame to the one of process %ld", actor->getPid()); + simgrid::smpi::Process* process = smpi_process_remote(actor); int current = process->privatized_region()->file_descriptor; void* tmp = mmap(TOPAGE(smpi_data_exe_start), smpi_data_exe_size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, current, 0); if (tmp != TOPAGE(smpi_data_exe_start)) xbt_die("Couldn't map the new region (errno %d): %s", errno, strerror(errno)); - smpi_loaded_page = dest; + smpi_loaded_page = actor->getPid(); #endif } diff --git a/src/smpi/internals/smpi_process.cpp b/src/smpi/internals/smpi_process.cpp index 2e173de0c1..fc8e8e153e 100644 --- a/src/smpi/internals/smpi_process.cpp +++ b/src/smpi/internals/smpi_process.cpp @@ -262,12 +262,11 @@ void Process::init(int *argc, char ***argv){ // cheinrich: I'm not sure what the impact of the SMPI_switch_data_segment on this call is. I moved // this up here so that I can set the privatized region before the switch. Process* process = smpi_process_remote(proc); - int my_proc_id = proc->getPid(); if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ /* Now using the segment index of this process */ process->set_privatized_region(smpi_init_global_memory_segment_process()); /* Done at the process's creation */ - SMPI_switch_data_segment(my_proc_id); + SMPI_switch_data_segment(proc); } process->set_data(argc, argv); diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 4652d05c70..c256f12d46 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2018. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -57,7 +57,7 @@ void Comm::destroy(Comm* comm) int Comm::dup(MPI_Comm* newcomm){ 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(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } MPI_Group cp = new Group(this->group()); (*newcomm) = new Comm(cp, this->topo()); @@ -300,7 +300,7 @@ void Comm::init_smp(){ } 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(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } //identify neighbours in comm //get the indices of all processes sharing the same simix host @@ -336,7 +336,7 @@ void Comm::init_smp(){ Coll_allgather_mpich::allgather(&leader, 1, MPI_INT , leaders_map, 1, MPI_INT, this); 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(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } if(leaders_map_==nullptr){ @@ -408,7 +408,7 @@ void Comm::init_smp(){ Coll_bcast_mpich::bcast(&(is_uniform_),1, MPI_INT, 0, comm_intra ); 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(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } // Are the ranks blocked ? = allocated contiguously on the SMP nodes int is_blocked=1; diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index aea96feee0..7103d09008 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -1,5 +1,5 @@ /* smpi_datatype.cpp -- MPI primitives to handle datatypes */ -/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -277,7 +277,7 @@ int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, // FIXME Handle the case of a partial shared malloc. if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ - smpi_switch_data_segment(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } /* First check if we really have something to do */ if (recvcount > 0 && recvbuf != sendbuf) { diff --git a/src/smpi/mpi/smpi_op.cpp b/src/smpi/mpi/smpi_op.cpp index 53fa2cb6a8..521f9b0dca 100644 --- a/src/smpi/mpi/smpi_op.cpp +++ b/src/smpi/mpi/smpi_op.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -242,7 +242,7 @@ void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype) { if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){//we need to switch as the called function may silently touch global variables XBT_DEBUG("Applying operation, switch to the right data frame "); - smpi_switch_data_segment(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } if (not smpi_process()->replaying() && *len > 0) { diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index c961ef2b1b..6b461e181e 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -413,7 +413,7 @@ void Request::start() if ((smpi_privatize_global_variables != 0) && (static_cast(buf_) >= smpi_data_exe_start) && (static_cast(buf_) < smpi_data_exe_start + smpi_data_exe_size)) { XBT_DEBUG("Privatization : We are sending from a zone inside global memory. Switch data segment "); - smpi_switch_data_segment(src_); + smpi_switch_data_segment(simgrid::s4u::Actor::byPid(src_)); } buf = xbt_malloc(size_); memcpy(buf,oldbuf,size_); @@ -708,7 +708,7 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status) static_cast(req->old_buf_) >= smpi_data_exe_start && static_cast(req->old_buf_) < smpi_data_exe_start + smpi_data_exe_size) { XBT_VERB("Privatization : We are unserializing to a zone in global memory Switch data segment "); - smpi_switch_data_segment(simgrid::s4u::Actor::self()->getPid()); + smpi_switch_data_segment(simgrid::s4u::Actor::self()); } if(datatype->flags() & DT_FLAG_DERIVED){ -- 2.20.1