-/* Copyright (c) 2013-2019. The SimGrid Team.
+/* Copyright (c) 2013-2022. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
if (fanout<1) {
XBT_DEBUG("coll:tuned:topo_build_tree invalid fanout %d", fanout);
- return NULL;
+ return nullptr;
}
if (fanout>MAXTREEFANOUT) {
XBT_DEBUG("coll:tuned:topo_build_tree invalid fanout %d bigger than max %d", fanout, MAXTREEFANOUT);
- return NULL;
+ return nullptr;
}
/*
tree = new ompi_coll_tree_t;
if (not tree) {
XBT_DEBUG("coll:tuned:topo_build_tree PANIC::out of memory");
- return NULL;
+ return nullptr;
}
- tree->tree_root = MPI_UNDEFINED;
- tree->tree_nextsize = MPI_UNDEFINED;
-
- /*
- * Set root
- */
- tree->tree_root = root;
-
/*
* Initialize tree
*/
tree = new ompi_coll_tree_t;
if (not tree) {
XBT_DEBUG("coll:tuned:topo_build_tree PANIC::out of memory");
- return NULL;
+ return nullptr;
}
- tree->tree_root = MPI_UNDEFINED;
- tree->tree_nextsize = MPI_UNDEFINED;
-
/*
* Initialize tree
*/
parent = size - 1;
delta = 0;
- while ( 1 ) {
- /* Compute the size of the right subtree */
- int rightsize = size >> 1;
-
- /* Determine the left and right child of this parent */
- int lchild = -1;
- int rchild = -1;
- if (size - 1 > 0) {
- lchild = parent - 1;
- if (lchild > 0) {
- rchild = rightsize - 1;
- }
+ while (true) {
+ /* Compute the size of the right subtree */
+ int rightsize = size >> 1;
+
+ /* Determine the left and right child of this parent */
+ int lchild = -1;
+ int rchild = -1;
+ if (size - 1 > 0) {
+ lchild = parent - 1;
+ if (lchild > 0) {
+ rchild = rightsize - 1;
}
+ }
- /* The following cases are possible: myrank can be
- - a parent,
- - belong to the left subtree, or
- - belong to the right subtee
- Each of the cases need to be handled differently.
+ /* The following cases are possible: myrank can be
+ - a parent,
+ - belong to the left subtree, or
+ - belong to the right subtee
+ Each of the cases need to be handled differently.
+ */
+
+ if (myrank == parent) {
+ /* I am the parent:
+ - compute real ranks of my children, and exit the loop. */
+ if (lchild >= 0)
+ tree->tree_next[0] = lchild + delta;
+ if (rchild >= 0)
+ tree->tree_next[1] = rchild + delta;
+ break;
+ }
+ if (myrank > rchild) {
+ /* I belong to the left subtree:
+ - If I am the left child, compute real rank of my parent
+ - Iterate down through tree:
+ compute new size, shift ranks down, and update delta.
*/
-
- if (myrank == parent) {
- /* I am the parent:
- - compute real ranks of my children, and exit the loop. */
- if (lchild >= 0) tree->tree_next[0] = lchild + delta;
- if (rchild >= 0) tree->tree_next[1] = rchild + delta;
- break;
+ if (myrank == lchild) {
+ tree->tree_prev = parent + delta;
}
- if (myrank > rchild) {
- /* I belong to the left subtree:
- - If I am the left child, compute real rank of my parent
- - Iterate down through tree:
- compute new size, shift ranks down, and update delta.
- */
- if (myrank == lchild) {
- tree->tree_prev = parent + delta;
- }
- size = size - rightsize - 1;
- delta = delta + rightsize;
- myrank = myrank - rightsize;
- parent = size - 1;
-
- } else {
- /* I belong to the right subtree:
- - If I am the right child, compute real rank of my parent
- - Iterate down through tree:
- compute new size and parent,
- but the delta and rank do not need to change.
- */
- if (myrank == rchild) {
- tree->tree_prev = parent + delta;
- }
- size = rightsize;
- parent = rchild;
+ size = size - rightsize - 1;
+ delta = delta + rightsize;
+ myrank = myrank - rightsize;
+ parent = size - 1;
+
+ } else {
+ /* I belong to the right subtree:
+ - If I am the right child, compute real rank of my parent
+ - Iterate down through tree:
+ compute new size and parent,
+ but the delta and rank do not need to change.
+ */
+ if (myrank == rchild) {
+ tree->tree_prev = parent + delta;
}
+ size = rightsize;
+ parent = rchild;
+ }
}
if (tree->tree_next[0] >= 0) { tree->tree_nextsize = 1; }
ptr = *tree;
delete ptr;
- *tree = NULL; /* mark tree as gone */
+ *tree = nullptr; /* mark tree as gone */
return MPI_SUCCESS;
}
ompi_coll_tuned_topo_build_bmtree( MPI_Comm comm,
int root )
{
- int childs = 0;
+ int children = 0;
int rank;
int size;
int mask = 1;
bmtree = new ompi_coll_tree_t;
if (not bmtree) {
XBT_DEBUG("coll:tuned:topo:build_bmtree PANIC out of memory");
- return NULL;
+ return nullptr;
}
bmtree->tree_bmtree = 1;
if( remote >= size ) remote -= size;
bmtree->tree_prev = remote;
}
- /* And now let's fill my childs */
+ /* And now let's fill my children */
while( mask < size ) {
remote = (index ^ mask);
if( remote >= size ) break;
remote += root;
if( remote >= size ) remote -= size;
- if (childs==MAXTREEFANOUT) {
- XBT_DEBUG("coll:tuned:topo:build_bmtree max fanout incorrect %d needed %d", MAXTREEFANOUT, childs);
- return NULL;
+ if (children==MAXTREEFANOUT) {
+ XBT_DEBUG("coll:tuned:topo:build_bmtree max fanout incorrect %d needed %d", MAXTREEFANOUT, children);
+ delete bmtree;
+ return nullptr;
}
- bmtree->tree_next[childs] = remote;
+ bmtree->tree_next[children] = remote;
mask <<= 1;
- childs++;
+ children++;
}
- bmtree->tree_nextsize = childs;
+ bmtree->tree_nextsize = children;
bmtree->tree_root = root;
return bmtree;
}
*/
ompi_coll_tree_t* ompi_coll_tuned_topo_build_in_order_bmtree(MPI_Comm comm, int root)
{
- int childs = 0;
+ int children = 0;
int rank, vrank;
int size;
int mask = 1;
bmtree = new ompi_coll_tree_t;
if (not bmtree) {
XBT_DEBUG("coll:tuned:topo:build_bmtree PANIC out of memory");
- return NULL;
+ delete bmtree;
+ return nullptr;
}
bmtree->tree_bmtree = 1;
bmtree->tree_prev = (remote + root) % size;
break;
} else if (remote < size) {
- bmtree->tree_next[childs] = (remote + root) % size;
- childs++;
- if (childs == MAXTREEFANOUT) {
- XBT_DEBUG("coll:tuned:topo:build_bmtree max fanout incorrect %d needed %d", MAXTREEFANOUT, childs);
- return NULL;
+ bmtree->tree_next[children] = (remote + root) % size;
+ children++;
+ if (children == MAXTREEFANOUT) {
+ XBT_DEBUG("coll:tuned:topo:build_bmtree max fanout incorrect %d needed %d", MAXTREEFANOUT, children);
+ delete bmtree;
+ return nullptr;
}
}
mask <<= 1;
}
- bmtree->tree_nextsize = childs;
+ bmtree->tree_nextsize = children;
bmtree->tree_root = root;
return bmtree;
if (not chain) {
XBT_DEBUG("coll:tuned:topo:build_chain PANIC out of memory");
fflush(stdout);
- return NULL;
+ return nullptr;
}
- chain->tree_root = MPI_UNDEFINED;
- chain->tree_nextsize = -1;
for(i=0;i<fanout;i++) chain->tree_next[i] = -1;
/*