Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branches 'master' and 'master' of github.com:simgrid/simgrid
[simgrid.git] / src / smpi / colls / smpi_mpich_selector.cpp
index 7ab6a1b..7fd3910 100644 (file)
@@ -1,6 +1,6 @@
 /* selector for collective algorithms based on mpich decision logic */
 
-/* Copyright (c) 2009-2010, 2013-2014. The SimGrid Team.
+/* Copyright (c) 2009-2010, 2013-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 
    End Algorithm: MPI_Allreduce
 */
-int smpi_coll_tuned_allreduce_mpich(void *sbuf, void *rbuf, int count,
+namespace simgrid{
+namespace smpi{
+int Coll_allreduce_mpich::allreduce(void *sbuf, void *rbuf, int count,
                         MPI_Datatype dtype, MPI_Op op, MPI_Comm comm)
 {
     size_t dsize, block_dsize;
-    int comm_size = smpi_comm_size(comm);
+    int comm_size = comm->size();
     const size_t large_message = 2048; //MPIR_PARAM_ALLREDUCE_SHORT_MSG_SIZE
 
-    dsize = smpi_datatype_size(dtype);
+    dsize = dtype->size();
     block_dsize = dsize * count;
 
 
@@ -72,14 +74,14 @@ int smpi_coll_tuned_allreduce_mpich(void *sbuf, void *rbuf, int count,
     while (pof2 <= comm_size) pof2 <<= 1;
     pof2 >>=1;
 
-    if (block_dsize > large_message && count >= pof2 && smpi_op_is_commute(op)) {
+    if (block_dsize > large_message && count >= pof2 && (op==MPI_OP_NULL || op->is_commutative())) {
       //for long messages
-       return (smpi_coll_tuned_allreduce_rab_rdb (sbuf, rbuf, 
+       return (Coll_allreduce_rab_rdb::allreduce (sbuf, rbuf, 
                                                                    count, dtype,
                                                                    op, comm));
     }else {
       //for short ones and count < pof2
-      return (smpi_coll_tuned_allreduce_rdb (sbuf, rbuf, 
+      return (Coll_allreduce_rdb::allreduce (sbuf, rbuf, 
                                                                    count, dtype,
                                                                    op, comm));
     }
@@ -132,7 +134,7 @@ int smpi_coll_tuned_allreduce_mpich(void *sbuf, void *rbuf, int count,
    End Algorithm: MPI_Alltoall
 */
 
-int smpi_coll_tuned_alltoall_mpich( void *sbuf, int scount, 
+int Coll_alltoall_mpich::alltoall( void *sbuf, int scount, 
                                              MPI_Datatype sdtype,
                                              void* rbuf, int rcount, 
                                              MPI_Datatype rdtype, 
@@ -140,7 +142,7 @@ int smpi_coll_tuned_alltoall_mpich( void *sbuf, int scount,
 {
     int communicator_size;
     size_t dsize, block_dsize;
-    communicator_size = smpi_comm_size(comm);
+    communicator_size = comm->size();
 
     unsigned int short_size=256;
     unsigned int medium_size=32768;
@@ -158,30 +160,30 @@ int smpi_coll_tuned_alltoall_mpich( void *sbuf, int scount,
 //   and sends to (rank+i). 
 
 
-    dsize = smpi_datatype_size(sdtype);
+    dsize = sdtype->size();
     block_dsize = dsize * scount;
 
     if ((block_dsize < short_size) && (communicator_size >= 8)) {
-        return smpi_coll_tuned_alltoall_bruck(sbuf, scount, sdtype, 
+        return Coll_alltoall_bruck::alltoall(sbuf, scount, sdtype, 
                                                     rbuf, rcount, rdtype,
                                                     comm);
 
     } else if (block_dsize < medium_size) {
-        return smpi_coll_tuned_alltoall_basic_linear(sbuf, scount, sdtype, 
+        return Coll_alltoall_basic_linear::alltoall(sbuf, scount, sdtype, 
                                                            rbuf, rcount, rdtype, 
                                                            comm);
     }else if (communicator_size%2){
-        return smpi_coll_tuned_alltoall_ring(sbuf, scount, sdtype, 
+        return Coll_alltoall_ring::alltoall(sbuf, scount, sdtype, 
                                                            rbuf, rcount, rdtype, 
                                                            comm);
     }
 
-    return smpi_coll_tuned_alltoall_ring (sbuf, scount, sdtype,
+    return Coll_alltoall_ring::alltoall (sbuf, scount, sdtype,
                                                     rbuf, rcount, rdtype,
                                                     comm);
 }
 
-int smpi_coll_tuned_alltoallv_mpich(void *sbuf, int *scounts, int *sdisps,
+int Coll_alltoallv_mpich::alltoallv(void *sbuf, int *scounts, int *sdisps,
                                               MPI_Datatype sdtype,
                                               void *rbuf, int *rcounts, int *rdisps,
                                               MPI_Datatype rdtype,
@@ -189,15 +191,15 @@ int smpi_coll_tuned_alltoallv_mpich(void *sbuf, int *scounts, int *sdisps,
                                               )
 {
     /* For starters, just keep the original algorithm. */
-    return smpi_coll_tuned_alltoallv_bruck(sbuf, scounts, sdisps, sdtype, 
+    return Coll_alltoallv_bruck::alltoallv(sbuf, scounts, sdisps, sdtype, 
                                                         rbuf, rcounts, rdisps,rdtype,
                                                         comm);
 }
 
 
-int smpi_coll_tuned_barrier_mpich(MPI_Comm  comm)
+int Coll_barrier_mpich::barrier(MPI_Comm  comm)
 {   
-    return smpi_coll_tuned_barrier_ompi_bruck(comm);
+    return Coll_barrier_ompi_bruck::barrier(comm);
 }
 
 /* This is the default implementation of broadcast. The algorithm is:
@@ -243,7 +245,7 @@ int smpi_coll_tuned_barrier_mpich(MPI_Comm  comm)
 */
 
 
-int smpi_coll_tuned_bcast_mpich(void *buff, int count,
+int Coll_bcast_mpich::bcast(void *buff, int count,
                                           MPI_Datatype datatype, int root,
                                           MPI_Comm  comm
                                           )
@@ -257,27 +259,27 @@ int smpi_coll_tuned_bcast_mpich(void *buff, int count,
     //int segsize = 0;
     size_t message_size, dsize;
 
-    communicator_size = smpi_comm_size(comm);
+    communicator_size = comm->size();
 
     /* else we need data size for decision function */
-    dsize = smpi_datatype_size(datatype);
+    dsize = datatype->size();
     message_size = dsize * (unsigned long)count;   /* needed for decision */
 
     /* Handle messages of small and intermediate size, and 
        single-element broadcasts */
     if ((message_size < small_message_size) || (communicator_size <= 8)) {
         /* Binomial without segmentation */
-        return  smpi_coll_tuned_bcast_binomial_tree (buff, count, datatype, 
+        return  Coll_bcast_binomial_tree::bcast (buff, count, datatype, 
                                                       root, comm);
 
     } else if (message_size < intermediate_message_size && !(communicator_size%2)) {
         // SplittedBinary with 1KB segments
-        return smpi_coll_tuned_bcast_scatter_rdb_allgather(buff, count, datatype, 
+        return Coll_bcast_scatter_rdb_allgather::bcast(buff, count, datatype, 
                                                          root, comm);
 
     }
      //Handle large message sizes 
-     return smpi_coll_tuned_bcast_scatter_LR_allgather (buff, count, datatype, 
+     return Coll_bcast_scatter_LR_allgather::bcast (buff, count, datatype, 
                                                      root, comm);
                                                          
 }
@@ -339,7 +341,7 @@ int smpi_coll_tuned_bcast_mpich(void *buff, int count,
 */
 
 
-int smpi_coll_tuned_reduce_mpich( void *sendbuf, void *recvbuf,
+int Coll_reduce_mpich::reduce( void *sendbuf, void *recvbuf,
                                             int count, MPI_Datatype  datatype,
                                             MPI_Op   op, int root,
                                             MPI_Comm   comm
@@ -348,21 +350,20 @@ int smpi_coll_tuned_reduce_mpich( void *sendbuf, void *recvbuf,
     int communicator_size=0;
     //int segsize = 0;
     size_t message_size, dsize;
-    communicator_size = smpi_comm_size(comm);
+    communicator_size = comm->size();
 
     /* need data size for decision function */
-    dsize=smpi_datatype_size(datatype);
+    dsize=datatype->size();
     message_size = dsize * count;   /* needed for decision */
 
     int pof2 = 1;
     while (pof2 <= communicator_size) pof2 <<= 1;
     pof2 >>= 1;
 
-
-    if ((count < pof2) || (message_size < 2048) || !smpi_op_is_commute(op)) {
-        return smpi_coll_tuned_reduce_binomial (sendbuf, recvbuf, count, datatype, op, root, comm); 
+    if ((count < pof2) || (message_size < 2048) || (op != MPI_OP_NULL && not op->is_commutative())) {
+      return Coll_reduce_binomial::reduce(sendbuf, recvbuf, count, datatype, op, root, comm); 
     }
-        return smpi_coll_tuned_reduce_scatter_gather(sendbuf, recvbuf, count, datatype, op, root, comm/*, module,
+        return Coll_reduce_scatter_gather::reduce(sendbuf, recvbuf, count, datatype, op, root, comm/*, module,
                                                      segsize, max_requests*/);
 }
 
@@ -416,7 +417,7 @@ int smpi_coll_tuned_reduce_mpich( void *sendbuf, void *recvbuf,
 */
 
 
-int smpi_coll_tuned_reduce_scatter_mpich( void *sbuf, void *rbuf,
+int Coll_reduce_scatter_mpich::reduce_scatter( void *sbuf, void *rbuf,
                                                     int *rcounts,
                                                     MPI_Datatype dtype,
                                                     MPI_Op  op,
@@ -428,40 +429,41 @@ int smpi_coll_tuned_reduce_scatter_mpich( void *sbuf, void *rbuf,
 
     if(sbuf==rbuf)sbuf=MPI_IN_PLACE; //restore MPI_IN_PLACE as these algorithms handle it
 
-    XBT_DEBUG("smpi_coll_tuned_reduce_scatter_mpich");
+    XBT_DEBUG("Coll_reduce_scatter_mpich::reduce");
     
-    comm_size = smpi_comm_size(comm);
+    comm_size = comm->size();
     // We need data size for decision function 
     total_message_size = 0;
     for (i = 0; i < comm_size; i++) { 
         total_message_size += rcounts[i];
     }
 
-    if( smpi_op_is_commute(op) &&  total_message_size > 524288) { 
-        return smpi_coll_tuned_reduce_scatter_mpich_pair (sbuf, rbuf, rcounts, 
+    if( (op==MPI_OP_NULL || op->is_commutative()) &&  total_message_size > 524288) { 
+        return Coll_reduce_scatter_mpich_pair::reduce_scatter (sbuf, rbuf, rcounts, 
                                                                     dtype, op, 
-                                                                    comm); 
-    }else if (!smpi_op_is_commute(op)) {
-        int is_block_regular = 1;
-        for (i = 0; i < (comm_size - 1); ++i) {
-            if (rcounts[i] != rcounts[i+1]) {
-                is_block_regular = 0;
-                break;
-            }
+                                                                    comm);
+    } else if ((op != MPI_OP_NULL && not op->is_commutative())) {
+      int is_block_regular = 1;
+      for (i = 0; i < (comm_size - 1); ++i) {
+        if (rcounts[i] != rcounts[i + 1]) {
+          is_block_regular = 0;
+          break;
         }
+      }
 
-        /* slightly retask pof2 to mean pof2 equal or greater, not always greater as it is above */
-        int pof2 = 1;
-        while (pof2 < comm_size) pof2 <<= 1;
+      /* slightly retask pof2 to mean pof2 equal or greater, not always greater as it is above */
+      int pof2 = 1;
+      while (pof2 < comm_size)
+        pof2 <<= 1;
 
-        if (pof2 == comm_size && is_block_regular) {
-            /* noncommutative, pof2 size, and block regular */
-            return smpi_coll_tuned_reduce_scatter_mpich_noncomm(sbuf, rbuf, rcounts, dtype, op, comm);
-        }
+      if (pof2 == comm_size && is_block_regular) {
+        /* noncommutative, pof2 size, and block regular */
+        return Coll_reduce_scatter_mpich_noncomm::reduce_scatter(sbuf, rbuf, rcounts, dtype, op, comm);
+      }
 
-       return smpi_coll_tuned_reduce_scatter_mpich_rdb(sbuf, rbuf, rcounts, dtype, op, comm);
+      return Coll_reduce_scatter_mpich_rdb::reduce_scatter(sbuf, rbuf, rcounts, dtype, op, comm);
     }else{      
-       return smpi_coll_tuned_reduce_scatter_mpich_rdb(sbuf, rbuf, rcounts, dtype, op, comm);
+       return Coll_reduce_scatter_mpich_rdb::reduce_scatter(sbuf, rbuf, rcounts, dtype, op, comm);
     }
 }
 
@@ -511,7 +513,7 @@ int smpi_coll_tuned_reduce_scatter_mpich( void *sbuf, void *rbuf,
    End Algorithm: MPI_Allgather
 */
 
-int smpi_coll_tuned_allgather_mpich(void *sbuf, int scount, 
+int Coll_allgather_mpich::allgather(void *sbuf, int scount, 
                                               MPI_Datatype sdtype,
                                               void* rbuf, int rcount, 
                                               MPI_Datatype rdtype, 
@@ -521,10 +523,10 @@ int smpi_coll_tuned_allgather_mpich(void *sbuf, int scount,
     int communicator_size, pow2_size;
     size_t dsize, total_dsize;
 
-    communicator_size = smpi_comm_size(comm);
+    communicator_size = comm->size();
 
     /* Determine complete data size */
-    dsize=smpi_datatype_size(sdtype);
+    dsize=sdtype->size();
     total_dsize = dsize * scount * communicator_size;   
    
     for (pow2_size  = 1; pow2_size < communicator_size; pow2_size <<=1); 
@@ -539,15 +541,15 @@ int smpi_coll_tuned_allgather_mpich(void *sbuf, int scount,
        - for everything else use ring.
     */
     if ((pow2_size == communicator_size) && (total_dsize < 524288)) {
-        return smpi_coll_tuned_allgather_rdb(sbuf, scount, sdtype, 
+        return Coll_allgather_rdb::allgather(sbuf, scount, sdtype, 
                                                                  rbuf, rcount, rdtype, 
                                                                  comm);
     } else if (total_dsize <= 81920) { 
-        return smpi_coll_tuned_allgather_bruck(sbuf, scount, sdtype, 
+        return Coll_allgather_bruck::allgather(sbuf, scount, sdtype, 
                                                      rbuf, rcount, rdtype,
                                                      comm);
     } 
-    return smpi_coll_tuned_allgather_ring(sbuf, scount, sdtype, 
+    return Coll_allgather_ring::allgather(sbuf, scount, sdtype, 
                                                 rbuf, rcount, rdtype,
                                                 comm);
 }
@@ -589,7 +591,7 @@ int smpi_coll_tuned_allgather_mpich(void *sbuf, int scount,
 
    End Algorithm: MPI_Allgatherv
 */
-int smpi_coll_tuned_allgatherv_mpich(void *sbuf, int scount, 
+int Coll_allgatherv_mpich::allgatherv(void *sbuf, int scount, 
                                                MPI_Datatype sdtype,
                                                void* rbuf, int *rcounts, 
                                                int *rdispls,
@@ -600,7 +602,7 @@ int smpi_coll_tuned_allgatherv_mpich(void *sbuf, int scount,
     int communicator_size, pow2_size,i;
     size_t total_dsize;
 
-    communicator_size = smpi_comm_size(comm);
+    communicator_size = comm->size();
 
     /* Determine complete data size */
     total_dsize = 0;
@@ -612,15 +614,15 @@ int smpi_coll_tuned_allgatherv_mpich(void *sbuf, int scount,
     for (pow2_size  = 1; pow2_size < communicator_size; pow2_size <<=1); 
 
     if ((pow2_size == communicator_size) && (total_dsize < 524288)) {
-        return smpi_coll_tuned_allgatherv_mpich_rdb(sbuf, scount, sdtype, 
+        return Coll_allgatherv_mpich_rdb::allgatherv(sbuf, scount, sdtype, 
                                                                  rbuf, rcounts, rdispls, rdtype, 
                                                                  comm);
     } else if (total_dsize <= 81920) { 
-        return smpi_coll_tuned_allgatherv_ompi_bruck(sbuf, scount, sdtype, 
+        return Coll_allgatherv_ompi_bruck::allgatherv(sbuf, scount, sdtype, 
                                                      rbuf, rcounts, rdispls, rdtype,
                                                      comm);
     } 
-    return smpi_coll_tuned_allgatherv_mpich_ring(sbuf, scount, sdtype,
+    return Coll_allgatherv_mpich_ring::allgatherv(sbuf, scount, sdtype,
                                                 rbuf, rcounts, rdispls, rdtype,
                                                 comm);
 }
@@ -647,7 +649,7 @@ int smpi_coll_tuned_allgatherv_mpich(void *sbuf, int scount,
    End Algorithm: MPI_Gather
 */
 
-int smpi_coll_tuned_gather_mpich(void *sbuf, int scount, 
+int Coll_gather_mpich::gather(void *sbuf, int scount, 
                                            MPI_Datatype sdtype,
                                            void* rbuf, int rcount, 
                                            MPI_Datatype rdtype, 
@@ -655,7 +657,7 @@ int smpi_coll_tuned_gather_mpich(void *sbuf, int scount,
                                            MPI_Comm  comm
                                            )
 {
-        return smpi_coll_tuned_gather_ompi_binomial (sbuf, scount, sdtype, 
+        return Coll_gather_ompi_binomial::gather (sbuf, scount, sdtype, 
                                                       rbuf, rcount, rdtype, 
                                                       root, comm);
 }
@@ -682,24 +684,26 @@ int smpi_coll_tuned_gather_mpich(void *sbuf, int scount,
 */
 
 
-int smpi_coll_tuned_scatter_mpich(void *sbuf, int scount, 
+int Coll_scatter_mpich::scatter(void *sbuf, int scount, 
                                             MPI_Datatype sdtype,
                                             void* rbuf, int rcount, 
                                             MPI_Datatype rdtype, 
                                             int root, MPI_Comm  comm
                                             )
 {
-  if(smpi_comm_rank(comm)!=root){
-      sbuf=xbt_malloc(rcount*smpi_datatype_get_extent(rdtype));
+  if(comm->rank()!=root){
+      sbuf=xbt_malloc(rcount*rdtype->get_extent());
       scount=rcount;
       sdtype=rdtype;
   }
-  int ret= smpi_coll_tuned_scatter_ompi_binomial (sbuf, scount, sdtype,
+  int ret= Coll_scatter_ompi_binomial::scatter (sbuf, scount, sdtype,
                                                        rbuf, rcount, rdtype, 
                                                        root, comm);
-  if(smpi_comm_rank(comm)!=root){
+  if(comm->rank()!=root){
       xbt_free(sbuf);
   }
   return ret;
 }
+}
+}