Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / smpi_topo.cpp
index 34189dc..432174e 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2014, 2017. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2014-2017. 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. */
@@ -9,6 +8,8 @@
 #include "private.h"
 #include <vector>
 #include <math.h>
+#include "src/smpi/smpi_comm.hpp"
+#include "src/smpi/smpi_topo.hpp"
 
 /* static functions */
 static int assignnodes(int ndim, int nfactor, int *pfacts,int **pdims);
@@ -18,51 +19,47 @@ static int getfactors(int num, int *nfators, int **factors);
 namespace simgrid{
 namespace smpi{
 
-
-Graph::~Graph() 
+Topo_Graph::~Topo_Graph()
 {
-  delete[] m_index;
-  delete[] m_edges;
+  delete[] index_;
+  delete[] edges_;
 }
 
-Dist_Graph::~Dist_Graph() 
+Topo_Dist_Graph::~Topo_Dist_Graph()
 {
-  delete[] m_in;
-  delete[] m_in_weights;
-  delete[] m_out;
-  delete[] m_out_weights;
+  delete[] in_;
+  delete[] in_weights_;
+  delete[] out_;
+  delete[] out_weights_;
 }
 
 /*******************************************************************************
  * Cartesian topologies
  ******************************************************************************/
-Cart::~Cart() 
+Topo_Cart::~Topo_Cart()
 {
-  delete[] m_dims;
-  delete[] m_periodic;
-  delete[] m_position;
+  delete[] dims_;
+  delete[] periodic_;
+  delete[] position_;
 }
 
-Cart::Cart(int ndims)
+Topo_Cart::Topo_Cart(int ndims) : ndims_(ndims)
 {
-  m_nnodes = 0;
-  m_ndims = ndims;
-  m_dims = new int[ndims];
-  m_periodic = new int[ndims];
-  m_position = new int[ndims];
+  dims_ = new int[ndims];
+  periodic_ = new int[ndims];
+  position_ = new int[ndims];
 }
 
 /* reorder is ignored, don't know what would be the consequences of a dumb reordering but neither do I see the point of
  * reordering*/
-Cart::Cart(MPI_Comm comm_old, int ndims, int dims[], int periods[], int reorder, MPI_Comm *comm_cart) : Cart(ndims) {
+Topo_Cart::Topo_Cart(MPI_Comm comm_old, int ndims, int dims[], int periods[], int reorder, MPI_Comm *comm_cart) : Topo_Cart(ndims) {
   MPI_Group newGroup;
   MPI_Group oldGroup;
-  int nranks;
 
   int rank = comm_old->rank();
 
-  int newSize = 1;
   if(ndims != 0) {
+    int newSize = 1;
     for (int i = 0 ; i < ndims ; i++) {
       newSize *= dims[i];
     }
@@ -71,38 +68,37 @@ Cart::Cart(MPI_Comm comm_old, int ndims, int dims[], int periods[], int reorder,
       return;
     }
     oldGroup = comm_old->group();
-    newGroup = new simgrid::smpi::Group(newSize);
+    newGroup = new  Group(newSize);
     for (int i = 0 ; i < newSize ; i++) {
       newGroup->set_mapping(oldGroup->index(i), i);
     }
 
-    m_nnodes = newSize;
+    nnodes_ = newSize;
 
     //  FIXME : code duplication... See coords
-    nranks = newSize;
+    int nranks = newSize;
     for (int i=0; i<ndims; i++) {
-      m_dims[i] = dims[i];
-     m_periodic[i] = periods[i];
+      dims_[i] = dims[i];
+     periodic_[i] = periods[i];
       nranks = nranks / dims[i];
       /* FIXME: nranks could be zero (?) */
-      m_position[i] = rank / nranks;
+      position_[i] = rank / nranks;
       rank = rank % nranks;
     }
 
-    *comm_cart = new simgrid::smpi::Comm(newGroup, this);
+    *comm_cart = new  Comm(newGroup, this);
   } else {
     if (rank == 0) {
-      *comm_cart = new simgrid::smpi::Comm(new simgrid::smpi::Group(MPI_COMM_SELF->group()), this);
+      *comm_cart = new  Comm(new  Group(MPI_COMM_SELF->group()), this);
     } else {
       *comm_cart = MPI_COMM_NULL;
     }
   }
-  m_comm=*comm_cart;
+  comm_=*comm_cart;
 }
 
-Cart* Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
-  int oldNDims = m_ndims;
-  int j = 0;
+Topo_Cart* Topo_Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
+  int oldNDims = ndims_;
   int *newDims = nullptr;
   int *newPeriodic = nullptr;
 
@@ -120,62 +116,62 @@ Cart* Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
     newPeriodic = xbt_new(int, newNDims);
 
     // that should not segfault
+    int j = 0;
     for (int i = 0 ; j < newNDims ; i++) {
       if(remain_dims[i]) {
-        newDims[j] =m_dims[i];
-        newPeriodic[j] =m_periodic[i];
+        newDims[j] =dims_[i];
+        newPeriodic[j] =periodic_[i];
         j++;
       }
     }
   }
-  return new Cart(m_comm, newNDims, newDims, newPeriodic, 0, newcomm);
+  return new Topo_Cart(comm_, newNDims, newDims, newPeriodic, 0, newcomm);
 }
 
-int Cart::coords(int rank, int maxdims, int coords[]) {
-  int nnodes = m_nnodes;
-  for (int i = 0; i< m_ndims; i++ ) {
-    nnodes    = nnodes /m_dims[i];
+int Topo_Cart::coords(int rank, int maxdims, int coords[]) {
+  int nnodes = nnodes_;
+  for (int i = 0; i< ndims_; i++ ) {
+    nnodes    = nnodes /dims_[i];
     coords[i] = rank / nnodes;
     rank      = rank % nnodes;
   }
   return MPI_SUCCESS;
 }
 
-int Cart::get(int maxdims, int* dims, int* periods, int* coords) {
-  int ndims=m_ndims < maxdims ?m_ndims : maxdims;
+int Topo_Cart::get(int maxdims, int* dims, int* periods, int* coords) {
+  int ndims=ndims_ < maxdims ?ndims_ : maxdims;
   for(int i = 0 ; i < ndims ; i++) {
-    dims[i] =m_dims[i];
-    periods[i] =m_periodic[i];
-    coords[i] =m_position[i];
+    dims[i] =dims_[i];
+    periods[i] =periodic_[i];
+    coords[i] =position_[i];
   }
   return MPI_SUCCESS;
 }
 
-int Cart::rank(int* coords, int* rank) {
-  int ndims =m_ndims;
-  int coord;
+int Topo_Cart::rank(int* coords, int* rank) {
+  int ndims =ndims_;
   *rank = 0;
   int multiplier = 1;
 
   for (int i=ndims-1; i >=0; i-- ) {
-    coord = coords[i];
+    int coord = coords[i];
 
     /* The user can give us whatever coordinates he wants. If one of them is out of range, either this dimension is
      * periodic, and we consider the equivalent coordinate inside the bounds, or it's not and then it's an error
      */
-    if (coord >=m_dims[i]) {
-      if (m_periodic[i] ) {
-        coord = coord %m_dims[i];
+    if (coord >=dims_[i]) {
+      if (periodic_[i] ) {
+        coord = coord %dims_[i];
       } else {
         // Should I do that ?
         *rank = -1;
         return MPI_ERR_ARG;
       }
     } else if (coord <  0) {
-      if(m_periodic[i]) {
-        coord = coord %m_dims[i];
+      if(periodic_[i]) {
+        coord = coord %dims_[i];
         if (coord)
-          coord =m_dims[i] + coord;
+          coord =dims_[i] + coord;
       } else {
         *rank = -1;
         return MPI_ERR_ARG;
@@ -183,29 +179,29 @@ int Cart::rank(int* coords, int* rank) {
     }
 
     *rank += multiplier * coord;
-    multiplier *=m_dims[i];
+    multiplier *=dims_[i];
   }
   return MPI_SUCCESS;
 }
 
-int Cart::shift(int direction, int disp, int *rank_source, int *rank_dest) {
+int Topo_Cart::shift(int direction, int disp, int *rank_source, int *rank_dest) {
 
-  int position[m_ndims];
+  int position[ndims_];
 
-  if(m_ndims == 0) {
+  if(ndims_ == 0) {
     return MPI_ERR_ARG;
   }
-  if (m_ndims < direction) {
+  if (ndims_ < direction) {
     return MPI_ERR_DIMS;
   }
 
-  this->coords(m_comm->rank(),m_ndims, position);
+  this->coords(comm_->rank(),ndims_, position);
   position[direction] += disp;
 
   if(position[direction] < 0 ||
-      position[direction] >=m_dims[direction]) {
-    if(m_periodic[direction]) {
-      position[direction] %=m_dims[direction];
+      position[direction] >=dims_[direction]) {
+    if(periodic_[direction]) {
+      position[direction] %=dims_[direction];
       this->rank(position, rank_dest);
     } else {
       *rank_dest = MPI_PROC_NULL;
@@ -214,10 +210,10 @@ int Cart::shift(int direction, int disp, int *rank_source, int *rank_dest) {
     this->rank(position, rank_dest);
   }
 
-  position[direction] = m_position[direction] - disp;
-  if(position[direction] < 0 || position[direction] >=m_dims[direction]) {
-    if(m_periodic[direction]) {
-      position[direction] %=m_dims[direction];
+  position[direction] = position_[direction] - disp;
+  if(position[direction] < 0 || position[direction] >=dims_[direction]) {
+    if(periodic_[direction]) {
+      position[direction] %=dims_[direction];
       this->rank(position, rank_source);
     } else {
       *rank_source = MPI_PROC_NULL;
@@ -229,8 +225,8 @@ int Cart::shift(int direction, int disp, int *rank_source, int *rank_dest) {
   return MPI_SUCCESS;
 }
 
-int Cart::dim_get(int *ndims) {
-  *ndims =m_ndims;
+int Topo_Cart::dim_get(int *ndims) {
+  *ndims =ndims_;
   return MPI_SUCCESS;
 }
 
@@ -243,12 +239,12 @@ int Cart::dim_get(int *ndims) {
  * Copyright (c) 2004-2005 The University of Tennessee and The University
  *                         of Tennessee Research Foundation.  All rights
  *                         reserved.
- * Copyright (c) 2004-2014 High Performance Computing Center Stuttgart, 
+ * Copyright (c) 2004-2014 High Performance Computing Center Stuttgart,
  *                         University of Stuttgart.  All rights reserved.
  * Copyright (c) 2004-2005 The Regents of the University of California.
  *                         All rights reserved.
  * Copyright (c) 2012      Los Alamos National Security, LLC.  All rights
- *                         reserved. 
+ *                         reserved.
  * Copyright (c) 2014      Intel, Inc. All rights reserved
  * $COPYRIGHT$
  *
@@ -257,11 +253,10 @@ int Cart::dim_get(int *ndims) {
  * $HEADER$
  */
 
-
 /*
  * This is a utility function, no need to have anything in the lower layer for this at all
  */
-int Dims_create(int nnodes, int ndims, int dims[])
+int Topo_Cart::Dims_create(int nnodes, int ndims, int dims[])
 {
   /* Get # of free-to-be-assigned processes and # of free dimensions */
   int freeprocs = nnodes;