-/* 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. */
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)
{
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) {
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);
}
Topo_Cart* Topo_Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
int oldNDims = ndims_;
- int *newDims = nullptr;
- int *newPeriodic = nullptr;
+ std::vector<int> newDims;
+ std::vector<int> newPeriodic;
if (remain_dims == nullptr && oldNDims != 0) {
return nullptr;
}
if (newNDims > 0) {
- newDims = new int[newNDims];
- newPeriodic = new int[newNDims];
+ newDims.resize(newNDims);
+ newPeriodic.resize(newNDims);
// that should not segfault
int j = 0;
}
Topo_Cart* res;
if (newNDims == 0){
- res = new Topo_Cart(getComm(), newNDims, newDims, newPeriodic, 0, newcomm);
+ res = new Topo_Cart(getComm(), newNDims, newDims.data(), newPeriodic.data(), 0, newcomm);
} else {
*newcomm = getComm()->split(color, getComm()->rank());
- auto topo = std::make_shared<Topo_Cart>(getComm(), newNDims, newDims, newPeriodic, 0, nullptr);
+ auto topo = std::make_shared<Topo_Cart>(getComm(), newNDims, newDims.data(), newPeriodic.data(), 0, nullptr);
res = topo.get();
res->setComm(*newcomm);
(*newcomm)->set_topo(topo);
}
- delete[] newDims;
- delete[] newPeriodic;
return res;
}
return MPI_ERR_DIMS;
}
- auto* position = new int[ndims_];
- this->coords(getComm()->rank(), ndims_, position);
+ std::vector<int> position(ndims_);
+ this->coords(getComm()->rank(), ndims_, position.data());
position[direction] += disp;
if(position[direction] < 0 ||
position[direction] >=dims_[direction]) {
if(periodic_[direction]) {
position[direction] %=dims_[direction];
- this->rank(position, rank_dest);
+ this->rank(position.data(), rank_dest);
} else {
*rank_dest = MPI_PROC_NULL;
}
} else {
- this->rank(position, rank_dest);
+ this->rank(position.data(), rank_dest);
}
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);
+ this->rank(position.data(), rank_source);
} else {
*rank_source = MPI_PROC_NULL;
}
} else {
- this->rank(position, rank_source);
+ this->rank(position.data(), rank_source);
}
- delete[] position;
return MPI_SUCCESS;
}
return MPI_SUCCESS;
}
-}
-}
+} // namespace simgrid::smpi
/*
* assignnodes
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) {