Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / smpi / colls / bcast / bcast-mvapich-smp.cpp
index 17e9ca0..ff2d754 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2017. The SimGrid Team.
+/* Copyright (c) 2013-2021. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -51,17 +51,17 @@ extern int mv2_intra_node_knomial_factor;
 extern int mv2_bcast_two_level_system_size;
 #define INTRA_NODE_ROOT 0
 
-#define MPIR_Pipelined_Bcast_Zcpy_MV2 Coll_bcast_mpich::bcast
-#define MPIR_Pipelined_Bcast_MV2 Coll_bcast_mpich::bcast
-#define MPIR_Bcast_binomial_MV2 Coll_bcast_binomial_tree::bcast
-#define MPIR_Bcast_scatter_ring_allgather_shm_MV2 Coll_bcast_scatter_LR_allgather::bcast
-#define MPIR_Bcast_scatter_doubling_allgather_MV2 Coll_bcast_scatter_rdb_allgather::bcast
-#define MPIR_Bcast_scatter_ring_allgather_MV2 Coll_bcast_scatter_LR_allgather::bcast
-#define MPIR_Shmem_Bcast_MV2 Coll_bcast_mpich::bcast
-#define MPIR_Bcast_tune_inter_node_helper_MV2 Coll_bcast_mvapich2_inter_node::bcast
-#define MPIR_Bcast_inter_node_helper_MV2 Coll_bcast_mvapich2_inter_node::bcast
-#define MPIR_Knomial_Bcast_intra_node_MV2 Coll_bcast_mvapich2_knomial_intra_node::bcast
-#define MPIR_Bcast_intra_MV2 Coll_bcast_mvapich2_intra_node::bcast
+#define MPIR_Pipelined_Bcast_Zcpy_MV2 bcast__mpich
+#define MPIR_Pipelined_Bcast_MV2 bcast__mpich
+#define MPIR_Bcast_binomial_MV2 bcast__binomial_tree
+#define MPIR_Bcast_scatter_ring_allgather_shm_MV2 bcast__scatter_LR_allgather
+#define MPIR_Bcast_scatter_doubling_allgather_MV2 bcast__scatter_rdb_allgather
+#define MPIR_Bcast_scatter_ring_allgather_MV2 bcast__scatter_LR_allgather
+#define MPIR_Shmem_Bcast_MV2 bcast__mpich
+#define MPIR_Bcast_tune_inter_node_helper_MV2 bcast__mvapich2_inter_node
+#define MPIR_Bcast_inter_node_helper_MV2 bcast__mvapich2_inter_node
+#define MPIR_Knomial_Bcast_intra_node_MV2 bcast__mvapich2_knomial_intra_node
+#define MPIR_Bcast_intra_MV2 bcast__mvapich2_intra_node
 
 extern int zcpy_knomial_factor;
 extern int mv2_pipelined_zcpy_knomial_factor;
@@ -73,13 +73,13 @@ extern int mv2_intra_node_knomial_factor;
 #define mv2_bcast_large_msg            512*1024
 #define mv2_knomial_intra_node_threshold 131072
 #define mv2_scatter_rd_inter_leader_bcast 1
-namespace simgrid{
-namespace smpi{
-int Coll_bcast_mvapich2_inter_node::bcast(void *buffer,
-                                                 int count,
-                                                 MPI_Datatype datatype,
-                                                 int root,
-                                                 MPI_Comm  comm)
+namespace simgrid {
+namespace smpi {
+int bcast__mvapich2_inter_node(void *buffer,
+                               int count,
+                               MPI_Datatype datatype,
+                               int root,
+                               MPI_Comm  comm)
 {
     int rank;
     int mpi_errno = MPI_SUCCESS;
@@ -91,13 +91,12 @@ int Coll_bcast_mvapich2_inter_node::bcast(void *buffer,
     rank = comm->rank();
     //comm_size = comm->size();
 
-
-    if (MV2_Bcast_function==NULL){
-      MV2_Bcast_function=Coll_bcast_mpich::bcast;
+    if (MV2_Bcast_function == nullptr) {
+      MV2_Bcast_function = bcast__mpich;
     }
 
-    if (MV2_Bcast_intra_node_function==NULL){
-      MV2_Bcast_intra_node_function= Coll_bcast_mpich::bcast;
+    if (MV2_Bcast_intra_node_function == nullptr) {
+      MV2_Bcast_intra_node_function = bcast__mpich;
     }
 
     if(comm->get_leaders_comm()==MPI_COMM_NULL){
@@ -170,23 +169,21 @@ int Coll_bcast_mvapich2_inter_node::bcast(void *buffer,
 }
 
 
-int Coll_bcast_mvapich2_knomial_intra_node::bcast(void *buffer,
-                                      int count,
-                                      MPI_Datatype datatype,
-                                      int root, MPI_Comm  comm)
+int bcast__mvapich2_knomial_intra_node(void *buffer,
+                                       int count,
+                                       MPI_Datatype datatype,
+                                       int root, MPI_Comm  comm)
 {
     int local_size = 0, rank;
     int mpi_errno = MPI_SUCCESS;
-    MPI_Request *reqarray = NULL;
-    MPI_Status *starray = NULL;
     int src, dst, mask, relative_rank;
     int k;
-    if (MV2_Bcast_function==NULL){
-      MV2_Bcast_function=Coll_bcast_mpich::bcast;
+    if (MV2_Bcast_function == nullptr) {
+      MV2_Bcast_function = bcast__mpich;
     }
 
-    if (MV2_Bcast_intra_node_function==NULL){
-      MV2_Bcast_intra_node_function= Coll_bcast_mpich::bcast;
+    if (MV2_Bcast_intra_node_function == nullptr) {
+      MV2_Bcast_intra_node_function = bcast__mpich;
     }
 
     if(comm->get_leaders_comm()==MPI_COMM_NULL){
@@ -196,10 +193,9 @@ int Coll_bcast_mvapich2_knomial_intra_node::bcast(void *buffer,
     local_size = comm->size();
     rank = comm->rank();
 
+    auto* reqarray = new MPI_Request[2 * mv2_intra_node_knomial_factor];
 
-    reqarray=(MPI_Request *)xbt_malloc(2 * mv2_intra_node_knomial_factor * sizeof (MPI_Request));
-
-    starray=(MPI_Status *)xbt_malloc(2 * mv2_intra_node_knomial_factor * sizeof (MPI_Status));
+    auto* starray = new MPI_Status[2 * mv2_intra_node_knomial_factor];
 
     /* intra-node k-nomial bcast  */
     if (local_size > 1) {
@@ -240,34 +236,34 @@ int Coll_bcast_mvapich2_knomial_intra_node::bcast(void *buffer,
             mask /= mv2_intra_node_knomial_factor;
         }
     }
