Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / colls / bcast-SMP-linear.c
index b999b39..b3f9b6a 100644 (file)
@@ -1,7 +1,10 @@
+/* Copyright (c) 2013-2014. 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. */
+
 #include "colls_private.h"
-#ifndef NUM_CORE
-#define NUM_CORE 8
-#endif
 
 int bcast_SMP_linear_segment_byte = 8192;
 
@@ -21,8 +24,20 @@ int smpi_coll_tuned_bcast_SMP_linear(void *buf, int count,
 
   rank = smpi_comm_rank(comm);
   size = smpi_comm_size(comm);
+  if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
+    smpi_comm_init_smp(comm);
+  }
+  int num_core=1;
+  if (smpi_comm_is_uniform(comm)){
+    num_core = smpi_comm_size(smpi_comm_get_intra_comm(comm));
+  }else{
+    //implementation buggy in this case
+    return smpi_coll_tuned_bcast_mpich( buf , count, datatype,
+              root, comm);
+  }
 
   int segment = bcast_SMP_linear_segment_byte / extent;
+  segment =  segment == 0 ? 1 :segment; 
   int pipe_length = count / segment;
   int remainder = count % segment;
   int increment = segment * extent;
@@ -30,13 +45,13 @@ int smpi_coll_tuned_bcast_SMP_linear(void *buf, int count,
 
   /* leader of each SMP do inter-communication
      and act as a root for intra-communication */
-  int to_inter = (rank + NUM_CORE) % size;
+  int to_inter = (rank + num_core) % size;
   int to_intra = (rank + 1) % size;
-  int from_inter = (rank - NUM_CORE + size) % size;
+  int from_inter = (rank - num_core + size) % size;
   int from_intra = (rank + size - 1) % size;
 
   // call native when MPI communication size is too small
-  if (size <= NUM_CORE) {
+  if (size <= num_core) {
     XBT_WARN("MPI_bcast_SMP_linear use default MPI_bcast.");             
     smpi_mpi_bcast(buf, count, datatype, root, comm);
     return MPI_SUCCESS;            
@@ -56,20 +71,20 @@ int smpi_coll_tuned_bcast_SMP_linear(void *buf, int count,
       smpi_mpi_send(buf, count, datatype, to_intra, tag, comm);
     }
     // case last ROOT of each SMP
-    else if (rank == (((size - 1) / NUM_CORE) * NUM_CORE)) {
+    else if (rank == (((size - 1) / num_core) * num_core)) {
       request = smpi_mpi_irecv(buf, count, datatype, from_inter, tag, comm);
       smpi_mpi_wait(&request, &status);
       smpi_mpi_send(buf, count, datatype, to_intra, tag, comm);
     }
     // case intermediate ROOT of each SMP
-    else if (rank % NUM_CORE == 0) {
+    else if (rank % num_core == 0) {
       request = smpi_mpi_irecv(buf, count, datatype, from_inter, tag, comm);
       smpi_mpi_wait(&request, &status);
       smpi_mpi_send(buf, count, datatype, to_inter, tag, comm);
       smpi_mpi_send(buf, count, datatype, to_intra, tag, comm);
     }
     // case last non-ROOT of each SMP
-    else if (((rank + 1) % NUM_CORE == 0) || (rank == (size - 1))) {
+    else if (((rank + 1) % num_core == 0) || (rank == (size - 1))) {
       request = smpi_mpi_irecv(buf, count, datatype, from_intra, tag, comm);
       smpi_mpi_wait(&request, &status);
     }
@@ -89,7 +104,7 @@ int smpi_coll_tuned_bcast_SMP_linear(void *buf, int count,
         (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status));
 
     // case ROOT of each SMP
-    if (rank % NUM_CORE == 0) {
+    if (rank % num_core == 0) {
       // case real root
       if (rank == 0) {
         for (i = 0; i < pipe_length; i++) {
@@ -100,7 +115,7 @@ int smpi_coll_tuned_bcast_SMP_linear(void *buf, int count,
         }
       }
       // case last ROOT of each SMP
-      else if (rank == (((size - 1) / NUM_CORE) * NUM_CORE)) {
+      else if (rank == (((size - 1) / num_core) * num_core)) {
         for (i = 0; i < pipe_length; i++) {
           request_array[i] = smpi_mpi_irecv((char *) buf + (i * increment), segment, datatype,
                     from_inter, (tag + i), comm);
@@ -126,7 +141,7 @@ int smpi_coll_tuned_bcast_SMP_linear(void *buf, int count,
         }
       }
     } else {                    // case last non-ROOT of each SMP
-      if (((rank + 1) % NUM_CORE == 0) || (rank == (size - 1))) {
+      if (((rank + 1) % num_core == 0) || (rank == (size - 1))) {
         for (i = 0; i < pipe_length; i++) {
           request_array[i] = smpi_mpi_irecv((char *) buf + (i * increment), segment, datatype,
                     from_intra, (tag + i), comm);