Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / smpi / mpi / smpi_topo.cpp
index a512932..48b723d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2014-2023. 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. */
@@ -16,8 +16,7 @@
 static int assignnodes(int ndim, const std::vector<int>& factors, std::vector<int>& dims);
 static int getfactors(int num, std::vector<int>& factors);
 
-namespace simgrid{
-namespace smpi{
+namespace simgrid::smpi {
 
 void Topo::setComm(MPI_Comm comm)
 {
@@ -38,9 +37,6 @@ Topo_Cart::Topo_Cart(int ndims) : ndims_(ndims), dims_(ndims), periodic_(ndims),
 Topo_Cart::Topo_Cart(MPI_Comm comm_old, int ndims, const int dims[], const int periods[], int /*reorder*/, MPI_Comm* comm_cart)
     : Topo_Cart(ndims)
 {
-  MPI_Group newGroup;
-  MPI_Group oldGroup;
-
   int rank = comm_old->rank();
 
   if(ndims != 0) {
@@ -66,10 +62,10 @@ Topo_Cart::Topo_Cart(MPI_Comm comm_old, int ndims, const int dims[], const int p
       position_[i] = rank / nranks;
       rank = rank % nranks;
     }
-    
+
     if(comm_cart != nullptr){
-      oldGroup = comm_old->group();
-      newGroup = new  Group(newSize);
+      const Group* oldGroup = comm_old->group();
+      auto* newGroup        = new Group(newSize);
       for (int i = 0 ; i < newSize ; i++) {
         newGroup->set_mapping(oldGroup->actor(i), i);
       }
@@ -323,8 +319,7 @@ int Topo_Cart::Dims_create(int nnodes, int ndims, int dims[])
   return MPI_SUCCESS;
 }
 
-}
-}
+} // namespace simgrid::smpi
 
 /*
  *  assignnodes
@@ -383,11 +378,13 @@ static int getfactors(int num, std::vector<int>& factors)
     factors.push_back(2);
   }
   /* determine all occurrences of uneven prime numbers up to sqrt(num) */
-  for (int d = 3; (num > 1) && (d * d < num); d += 2) {
+  int d = 3;
+  while ((num > 1) && (d * d < num)) {
     while((num % d) == 0) {
       num /= d;
       factors.push_back(d);
     }
+    d += 2;
   }
   /* as we looped only up to sqrt(num) one factor > sqrt(num) may be left over */
   if(num != 1) {