-    xbt_free(reqarray);
-    xbt_free(starray);
+    delete[] reqarray;
+    delete[] starray;
     return mpi_errno;
 }
 
 
-int Coll_bcast_mvapich2_intra_node::bcast(void *buffer,
-                         int count,
-                         MPI_Datatype datatype,
-                         int root, MPI_Comm  comm)
+int bcast__mvapich2_intra_node(void *buffer,
+                               int count,
+                               MPI_Datatype datatype,
+                               int root, MPI_Comm  comm)
 {
     int mpi_errno = MPI_SUCCESS;
     int comm_size;
-    int two_level_bcast = 1;
+    bool two_level_bcast = true;
     size_t nbytes = 0;
-    int is_homogeneous, is_contig;
+    bool is_homogeneous, is_contig;
     MPI_Aint type_size;
-    void *tmp_buf = NULL;
+    unsigned char* tmp_buf = nullptr;
     MPI_Comm shmem_comm;
 
     if (count == 0)
         return MPI_SUCCESS;
-    if (MV2_Bcast_function==NULL){
-      MV2_Bcast_function=Coll_bcast_mpich::bcast;
+    if (MV2_Bcast_function == nullptr) {
+      MV2_Bcast_function = bcast__mpich;
     }
 
-    if (MV2_Bcast_intra_node_function==NULL){
-      MV2_Bcast_intra_node_function= Coll_bcast_mpich::bcast;
+    if (MV2_Bcast_intra_node_function == nullptr) {
+      MV2_Bcast_intra_node_function = bcast__mpich;
     }
 
     if(comm->get_leaders_comm()==MPI_COMM_NULL){
@@ -278,16 +274,16 @@ int Coll_bcast_mvapich2_intra_node::bcast(void *buffer,
    // rank = comm->rank();
 /*
     if (HANDLE_GET_KIND(datatype) == HANDLE_KIND_BUILTIN)*/
-        is_contig = 1;
+        is_contig = true;
 /*    else {
         MPID_Datatype_get_ptr(datatype, dtp);
         is_contig = dtp->is_contig;
     }
 */
-    is_homogeneous = 1;
+    is_homogeneous = true;
 #ifdef MPID_HAS_HETERO
     if (comm_ptr->is_hetero)
-        is_homogeneous = 0;
+      is_homogeneous = false;
 #endif
 
     /* MPI_Type_size() might not give the accurate size of the packed
@@ -306,20 +302,20 @@ int Coll_bcast_mvapich2_intra_node::bcast(void *buffer,
     nbytes = (size_t) (count) * (type_size);
     if (comm_size <= mv2_bcast_two_level_system_size) {
         if (nbytes > mv2_bcast_short_msg && nbytes < mv2_bcast_large_msg) {
-            two_level_bcast = 1;
+          two_level_bcast = true;
         } else {
-            two_level_bcast = 0;
+          two_level_bcast = false;
         }
     }
 
-    if (two_level_bcast == 1
+    if (two_level_bcast
 #if defined(_MCST_SUPPORT_)
             || comm_ptr->ch.is_mcast_ok
 #endif
         ) {
 
       if (not is_contig || not is_homogeneous) {
-        tmp_buf = (void*)smpi_get_tmp_sendbuffer(nbytes);
+        tmp_buf = smpi_get_tmp_sendbuffer(nbytes);
 
         /* TODO: Pipeline the packing and communication */
         // position = 0;