X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1b2975e32481a9b38fe38af90db86ac5c54d8e59..39c935d6d5ee86d153f6f7e6a10d723ae7c57f6f:/src/smpi/colls/coll_tuned_topo.cpp diff --git a/src/smpi/colls/coll_tuned_topo.cpp b/src/smpi/colls/coll_tuned_topo.cpp index 0236803ca9..932e06973d 100644 --- a/src/smpi/colls/coll_tuned_topo.cpp +++ b/src/smpi/colls/coll_tuned_topo.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2019. The SimGrid Team. +/* Copyright (c) 2013-2021. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -89,11 +89,11 @@ ompi_coll_tuned_topo_build_tree( int fanout, 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; } /* @@ -105,17 +105,9 @@ ompi_coll_tuned_topo_build_tree( int fanout, 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 */ @@ -205,12 +197,9 @@ ompi_coll_tuned_topo_build_in_order_bintree( MPI_Comm comm ) 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 */ @@ -232,61 +221,63 @@ ompi_coll_tuned_topo_build_in_order_bintree( MPI_Comm comm ) 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; } @@ -306,7 +297,7 @@ int ompi_coll_tuned_topo_destroy_tree( ompi_coll_tree_t** tree ) ptr = *tree; delete ptr; - *tree = NULL; /* mark tree as gone */ + *tree = nullptr; /* mark tree as gone */ return MPI_SUCCESS; } @@ -327,7 +318,7 @@ ompi_coll_tree_t* ompi_coll_tuned_topo_build_bmtree( MPI_Comm comm, int root ) { - int childs = 0; + int children = 0; int rank; int size; int mask = 1; @@ -349,7 +340,7 @@ ompi_coll_tuned_topo_build_bmtree( MPI_Comm comm, 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; @@ -372,22 +363,22 @@ ompi_coll_tuned_topo_build_bmtree( MPI_Comm comm, 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); + if (children==MAXTREEFANOUT) { + XBT_DEBUG("coll:tuned:topo:build_bmtree max fanout incorrect %d needed %d", MAXTREEFANOUT, children); delete bmtree; - return NULL; + 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; } @@ -408,7 +399,7 @@ ompi_coll_tuned_topo_build_bmtree( MPI_Comm comm, */ 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; @@ -429,7 +420,7 @@ ompi_coll_tree_t* ompi_coll_tuned_topo_build_in_order_bmtree(MPI_Comm comm, int if (not bmtree) { XBT_DEBUG("coll:tuned:topo:build_bmtree PANIC out of memory"); delete bmtree; - return NULL; + return nullptr; } bmtree->tree_bmtree = 1; @@ -449,17 +440,17 @@ ompi_coll_tree_t* ompi_coll_tuned_topo_build_in_order_bmtree(MPI_Comm comm, int 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); + 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 NULL; + return nullptr; } } mask <<= 1; } - bmtree->tree_nextsize = childs; + bmtree->tree_nextsize = children; bmtree->tree_root = root; return bmtree; @@ -501,10 +492,8 @@ ompi_coll_tuned_topo_build_chain( int fanout, 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;itree_next[i] = -1; /*