From: Arnaud Giersch Date: Sun, 29 Dec 2019 20:56:46 +0000 (+0100) Subject: [sonar] Constify pointer and reference parameters in src/smpi/. X-Git-Tag: v3.25~191 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7cd237f9659b2df47fca65a4340ca7b5407f46a0 [sonar] Constify pointer and reference parameters in src/smpi/. --- diff --git a/include/simgrid/smpi/replay.hpp b/include/simgrid/smpi/replay.hpp index 715f52ee93..1a0d2a5a45 100644 --- a/include/simgrid/smpi/replay.hpp +++ b/include/simgrid/smpi/replay.hpp @@ -34,7 +34,7 @@ XBT_PRIVATE unsigned char* smpi_get_tmp_sendbuffer(size_t size); XBT_PRIVATE unsigned char* smpi_get_tmp_recvbuffer(size_t size); -XBT_PRIVATE void log_timed_action(simgrid::xbt::ReplayAction& action, double clock); +XBT_PRIVATE void log_timed_action(const simgrid::xbt::ReplayAction& action, double clock); namespace simgrid { namespace smpi { diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 3ec09537e7..141a23151a 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -1002,9 +1002,9 @@ XBT_PUBLIC void smpi_comm_set_copy_data_callback(void (*callback)(smx_activity_t */ XBT_PUBLIC void smpi_trace_set_call_location(const char* file, int line); /** Fortran binding **/ -XBT_PUBLIC void smpi_trace_set_call_location_(const char* file, int* line); +XBT_PUBLIC void smpi_trace_set_call_location_(const char* file, const int* line); /** Fortran binding + -fsecond-underscore **/ -XBT_PUBLIC void smpi_trace_set_call_location__(const char* file, int* line); +XBT_PUBLIC void smpi_trace_set_call_location__(const char* file, const int* line); #define SMPI_ITER_NAME1(line) _XBT_CONCAT(iter_count, line) #define SMPI_ITER_NAME(line) SMPI_ITER_NAME1(line) diff --git a/src/instr/instr_smpi.hpp b/src/instr/instr_smpi.hpp index f5f7f9f7ea..5414c5308c 100644 --- a/src/instr/instr_smpi.hpp +++ b/src/instr/instr_smpi.hpp @@ -12,7 +12,7 @@ /* Helper functions */ XBT_PRIVATE container_t smpi_container(int rank); -XBT_PRIVATE void TRACE_smpi_setup_container(int rank, sg_host_t host); +XBT_PRIVATE void TRACE_smpi_setup_container(int rank, const_sg_host_t host); XBT_PRIVATE void TRACE_smpi_computing_init(int rank); XBT_PRIVATE void TRACE_smpi_computing_out(int rank); diff --git a/src/smpi/include/smpi_comm.hpp b/src/smpi/include/smpi_comm.hpp index 9a416d6782..8c312ee6da 100644 --- a/src/smpi/include/smpi_comm.hpp +++ b/src/smpi/include/smpi_comm.hpp @@ -84,7 +84,7 @@ public: void add_rma_win(MPI_Win win); void remove_rma_win(MPI_Win win); void finish_rma_calls(); - MPI_Comm split_type(int type, int key, MPI_Info info); + MPI_Comm split_type(int type, int key, const Info* info); }; } // namespace smpi diff --git a/src/smpi/include/smpi_datatype.hpp b/src/smpi/include/smpi_datatype.hpp index 196ab80cbf..b55f3aa473 100644 --- a/src/smpi/include/smpi_datatype.hpp +++ b/src/smpi/include/smpi_datatype.hpp @@ -114,7 +114,7 @@ public: void commit(); bool is_valid(); bool is_basic(); - static const char* encode(MPI_Datatype dt) { return dt->id.c_str(); } + static const char* encode(const Datatype* dt) { return dt->id.c_str(); } static MPI_Datatype decode(const std::string& datatype_id); bool is_replayable(); void addflag(int flag); @@ -129,8 +129,8 @@ public: static int keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state); static int keyval_free(int* keyval); - int pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, MPI_Comm comm); - int unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Comm comm); + int pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, const Comm* comm); + int unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, const Comm* comm); static int create_contiguous(int count, MPI_Datatype old_type, MPI_Aint lb, MPI_Datatype* new_type); static int create_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type); diff --git a/src/smpi/include/smpi_file.hpp b/src/smpi/include/smpi_file.hpp index 95e3d9916a..3e38aa4c65 100644 --- a/src/smpi/include/smpi_file.hpp +++ b/src/smpi/include/smpi_file.hpp @@ -45,7 +45,7 @@ class File{ int sync(); int seek(MPI_Offset offset, int whence); int seek_shared(MPI_Offset offset, int whence); - int set_view(MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, const char *datarep, MPI_Info info); + int set_view(MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, const char* datarep, const Info* info); int get_view(MPI_Offset *disp, MPI_Datatype *etype, MPI_Datatype *filetype, char *datarep); MPI_Info info(); void set_info( MPI_Info info); @@ -57,7 +57,7 @@ class File{ static int write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status); template int op_all(void *buf, int count,MPI_Datatype datatype, MPI_Status *status); static int close(MPI_File *fh); - static int del(const char *filename, MPI_Info info); + static int del(const char* filename, const Info* info); MPI_Errhandler errhandler(); void set_errhandler( MPI_Errhandler errhandler); }; diff --git a/src/smpi/include/smpi_info.hpp b/src/smpi/include/smpi_info.hpp index 1fb206ab03..9799a973dd 100644 --- a/src/smpi/include/smpi_info.hpp +++ b/src/smpi/include/smpi_info.hpp @@ -21,7 +21,7 @@ class Info : public F2C{ public: Info() = default; - explicit Info(Info* orig) : map_(orig->map_) {} + explicit Info(const Info* orig) : map_(orig->map_) {} ~Info() = default; void ref(); static void unref(MPI_Info info); diff --git a/src/smpi/include/smpi_keyvals.hpp b/src/smpi/include/smpi_keyvals.hpp index a9af6701c7..38c6ae573b 100644 --- a/src/smpi/include/smpi_keyvals.hpp +++ b/src/smpi/include/smpi_keyvals.hpp @@ -56,7 +56,8 @@ class Keyval{ template int attr_delete(int keyval); template int attr_get(int keyval, void* attr_value, int* flag); template int attr_put(int keyval, void* attr_value); - template static int call_deleter(T* obj, smpi_key_elem elem, int keyval, void * value, int* flag); + template + static int call_deleter(T* obj, const s_smpi_key_elem_t* elem, int keyval, void* value, int* flag); template void cleanup_attr(); }; diff --git a/src/smpi/include/smpi_request.hpp b/src/smpi/include/smpi_request.hpp index 9634cbf672..5c9fccb933 100644 --- a/src/smpi/include/smpi_request.hpp +++ b/src/smpi/include/smpi_request.hpp @@ -117,7 +117,7 @@ public: static int grequest_start( MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn, MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request); static int grequest_complete( MPI_Request request); - static int get_status(MPI_Request req, int* flag, MPI_Status * status); + static int get_status(const Request* req, int* flag, MPI_Status* status); static void free_f(int id); static Request* f2c(int); diff --git a/src/smpi/include/smpi_status.hpp b/src/smpi/include/smpi_status.hpp index b5c67369cd..b85a561867 100644 --- a/src/smpi/include/smpi_status.hpp +++ b/src/smpi/include/smpi_status.hpp @@ -19,7 +19,7 @@ public: static void empty(MPI_Status * status); static int cancelled (const MPI_Status * status); static void set_cancelled (MPI_Status * status, int flag); -static void set_elements (MPI_Status * status, MPI_Datatype , int count); +static void set_elements(MPI_Status* status, const Datatype*, int count); static int get_count(const MPI_Status * status, MPI_Datatype datatype); }; diff --git a/src/smpi/include/smpi_win.hpp b/src/smpi/include/smpi_win.hpp index 242c7efcdf..ff217b95bb 100644 --- a/src/smpi/include/smpi_win.hpp +++ b/src/smpi/include/smpi_win.hpp @@ -78,9 +78,8 @@ public: int get_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr, int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Request* request=nullptr); - int compare_and_swap(const void *origin_addr, void *compare_addr, - void *result_addr, MPI_Datatype datatype, int target_rank, - MPI_Aint target_disp); + int compare_and_swap(const void* origin_addr, const void* compare_addr, void* result_addr, MPI_Datatype datatype, + int target_rank, MPI_Aint target_disp); static Win* f2c(int id); int lock(int lock_type, int rank, int assert); diff --git a/src/smpi/internals/instr_smpi.cpp b/src/smpi/internals/instr_smpi.cpp index 5c0f4e9ae6..8a728cfa00 100644 --- a/src/smpi/internals/instr_smpi.cpp +++ b/src/smpi/internals/instr_smpi.cpp @@ -136,7 +136,7 @@ static std::string TRACE_smpi_get_key(int src, int dst, int tag, int send) return key; } -void TRACE_smpi_setup_container(int rank, sg_host_t host) +void TRACE_smpi_setup_container(int rank, const_sg_host_t host) { container_t father = simgrid::instr::Container::get_root(); if (TRACE_smpi_is_grouped()) { diff --git a/src/smpi/internals/smpi_bench.cpp b/src/smpi/internals/smpi_bench.cpp index c52478aef2..b7315d3e0c 100644 --- a/src/smpi/internals/smpi_bench.cpp +++ b/src/smpi/internals/smpi_bench.cpp @@ -474,13 +474,13 @@ void smpi_trace_set_call_location(const char* file, const int line) } /** Required for Fortran bindings */ -void smpi_trace_set_call_location_(const char* file, int* line) +void smpi_trace_set_call_location_(const char* file, const int* line) { smpi_trace_set_call_location(file, *line); } /** Required for Fortran if -fsecond-underscore is activated */ -void smpi_trace_set_call_location__(const char* file, int* line) +void smpi_trace_set_call_location__(const char* file, const int* line) { smpi_trace_set_call_location(file, *line); } diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 3922c63077..3c3c90a3f9 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -132,13 +132,14 @@ void smpi_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, s }; } -static void memcpy_private(void* dest, const void* src, std::vector>& private_blocks) +static void memcpy_private(void* dest, const void* src, const std::vector>& private_blocks) { for (auto const& block : private_blocks) memcpy((uint8_t*)dest+block.first, (uint8_t*)src+block.first, block.second-block.first); } -static void check_blocks(std::vector> &private_blocks, size_t buff_size) { +static void check_blocks(const std::vector>& private_blocks, size_t buff_size) +{ for (auto const& block : private_blocks) xbt_assert(block.first <= block.second && block.second <= buff_size, "Oops, bug in shared malloc."); } @@ -557,7 +558,7 @@ int smpi_main(const char* executable, int argc, char* argv[]) /* 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) { + simgrid::s4u::Actor::on_creation.connect([&rank_counts](const simgrid::s4u::Actor& actor) { if (not actor.is_daemon()) rank_counts++; }); diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 27f4605f97..3e0124e7d1 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -64,7 +64,7 @@ public: typedef std::tuple req_key_t; typedef std::unordered_map>> req_storage_t; -void log_timed_action(simgrid::xbt::ReplayAction& action, double clock) +void log_timed_action(const simgrid::xbt::ReplayAction& action, double clock) { if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ std::string s = boost::algorithm::join(action, " "); @@ -754,7 +754,7 @@ void smpi_replay_init(const char* instance_id, int rank, double start_delay_flop TRACE_smpi_comm_in(my_proc_id, "smpi_replay_run_init", new simgrid::instr::NoOpTIData("init")); TRACE_smpi_comm_out(my_proc_id); xbt_replay_action_register("init", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::InitAction().execute(action); }); - xbt_replay_action_register("finalize", [](simgrid::xbt::ReplayAction&) { /* nothing to do */ }); + xbt_replay_action_register("finalize", [](simgrid::xbt::ReplayAction const&) { /* nothing to do */ }); xbt_replay_action_register("comm_size", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::CommunicatorAction().execute(action); }); xbt_replay_action_register("comm_split",[](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::CommunicatorAction().execute(action); }); xbt_replay_action_register("comm_dup", [](simgrid::xbt::ReplayAction& action) { simgrid::smpi::replay::CommunicatorAction().execute(action); }); diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 4fe6185d88..c35d2f1c21 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -571,7 +571,7 @@ void Comm::set_errhandler(MPI_Errhandler errhandler) errhandler_->ref(); } -MPI_Comm Comm::split_type(int type, int /*key*/, MPI_Info) +MPI_Comm Comm::split_type(int type, int /*key*/, const Info*) { //MPI_UNDEFINED can be given to some nodes... but we need them to still perform the smp part which is collective if(type != MPI_COMM_TYPE_SHARED && type != MPI_UNDEFINED){ diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index 8a7773cb2b..c086161cb6 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -256,7 +256,7 @@ void Datatype::set_name(const char* name){ name_ = xbt_strdup(name); } -int Datatype::pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, MPI_Comm) +int Datatype::pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, const Comm*) { if (outcount - *position < incount*static_cast(size_)) return MPI_ERR_OTHER; @@ -265,7 +265,7 @@ int Datatype::pack(const void* inbuf, int incount, void* outbuf, int outcount, i return MPI_SUCCESS; } -int Datatype::unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Comm) +int Datatype::unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, const Comm*) { if (outcount*static_cast(size_)> insize) return MPI_ERR_OTHER; diff --git a/src/smpi/mpi/smpi_file.cpp b/src/smpi/mpi/smpi_file.cpp index 4c73765a01..3cf7e0de72 100644 --- a/src/smpi/mpi/smpi_file.cpp +++ b/src/smpi/mpi/smpi_file.cpp @@ -91,7 +91,7 @@ namespace smpi{ return MPI_SUCCESS; } - int File::del(const char* filename, MPI_Info) + int File::del(const char* filename, const Info*) { //get the file with MPI_MODE_DELETE_ON_CLOSE and then close it File* f = new File(MPI_COMM_SELF,filename,MPI_MODE_DELETE_ON_CLOSE|MPI_MODE_RDWR, nullptr); @@ -248,7 +248,7 @@ namespace smpi{ return ret; } - int File::set_view(MPI_Offset /*disp*/, MPI_Datatype etype, MPI_Datatype filetype, const char* datarep, MPI_Info) + int File::set_view(MPI_Offset /*disp*/, MPI_Datatype etype, MPI_Datatype filetype, const char* datarep, const Info*) { etype_=etype; filetype_=filetype; diff --git a/src/smpi/mpi/smpi_keyvals.cpp b/src/smpi/mpi/smpi_keyvals.cpp index 33badb3a17..7ddedb633e 100644 --- a/src/smpi/mpi/smpi_keyvals.cpp +++ b/src/smpi/mpi/smpi_keyvals.cpp @@ -14,7 +14,8 @@ std::unordered_map* Keyval::attributes(){ return &attributes_; } -template <> int Keyval::call_deleter(Comm* obj, smpi_key_elem elem, int keyval, void* value, int* /*flag*/) +template <> +int Keyval::call_deleter(Comm* obj, const s_smpi_key_elem_t* elem, int keyval, void* value, int* /*flag*/) { int ret = MPI_SUCCESS; if(elem->delete_fn.comm_delete_fn!=MPI_NULL_DELETE_FN) @@ -24,7 +25,8 @@ template <> int Keyval::call_deleter(Comm* obj, smpi_key_elem elem, int ke return ret; } -template <> int Keyval::call_deleter(Win* obj, smpi_key_elem elem, int keyval, void* value, int* /*flag*/) +template <> +int Keyval::call_deleter(Win* obj, const s_smpi_key_elem_t* elem, int keyval, void* value, int* /*flag*/) { int ret = MPI_SUCCESS; if(elem->delete_fn.win_delete_fn!=MPI_NULL_DELETE_FN) @@ -35,7 +37,7 @@ template <> int Keyval::call_deleter(Win* obj, smpi_key_elem elem, int keyv } template <> -int Keyval::call_deleter(Datatype* obj, smpi_key_elem elem, int keyval, void* value, int* /*flag*/) +int Keyval::call_deleter(Datatype* obj, const s_smpi_key_elem_t* elem, int keyval, void* value, int* /*flag*/) { int ret = MPI_SUCCESS; if(elem->delete_fn.type_delete_fn!=MPI_NULL_DELETE_FN) diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index b9ac2b3526..18173a352c 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -1111,7 +1111,7 @@ void Request::free_f(int id) } } -int Request::get_status(MPI_Request req, int* flag, MPI_Status* status) +int Request::get_status(const Request* req, int* flag, MPI_Status* status) { *flag=0; diff --git a/src/smpi/mpi/smpi_status.cpp b/src/smpi/mpi/smpi_status.cpp index 7c8d6e1d9e..2d0f92e6b1 100644 --- a/src/smpi/mpi/smpi_status.cpp +++ b/src/smpi/mpi/smpi_status.cpp @@ -32,7 +32,8 @@ void Status::set_cancelled(MPI_Status * status, int flag) status->cancelled=flag; } -void Status::set_elements (MPI_Status * status, MPI_Datatype , int count){ +void Status::set_elements(MPI_Status* status, const Datatype*, int count) +{ status->count=count; } diff --git a/src/smpi/mpi/smpi_topo.cpp b/src/smpi/mpi/smpi_topo.cpp index 2dbbcd4704..5219fc6616 100644 --- a/src/smpi/mpi/smpi_topo.cpp +++ b/src/smpi/mpi/smpi_topo.cpp @@ -12,7 +12,7 @@ #include /* static functions */ -static int assignnodes(int ndim, int nfactor, int *pfacts,int **pdims); +static int assignnodes(int ndim, int nfactor, const int* pfacts, int** pdims); static int getfactors(int num, int *nfators, int **factors); @@ -349,7 +349,7 @@ int Topo_Cart::Dims_create(int nnodes, int ndims, int dims[]) * - ptr to array of dimensions (returned value) * Returns: - 0 or ERROR */ -static int assignnodes(int ndim, int nfactor, int *pfacts, int **pdims) +static int assignnodes(int ndim, int nfactor, const int* pfacts, int** pdims) { int *pmin; diff --git a/src/smpi/mpi/smpi_win.cpp b/src/smpi/mpi/smpi_win.cpp index 1dfda94394..41c17e7aa8 100644 --- a/src/smpi/mpi/smpi_win.cpp +++ b/src/smpi/mpi/smpi_win.cpp @@ -414,9 +414,9 @@ int Win::get_accumulate(const void* origin_addr, int origin_count, MPI_Datatype return MPI_SUCCESS; } -int Win::compare_and_swap(const void *origin_addr, void *compare_addr, - void *result_addr, MPI_Datatype datatype, int target_rank, - MPI_Aint target_disp){ +int Win::compare_and_swap(const void* origin_addr, const void* compare_addr, void* result_addr, MPI_Datatype datatype, + int target_rank, MPI_Aint target_disp) +{ //get sender pointer const Win* send_win = connected_wins_[target_rank]; diff --git a/src/smpi/plugins/load_balancer/LoadBalancer.cpp b/src/smpi/plugins/load_balancer/LoadBalancer.cpp index c748eb5b30..a5eb936551 100644 --- a/src/smpi/plugins/load_balancer/LoadBalancer.cpp +++ b/src/smpi/plugins/load_balancer/LoadBalancer.cpp @@ -46,7 +46,7 @@ void LoadBalancer::run() { simgrid::s4u::Engine* engine = simgrid::s4u::Engine::get_instance(); std::vector available_hosts = - engine->get_filtered_hosts([](simgrid::s4u::Host* host) { return host->is_on(); }); + engine->get_filtered_hosts([](const simgrid::s4u::Host* host) { return host->is_on(); }); xbt_assert(available_hosts.size() > 0, "No hosts available; are they all switched off?"); // TODO: Account for daemon background load (-> use especially the availability file) diff --git a/src/smpi/plugins/load_balancer/load_balancer.hpp b/src/smpi/plugins/load_balancer/load_balancer.hpp index 4924337984..3c87f07c97 100644 --- a/src/smpi/plugins/load_balancer/load_balancer.hpp +++ b/src/smpi/plugins/load_balancer/load_balancer.hpp @@ -46,11 +46,8 @@ public: void for_each_actor(simgrid::s4u::Host* host, const std::function& callback) { auto range = host_to_actors.equal_range(host); - std::for_each( - range.first, - range.second, - [&callback](host_to_actors_map_t::value_type& x) { callback(x.second); } - ); + std::for_each(range.first, range.second, + [&callback](host_to_actors_map_t::value_type const& x) { callback(x.second); }); } };