From 217ab9d5146bf370bbb20065fd357a5c099c78ee Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 13 Mar 2019 11:56:01 +0100 Subject: [PATCH] cleanups in smpi, mostly cosmetic stuff and indent --- src/smpi/include/smpi_actor.hpp | 5 +- src/smpi/include/smpi_coll.hpp | 83 +++++----- src/smpi/include/smpi_comm.hpp | 107 +++++++------ src/smpi/include/smpi_datatype.hpp | 16 +- src/smpi/include/smpi_datatype_derived.hpp | 5 +- src/smpi/include/smpi_group.hpp | 65 ++++---- src/smpi/include/smpi_host.hpp | 12 +- src/smpi/include/smpi_info.hpp | 33 ++-- src/smpi/include/smpi_op.hpp | 24 +-- src/smpi/include/smpi_request.hpp | 170 ++++++++++----------- src/smpi/include/smpi_topo.hpp | 89 ++++++----- src/smpi/include/smpi_win.hpp | 1 - src/smpi/internals/smpi_host.cpp | 24 ++- src/smpi/mpi/smpi_comm.cpp | 14 +- src/smpi/mpi/smpi_datatype.cpp | 46 +----- src/smpi/mpi/smpi_group.cpp | 17 --- src/smpi/mpi/smpi_info.cpp | 9 +- src/smpi/mpi/smpi_op.cpp | 21 --- src/smpi/mpi/smpi_request.cpp | 36 ----- 19 files changed, 317 insertions(+), 460 deletions(-) diff --git a/src/smpi/include/smpi_actor.hpp b/src/smpi/include/smpi_actor.hpp index 5a2e33378e..264507b131 100644 --- a/src/smpi/include/smpi_actor.hpp +++ b/src/smpi/include/smpi_actor.hpp @@ -15,7 +15,6 @@ namespace simgrid { namespace smpi { class ActorExt { -private: double simulated_ = 0 /* Used to time with simulated_start/elapsed */; s4u::Mailbox* mailbox_; s4u::Mailbox* mailbox_small_; @@ -41,7 +40,7 @@ private: papi_counter_t papi_counter_data_; #endif public: - explicit ActorExt(simgrid::s4u::ActorPtr actor, simgrid::s4u::Barrier* barrier); + explicit ActorExt(s4u::ActorPtr actor, s4u::Barrier* barrier); ActorExt(const ActorExt&) = delete; ActorExt& operator=(const ActorExt&) = delete; ~ActorExt(); @@ -75,7 +74,7 @@ public: void set_sampling(int s); int sampling(); static void init(); - simgrid::s4u::ActorPtr get_actor(); + s4u::ActorPtr get_actor(); int get_optind(); void set_optind(int optind); }; diff --git a/src/smpi/include/smpi_coll.hpp b/src/smpi/include/smpi_coll.hpp index 335cd7f200..0299f6c9e0 100644 --- a/src/smpi/include/smpi_coll.hpp +++ b/src/smpi/include/smpi_coll.hpp @@ -89,53 +89,52 @@ struct s_mpi_coll_description_t { }; class Colls{ - public: - static XBT_PUBLIC void coll_help(const char* category, s_mpi_coll_description_t* table); - static XBT_PUBLIC int find_coll_description(s_mpi_coll_description_t* table, const std::string& name, - const char* desc); - static void set_collectives(); - - // for each collective type, create the set_* prototype, the description array and the function pointer - COLL_APPLY(COLL_DEFS, COLL_GATHER_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_ALLGATHER_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_ALLGATHERV_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_REDUCE_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_ALLREDUCE_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_REDUCE_SCATTER_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_SCATTER_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_BARRIER_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_BCAST_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_ALLTOALL_SIG, ""); - COLL_APPLY(COLL_DEFS, COLL_ALLTOALLV_SIG, ""); - - // These fairly unused collectives only have one implementation in SMPI - static int gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, - MPI_Datatype recvtype, int root, MPI_Comm comm); - static int scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, - int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); - static int scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); - static int exscan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); - - static void (*smpi_coll_cleanup_callback)(); +public: + static XBT_PUBLIC void coll_help(const char* category, s_mpi_coll_description_t* table); + static XBT_PUBLIC int find_coll_description(s_mpi_coll_description_t* table, const std::string& name, + const char* desc); + static void set_collectives(); + + // for each collective type, create the set_* prototype, the description array and the function pointer + COLL_APPLY(COLL_DEFS, COLL_GATHER_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_ALLGATHER_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_ALLGATHERV_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_REDUCE_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_ALLREDUCE_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_REDUCE_SCATTER_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_SCATTER_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_BARRIER_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_BCAST_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_ALLTOALL_SIG, ""); + COLL_APPLY(COLL_DEFS, COLL_ALLTOALLV_SIG, ""); + + // These fairly unused collectives only have one implementation in SMPI + static int gatherv(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, + MPI_Datatype recvtype, int root, MPI_Comm comm); + static int scatterv(void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, + MPI_Datatype recvtype, int root, MPI_Comm comm); + static int scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); + static int exscan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); + + static void (*smpi_coll_cleanup_callback)(); }; class Coll { - public: - // for each collective type, create a function member - COLL_APPLY(COLL_SIG,COLL_GATHER_SIG,""); - COLL_APPLY(COLL_SIG,COLL_ALLGATHER_SIG,""); - COLL_APPLY(COLL_SIG,COLL_ALLGATHERV_SIG,""); - COLL_APPLY(COLL_SIG,COLL_REDUCE_SIG,""); - COLL_APPLY(COLL_SIG,COLL_ALLREDUCE_SIG,""); - COLL_APPLY(COLL_SIG,COLL_REDUCE_SCATTER_SIG,""); - COLL_APPLY(COLL_SIG,COLL_SCATTER_SIG,""); - COLL_APPLY(COLL_SIG,COLL_BARRIER_SIG,""); - COLL_APPLY(COLL_SIG,COLL_BCAST_SIG,""); - COLL_APPLY(COLL_SIG,COLL_ALLTOALL_SIG,""); - COLL_APPLY(COLL_SIG,COLL_ALLTOALLV_SIG,""); +public: + // for each collective type, create a function member + COLL_APPLY(COLL_SIG, COLL_GATHER_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_ALLGATHER_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_ALLGATHERV_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_REDUCE_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_ALLREDUCE_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_REDUCE_SCATTER_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_SCATTER_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_BARRIER_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_BCAST_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_ALLTOALL_SIG, ""); + COLL_APPLY(COLL_SIG, COLL_ALLTOALLV_SIG, ""); }; - /************* * GATHER * *************/ diff --git a/src/smpi/include/smpi_comm.hpp b/src/smpi/include/smpi_comm.hpp index aaee438204..e43c5b3e74 100644 --- a/src/smpi/include/smpi_comm.hpp +++ b/src/smpi/include/smpi_comm.hpp @@ -15,67 +15,64 @@ namespace simgrid{ namespace smpi{ class Comm : public F2C, public Keyval{ + MPI_Group group_; + SMPI_Topo_type topoType_; + MPI_Topology topo_; // to be replaced by an union + int refcount_; + MPI_Comm leaders_comm_; // inter-node communicator + MPI_Comm intra_comm_; // intra-node communicator . For MPI_COMM_WORLD this can't be used, as var is global. + // use an intracomm stored in the process data instead + int* leaders_map_; // who is the leader of each process + int is_uniform_; + int* non_uniform_map_; // set if smp nodes have a different number of processes allocated + int is_blocked_; // are ranks allocated on the same smp node contiguous ? + int is_smp_comm_; // set to 0 in case this is already an intra-comm or a leader-comm to avoid recursivity + std::list rma_wins_; // attached windows for synchronization. - private: - MPI_Group group_; - SMPI_Topo_type topoType_; - MPI_Topology topo_; // to be replaced by an union - int refcount_; - MPI_Comm leaders_comm_;//inter-node communicator - MPI_Comm intra_comm_;//intra-node communicator . For MPI_COMM_WORLD this can't be used, as var is global. - //use an intracomm stored in the process data instead - int* leaders_map_; //who is the leader of each process - int is_uniform_; - int* non_uniform_map_; //set if smp nodes have a different number of processes allocated - int is_blocked_;// are ranks allocated on the same smp node contiguous ? - int is_smp_comm_;// set to 0 in case this is already an intra-comm or a leader-comm to avoid recursivity - std::list rma_wins_; // attached windows for synchronization. +public: + static std::unordered_map keyvals_; + static int keyval_id_; - public: - static std::unordered_map keyvals_; - static int keyval_id_; + Comm() = default; + Comm(MPI_Group group, MPI_Topology topo, int smp = 0); + int dup(MPI_Comm* newcomm); + MPI_Group group(); + MPI_Topology topo() { return topo_; } + int size(); + int rank(); + void get_name(char* name, int* len); + void set_leaders_comm(MPI_Comm leaders); + void set_intra_comm(MPI_Comm leaders) { intra_comm_ = leaders; }; + int* get_non_uniform_map(); + int* get_leaders_map(); + MPI_Comm get_leaders_comm(); + MPI_Comm get_intra_comm(); + int is_uniform(); + int is_blocked(); + int is_smp_comm(); + MPI_Comm split(int color, int key); + void cleanup_smp(); + void ref(); + static void unref(MPI_Comm comm); + static void destroy(MPI_Comm comm); + void init_smp(); - Comm() = default; - Comm(MPI_Group group, MPI_Topology topo, int smp=0); - int dup(MPI_Comm* newcomm); - MPI_Group group(); - MPI_Topology topo(); - int size(); - int rank(); - void get_name (char* name, int* len); - void set_leaders_comm(MPI_Comm leaders); - void set_intra_comm(MPI_Comm leaders); - int* get_non_uniform_map(); - int* get_leaders_map(); - MPI_Comm get_leaders_comm(); - MPI_Comm get_intra_comm(); - int is_uniform(); - int is_blocked(); - int is_smp_comm(); - MPI_Comm split(int color, int key); - void cleanup_smp(); - void ref(); - static void unref(MPI_Comm comm); - static void destroy(MPI_Comm comm); - void init_smp(); + int add_f() override; + static void free_f(int id); + static Comm* f2c(int); - int add_f() override; - static void free_f(int id); - static Comm* f2c(int); - - static int keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state); - static int keyval_free(int* keyval); - static void keyval_cleanup(); - - 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); + static int keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, + void* extra_state); + static int keyval_free(int* keyval); + static void keyval_cleanup(); + 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); }; -} -} - +} // namespace smpi +} // namespace simgrid #endif diff --git a/src/smpi/include/smpi_datatype.hpp b/src/smpi/include/smpi_datatype.hpp index 6c8b8d9954..3b00c7e02b 100644 --- a/src/smpi/include/smpi_datatype.hpp +++ b/src/smpi/include/smpi_datatype.hpp @@ -102,24 +102,24 @@ public: Datatype& operator=(const Datatype&) = delete; virtual ~Datatype(); - char* name(); - size_t size(); - MPI_Aint lb(); - MPI_Aint ub(); - int flags(); - int refcount(); + char* name() { return name_; } + size_t size() { return size_; } + MPI_Aint lb() { return lb_; } + MPI_Aint ub() { return ub_; } + int flags() { return flags_; } + int refcount() { return refcount_; } void ref(); static void unref(MPI_Datatype datatype); void commit(); bool is_valid(); bool is_basic(); - static const char* encode(MPI_Datatype dt); + static const char* encode(MPI_Datatype dt) { return dt->id.c_str(); } static MPI_Datatype decode(const std::string& datatype_id); bool is_replayable(); void addflag(int flag); int extent(MPI_Aint* lb, MPI_Aint* extent); - MPI_Aint get_extent(); + MPI_Aint get_extent() { return ub_ - lb_; }; void get_name(char* name, int* length); void set_name(char* name); static int copy(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, diff --git a/src/smpi/include/smpi_datatype_derived.hpp b/src/smpi/include/smpi_datatype_derived.hpp index 30b4e9e232..e98619709a 100644 --- a/src/smpi/include/smpi_datatype_derived.hpp +++ b/src/smpi/include/smpi_datatype_derived.hpp @@ -87,8 +87,7 @@ public: void unserialize(void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); }; - -} -} +} // namespace smpi +} // namespace simgrid #endif diff --git a/src/smpi/include/smpi_group.hpp b/src/smpi/include/smpi_group.hpp index 1a008533a1..cdbf4b8346 100644 --- a/src/smpi/include/smpi_group.hpp +++ b/src/smpi/include/smpi_group.hpp @@ -16,40 +16,37 @@ namespace simgrid{ namespace smpi{ class Group : public F2C{ - private: - int size_; - /* This is actually a map from int to int. We could use - * std::map here, but looking up a value there costs O(log(n)). - * For a vector, this costs O(1). We hence go with the vector. - */ - std::vector rank_to_actor_map_; - std::map actor_to_rank_map_; - std::vector index_to_rank_map_; - - int refcount_; - public: - explicit Group(); - explicit Group(int size); - explicit Group(Group* origin); - - void set_mapping(simgrid::s4u::ActorPtr actor, int rank); - int rank(int index); - simgrid::s4u::ActorPtr actor(int rank); - int rank(const simgrid::s4u::ActorPtr process); - void ref(); - static void unref(MPI_Group group); - int size(); - int compare(MPI_Group group2); - int incl(int n, int* ranks, MPI_Group* newgroup); - int excl(int n, int *ranks, MPI_Group * newgroup); - int group_union(MPI_Group group2, MPI_Group* newgroup); - int intersection(MPI_Group group2, MPI_Group* newgroup); - int difference(MPI_Group group2, MPI_Group* newgroup); - int range_incl(int n, int ranges[][3], MPI_Group * newgroup); - int range_excl(int n, int ranges[][3], MPI_Group * newgroup); - - static Group* f2c(int id); - + int size_ = 0; + /* This is actually a map from int to int. We could use std::map here, but looking up a value there costs O(log(n)). + * For a vector, this costs O(1). We hence go with the vector. + */ + std::vector rank_to_actor_map_; + std::map actor_to_rank_map_; + std::vector index_to_rank_map_; + + int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */ +public: + Group() = default; + explicit Group(int size) : size_(size), rank_to_actor_map_(size, nullptr), index_to_rank_map_(size, MPI_UNDEFINED) {} + explicit Group(Group* origin); + + void set_mapping(s4u::ActorPtr actor, int rank); + int rank(int index); + s4u::ActorPtr actor(int rank); + int rank(const s4u::ActorPtr process); + void ref(); + static void unref(MPI_Group group); + int size() { return size_; } + int compare(MPI_Group group2); + int incl(int n, int* ranks, MPI_Group* newgroup); + int excl(int n, int* ranks, MPI_Group* newgroup); + int group_union(MPI_Group group2, MPI_Group* newgroup); + int intersection(MPI_Group group2, MPI_Group* newgroup); + int difference(MPI_Group group2, MPI_Group* newgroup); + int range_incl(int n, int ranges[][3], MPI_Group* newgroup); + int range_excl(int n, int ranges[][3], MPI_Group* newgroup); + + static Group* f2c(int id); }; } } diff --git a/src/smpi/include/smpi_host.hpp b/src/smpi/include/smpi_host.hpp index 5df8d7c4e5..8768c01402 100644 --- a/src/smpi/include/smpi_host.hpp +++ b/src/smpi/include/smpi_host.hpp @@ -17,18 +17,16 @@ namespace simgrid { namespace smpi { class Host { - - private: std::vector orecv_parsed_values; std::vector osend_parsed_values; std::vector oisend_parsed_values; - simgrid::s4u::Host *host = nullptr; + s4u::Host* host = nullptr; - public: - static simgrid::xbt::Extension EXTENSION_ID; +public: + static xbt::Extension EXTENSION_ID; - explicit Host(simgrid::s4u::Host *ptr); - ~Host(); + explicit Host(s4u::Host* ptr); + ~Host() = default; double orecv(size_t size); double osend(size_t size); diff --git a/src/smpi/include/smpi_info.hpp b/src/smpi/include/smpi_info.hpp index 49361ea2a5..01062cc31b 100644 --- a/src/smpi/include/smpi_info.hpp +++ b/src/smpi/include/smpi_info.hpp @@ -16,23 +16,22 @@ namespace simgrid{ namespace smpi{ class Info : public F2C{ - private: - std::map map_; - int refcount_ = 1; - - public: - Info() = default; - explicit Info(Info* orig); - ~Info() = default; - void ref(); - static void unref(MPI_Info info); - void set(char *key, char *value); - int get(char *key,int valuelen, char *value, int *flag); - int remove(char* key); - int get_nkeys(int *nkeys); - int get_nthkey(int n, char *key); - int get_valuelen(char *key, int *valuelen, int *flag); - static Info* f2c(int id); + std::map map_; + int refcount_ = 1; + +public: + Info() = default; + explicit Info(Info* orig) : map_(orig->map_) {} + ~Info() = default; + void ref(); + static void unref(MPI_Info info); + void set(char* key, char* value) { map_[key] = value; } + int get(char* key, int valuelen, char* value, int* flag); + int remove(char* key); + int get_nkeys(int* nkeys); + int get_nthkey(int n, char* key); + int get_valuelen(char* key, int* valuelen, int* flag); + static Info* f2c(int id); }; } diff --git a/src/smpi/include/smpi_op.hpp b/src/smpi/include/smpi_op.hpp index 14e60da2b0..53541773e3 100644 --- a/src/smpi/include/smpi_op.hpp +++ b/src/smpi/include/smpi_op.hpp @@ -13,18 +13,18 @@ namespace simgrid{ namespace smpi{ class Op : public F2C{ - private: - MPI_User_function *func_; - bool is_commutative_; - bool is_fortran_op_; - public: - - Op(MPI_User_function * function, bool commutative); - bool is_commutative(); - bool is_fortran_op(); - void set_fortran_op(); - void apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype); - static Op* f2c(int id); + MPI_User_function* func_; + bool is_commutative_; + bool is_fortran_op_ = false; + +public: + Op(MPI_User_function* function, bool commutative) : func_(function), is_commutative_(commutative) {} + bool is_commutative() { return is_commutative_; } + bool is_fortran_op() { return is_fortran_op_; } + // tell that we were created from fortran, so we need to translate the type to fortran when called + void set_fortran_op() { is_fortran_op_ = true; } + void apply(void* invec, void* inoutvec, int* len, MPI_Datatype datatype); + static Op* f2c(int id); }; } diff --git a/src/smpi/include/smpi_request.hpp b/src/smpi/include/smpi_request.hpp index c6292518a4..487623739f 100644 --- a/src/smpi/include/smpi_request.hpp +++ b/src/smpi/include/smpi_request.hpp @@ -13,91 +13,91 @@ namespace simgrid{ namespace smpi{ class Request : public F2C { - private : - void *buf_; - /* in the case of non-contiguous memory the user address should be keep - * to unserialize the data inside the user memory*/ - void *old_buf_; - /* this is especially for derived datatypes that we need to serialize/unserialize. - * It let us know how to unserialize at the end of the communication */ - MPI_Datatype old_type_; - size_t size_; - int src_; - int dst_; - int tag_; - //to handle cases where we have an unknown sender - //We can't override src, tag, and size, because the request may be reused later - int real_src_; - int real_tag_; - int truncated_; - size_t real_size_; - MPI_Comm comm_; - smx_activity_t action_; - unsigned flags_; - int detached_; - MPI_Request detached_sender_; - int refcount_; - MPI_Op op_; - int cancelled_; - public: - Request()=default; - Request(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags); - MPI_Comm comm(); - size_t size(); - size_t real_size(); - int src(); - int dst(); - int tag(); - int flags(); - int detached(); - MPI_Datatype type(); - void print_request(const char *message); - void start(); - void cancel(); - void ref(); - static void finish_wait(MPI_Request* request, MPI_Status * status); - static void unref(MPI_Request* request); - static void wait(MPI_Request* req, MPI_Status * status); - static MPI_Request send_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - static MPI_Request isend_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - static MPI_Request ssend_init(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - static MPI_Request rma_send_init(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm,MPI_Op op); - static MPI_Request recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); - static MPI_Request rma_recv_init(void *buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm,MPI_Op op); - static MPI_Request irecv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); - static MPI_Request isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - static MPI_Request issend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - static MPI_Request irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); - - static void recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status); - static void send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - static void ssend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); - - static void sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,int dst, int sendtag, - void *recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, - MPI_Comm comm, MPI_Status * status); - - static void startall(int count, MPI_Request * requests); - - static int test(MPI_Request * request,MPI_Status * status); - static int testsome(int incount, MPI_Request requests[], int *indices, MPI_Status status[]); - static int testany(int count, MPI_Request requests[], int *index, MPI_Status * status); - static int testall(int count, MPI_Request requests[], MPI_Status status[]); - - static void probe(int source, int tag, MPI_Comm comm, MPI_Status* status); - static void iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status); - - static int waitany(int count, MPI_Request requests[], MPI_Status * status); - static int waitall(int count, MPI_Request requests[], MPI_Status status[]); - static int waitsome(int incount, MPI_Request requests[], int *indices, MPI_Status status[]); - - static int match_send(void* a, void* b, simgrid::kernel::activity::CommImpl* ignored); - static int match_recv(void* a, void* b, simgrid::kernel::activity::CommImpl* ignored); - - int add_f() override; - static void free_f(int id); - static Request* f2c(int); - + void* buf_; + /* in the case of non-contiguous memory the user address should be keep + * to unserialize the data inside the user memory*/ + void* old_buf_; + /* this is especially for derived datatypes that we need to serialize/unserialize. + * It let us know how to unserialize at the end of the communication */ + MPI_Datatype old_type_; + size_t size_; + int src_; + int dst_; + int tag_; + // to handle cases where we have an unknown sender + // We can't override src, tag, and size, because the request may be reused later + int real_src_; + int real_tag_; + int truncated_; + size_t real_size_; + MPI_Comm comm_; + smx_activity_t action_; + unsigned flags_; + int detached_; + MPI_Request detached_sender_; + int refcount_; + MPI_Op op_; + int cancelled_; + +public: + Request() = default; + Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, MPI_Comm comm, unsigned flags); + MPI_Comm comm() { return comm_; } + size_t size() { return size_; } + size_t real_size() { return real_size_; } + int src() { return src_; } + int dst() { return dst_; } + int tag() { return tag_; } + int flags() { return flags_; } + int detached() { return detached_; } + MPI_Datatype type() { return old_type_; } + void print_request(const char* message); + void start(); + void cancel(); + void ref(); + static void finish_wait(MPI_Request* request, MPI_Status* status); + static void unref(MPI_Request* request); + static void wait(MPI_Request* req, MPI_Status* status); + static MPI_Request send_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + static MPI_Request isend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + static MPI_Request ssend_init(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + static MPI_Request rma_send_init(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, + MPI_Comm comm, MPI_Op op); + static MPI_Request recv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); + static MPI_Request rma_recv_init(void* buf, int count, MPI_Datatype datatype, int src, int dst, int tag, + MPI_Comm comm, MPI_Op op); + static MPI_Request irecv_init(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); + static MPI_Request isend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + static MPI_Request issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + static MPI_Request irecv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm); + + static void recv(void* buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status* status); + static void send(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + static void ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm); + + static void sendrecv(void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, + int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status); + + static void startall(int count, MPI_Request* requests); + + static int test(MPI_Request* request, MPI_Status* status); + static int testsome(int incount, MPI_Request requests[], int* indices, MPI_Status status[]); + static int testany(int count, MPI_Request requests[], int* index, MPI_Status* status); + static int testall(int count, MPI_Request requests[], MPI_Status status[]); + + static void probe(int source, int tag, MPI_Comm comm, MPI_Status* status); + static void iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status); + + static int waitany(int count, MPI_Request requests[], MPI_Status* status); + static int waitall(int count, MPI_Request requests[], MPI_Status status[]); + static int waitsome(int incount, MPI_Request requests[], int* indices, MPI_Status status[]); + + static int match_send(void* a, void* b, kernel::activity::CommImpl* ignored); + static int match_recv(void* a, void* b, kernel::activity::CommImpl* ignored); + + int add_f() override; + static void free_f(int id); + static Request* f2c(int); }; diff --git a/src/smpi/include/smpi_topo.hpp b/src/smpi/include/smpi_topo.hpp index 35e3196d52..be11c3250a 100644 --- a/src/smpi/include/smpi_topo.hpp +++ b/src/smpi/include/smpi_topo.hpp @@ -15,61 +15,60 @@ namespace simgrid{ namespace smpi{ class Topo { - public: - virtual ~Topo()=default; - MPI_Comm getComm() const { return comm_; } - void setComm(MPI_Comm comm) { comm_ = comm; } - private: - MPI_Comm comm_; -}; + MPI_Comm comm_; +public: + virtual ~Topo() = default; + MPI_Comm getComm() const { return comm_; } + void setComm(MPI_Comm comm) { comm_ = comm; } +}; class Topo_Cart: public Topo { - private: - int nnodes_ = 0; - int ndims_; - int *dims_; - int *periodic_; - int *position_; - public: - explicit Topo_Cart(int ndims); - Topo_Cart(const Topo_Cart&) = delete; - Topo_Cart& operator=(const Topo_Cart&) = delete; - ~Topo_Cart(); - Topo_Cart(MPI_Comm comm_old, int ndims, int dims[], int periods[], int reorder, MPI_Comm *comm_cart); - Topo_Cart* sub(const int remain_dims[], MPI_Comm *newcomm) ; - int coords(int rank, int maxdims, int coords[]) ; - int get(int maxdims, int* dims, int* periods, int* coords); - int rank(int* coords, int* rank); - int shift(int direction, int disp, int *rank_source, int *rank_dest) ; - int dim_get(int *ndims); - static int Dims_create(int nnodes, int ndims, int dims[]); + int nnodes_ = 0; + int ndims_; + int* dims_; + int* periodic_; + int* position_; + +public: + explicit Topo_Cart(int ndims); + Topo_Cart(const Topo_Cart&) = delete; + Topo_Cart& operator=(const Topo_Cart&) = delete; + ~Topo_Cart(); + Topo_Cart(MPI_Comm comm_old, int ndims, int dims[], int periods[], int reorder, MPI_Comm* comm_cart); + Topo_Cart* sub(const int remain_dims[], MPI_Comm* newcomm); + int coords(int rank, int maxdims, int coords[]); + int get(int maxdims, int* dims, int* periods, int* coords); + int rank(int* coords, int* rank); + int shift(int direction, int disp, int* rank_source, int* rank_dest); + int dim_get(int* ndims); + static int Dims_create(int nnodes, int ndims, int dims[]); }; class Topo_Graph: public Topo { - private: - int nnodes_; - int *index_; - int *edges_; - public: - Topo_Graph(); - Topo_Graph(const Topo_Graph&) = delete; - Topo_Graph& operator=(const Topo_Graph&) = delete; - ~Topo_Graph(); + int nnodes_; + int* index_; + int* edges_; + +public: + Topo_Graph(); + Topo_Graph(const Topo_Graph&) = delete; + Topo_Graph& operator=(const Topo_Graph&) = delete; + ~Topo_Graph(); }; class Topo_Dist_Graph: public Topo { - private: - int *in_; - int *in_weights_; - int *out_; - int *out_weights_; - public: - Topo_Dist_Graph(); - Topo_Dist_Graph(const Topo_Dist_Graph&) = delete; - Topo_Dist_Graph& operator=(const Topo_Dist_Graph&) = delete; - ~Topo_Dist_Graph(); + int* in_; + int* in_weights_; + int* out_; + int* out_weights_; + +public: + Topo_Dist_Graph(); + Topo_Dist_Graph(const Topo_Dist_Graph&) = delete; + Topo_Dist_Graph& operator=(const Topo_Dist_Graph&) = delete; + ~Topo_Dist_Graph(); }; } diff --git a/src/smpi/include/smpi_win.hpp b/src/smpi/include/smpi_win.hpp index beee0b4927..c32499feea 100644 --- a/src/smpi/include/smpi_win.hpp +++ b/src/smpi/include/smpi_win.hpp @@ -19,7 +19,6 @@ namespace simgrid{ namespace smpi{ class Win : public F2C, public Keyval { - private : void* base_; MPI_Aint size_; int disp_unit_; diff --git a/src/smpi/internals/smpi_host.cpp b/src/smpi/internals/smpi_host.cpp index 30573e304a..25cadabe2f 100644 --- a/src/smpi/internals/smpi_host.cpp +++ b/src/smpi/internals/smpi_host.cpp @@ -17,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_host, smpi, "Logging specific to SMPI (host namespace simgrid { namespace smpi { -simgrid::xbt::Extension Host::EXTENSION_ID; +xbt::Extension Host::EXTENSION_ID; double Host::orecv(size_t size) { @@ -46,9 +46,8 @@ double Host::osend(size_t size) { double current = osend_parsed_values.empty() ? 0.0 : osend_parsed_values[0].values[0] + osend_parsed_values[0].values[1] * size; - // Iterate over all the sections that were specified and find the right - // value. (fact.factor represents the interval sizes; we want to find the - // section that has fact.factor <= size and no other such fact.factor <= size) + // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval + // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size) // Note: parse_factor() (used before) already sorts the vector we iterate over! for (auto const& fact : osend_parsed_values) { if (size <= fact.factor) { // Values already too large, use the previously computed value of current! @@ -88,33 +87,32 @@ double Host::oisend(size_t size) return current; } -Host::Host(simgrid::s4u::Host *ptr) : host(ptr) +Host::Host(s4u::Host* ptr) : host(ptr) { - if (not Host::EXTENSION_ID.valid()) - Host::EXTENSION_ID = simgrid::s4u::Host::extension_create(); + if (not smpi::Host::EXTENSION_ID.valid()) + smpi::Host::EXTENSION_ID = s4u::Host::extension_create(); const char* orecv_string = host->get_property("smpi/or"); if (orecv_string != nullptr) { orecv_parsed_values = parse_factor(orecv_string); } else { - orecv_parsed_values = parse_factor(simgrid::config::get_value("smpi/or")); + orecv_parsed_values = parse_factor(config::get_value("smpi/or")); } const char* osend_string = host->get_property("smpi/os"); if (osend_string != nullptr) { osend_parsed_values = parse_factor(osend_string); } else { - osend_parsed_values = parse_factor(simgrid::config::get_value("smpi/os")); + osend_parsed_values = parse_factor(config::get_value("smpi/os")); } const char* oisend_string = host->get_property("smpi/ois"); if (oisend_string != nullptr) { oisend_parsed_values = parse_factor(oisend_string); } else { - oisend_parsed_values = parse_factor(simgrid::config::get_value("smpi/ois")); + oisend_parsed_values = parse_factor(config::get_value("smpi/ois")); } } -Host::~Host()=default; -} -} +} // namespace smpi +} // namespace simgrid diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 97cb03340c..c9ddb5a26f 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -100,10 +100,6 @@ MPI_Group Comm::group() return group_; } -MPI_Topology Comm::topo() { - return topo_; -} - int Comm::size() { if (this == MPI_COMM_UNINITIALIZED) @@ -140,10 +136,6 @@ void Comm::set_leaders_comm(MPI_Comm leaders){ leaders_comm_=leaders; } -void Comm::set_intra_comm(MPI_Comm leaders){ - intra_comm_=leaders; -} - int* Comm::get_non_uniform_map(){ if (this == MPI_COMM_UNINITIALIZED) return smpi_process()->comm_world()->get_non_uniform_map(); @@ -511,7 +503,5 @@ MPI_Comm Comm::split_type(int type, int key, MPI_Info info) return this->get_intra_comm(); } -} -} - - +} // namespace smpi +} // namespace simgrid diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index 8da35270a4..9cce9baf2c 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -177,7 +177,6 @@ Datatype::~Datatype(){ xbt_free(name_); } - void Datatype::ref(){ refcount_++; @@ -216,16 +215,6 @@ bool Datatype::is_basic() return (flags_ & DT_FLAG_BASIC); } -const char* Datatype::encode(MPI_Datatype dt) -{ - return dt->id.c_str(); -} - -MPI_Datatype Datatype::decode(const std::string& datatype_id) -{ - return id2type_lookup.find(datatype_id)->second; -} - bool Datatype::is_replayable() { return (simgrid::instr::trace_format == simgrid::instr::TraceFormat::Ti) && @@ -233,45 +222,21 @@ bool Datatype::is_replayable() (this == MPI_SHORT) || (this == MPI_LONG) || (this == MPI_FLOAT)); } -size_t Datatype::size(){ - return size_; -} - -int Datatype::flags(){ - return flags_; -} - -int Datatype::refcount(){ - return refcount_; +MPI_Datatype Datatype::decode(const std::string& datatype_id) +{ + return id2type_lookup.find(datatype_id)->second; } void Datatype::addflag(int flag){ flags_ &= flag; } -MPI_Aint Datatype::lb(){ - return lb_; -} - -MPI_Aint Datatype::ub(){ - return ub_; -} - -char* Datatype::name(){ - return name_; -} - - int Datatype::extent(MPI_Aint * lb, MPI_Aint * extent){ *lb = lb_; *extent = ub_ - lb_; return MPI_SUCCESS; } -MPI_Aint Datatype::get_extent(){ - return ub_ - lb_; -} - void Datatype::get_name(char* name, int* length){ *length = strlen(name_); strncpy(name, name_, *length+1); @@ -299,7 +264,6 @@ int Datatype::unpack(void* inbuf, int insize, int* position, void* outbuf, int o return MPI_SUCCESS; } - int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype){ @@ -336,11 +300,11 @@ int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, } //Default serialization method : memcpy. -void Datatype::serialize( void* noncontiguous_buf, void *contiguous_buf, int count){ +void Datatype::serialize(void* noncontiguous_buf, void* contiguous_buf, int count) +{ char* contiguous_buf_char = static_cast(contiguous_buf); char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb_; memcpy(contiguous_buf_char, noncontiguous_buf_char, count*size_); - } void Datatype::unserialize( void* contiguous_buf, void *noncontiguous_buf, int count, MPI_Op op){ diff --git a/src/smpi/mpi/smpi_group.cpp b/src/smpi/mpi/smpi_group.cpp index d4d2d86cde..a6e92a9b72 100644 --- a/src/smpi/mpi/smpi_group.cpp +++ b/src/smpi/mpi/smpi_group.cpp @@ -19,22 +19,10 @@ namespace smpi{ using simgrid::s4u::ActorPtr; -Group::Group() -{ - size_ = 0; /* size */ - refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */ -} - -Group::Group(int n) : size_(n), rank_to_actor_map_(size_, nullptr), index_to_rank_map_(size_, MPI_UNDEFINED) -{ - refcount_ = 1; -} - Group::Group(Group* origin) { if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) { size_ = origin->size(); - refcount_ = 1; // FIXME: cheinrich: There is no such thing as an index any more; the two maps should be removed index_to_rank_map_ = origin->index_to_rank_map_; rank_to_actor_map_ = origin->rank_to_actor_map_; @@ -95,11 +83,6 @@ void Group::unref(Group* group) } } -int Group::size() -{ - return size_; -} - int Group::compare(MPI_Group group2) { int result; diff --git a/src/smpi/mpi/smpi_info.cpp b/src/smpi/mpi/smpi_info.cpp index fb9cef8f39..7b3efad28c 100644 --- a/src/smpi/mpi/smpi_info.cpp +++ b/src/smpi/mpi/smpi_info.cpp @@ -9,11 +9,8 @@ namespace simgrid { namespace smpi { -Info::Info(Info* info) : map_(info->map_) +void Info::ref() { -} - -void Info::ref(){ refcount_++; } @@ -24,10 +21,6 @@ void Info::unref(Info* info){ } } -void Info::set(char *key, char *value){ - map_[key] = value; -} - int Info::get(char *key, int valuelen, char *value, int *flag){ *flag=false; auto val = map_.find(key); diff --git a/src/smpi/mpi/smpi_op.cpp b/src/smpi/mpi/smpi_op.cpp index edd56514b0..e81b93ff0a 100644 --- a/src/smpi/mpi/smpi_op.cpp +++ b/src/smpi/mpi/smpi_op.cpp @@ -217,27 +217,6 @@ CREATE_MPI_OP(MPI_NO_OP, no_func); namespace simgrid{ namespace smpi{ -Op::Op(MPI_User_function * function, bool commutative) : func_(function), is_commutative_(commutative) -{ - is_fortran_op_ = false; -} - -bool Op::is_commutative() -{ - return is_commutative_; -} - -bool Op::is_fortran_op() -{ - return is_fortran_op_; -} - -void Op::set_fortran_op() -{ - //tell that we were created from fortran, so we need to translate the type to fortran when called - is_fortran_op_ = true; -} - void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype) { if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) { diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index b79810ef8b..759f0f52b9 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -71,42 +71,6 @@ Request::Request(void* buf, int count, MPI_Datatype datatype, int src, int dst, cancelled_ = 0; } -MPI_Comm Request::comm(){ - return comm_; -} - -int Request::src(){ - return src_; -} - -int Request::dst(){ - return dst_; -} - -int Request::tag(){ - return tag_; -} - -int Request::flags(){ - return flags_; -} - -int Request::detached(){ - return detached_; -} - -MPI_Datatype Request::type(){ - return old_type_; -} - -size_t Request::size(){ - return size_; -} - -size_t Request::real_size(){ - return real_size_; -} - void Request::ref(){ refcount_++; } -- 2.20.1