From bc769718d6c146447a675eebc7a67212ab660d19 Mon Sep 17 00:00:00 2001 From: lasnier Date: Tue, 27 Nov 2012 17:31:05 +0100 Subject: [PATCH] Hypercubic --- smp/src/CMakeLists.txt | 1 + smp/src/smp.h | 1 + smp/src/topology/complete.cpp | 5 + smp/src/topology/hypercubic.cpp | 62 +++++++++++ smp/src/topology/hypercubic.h | 58 +++++++++++ smp/src/topology/ring.cpp | 5 + smp/src/topology/star.cpp | 5 + smp/test/t-smpTopo.cpp | 176 ++++++++++++++++++-------------- 8 files changed, 238 insertions(+), 75 deletions(-) create mode 100644 smp/src/topology/hypercubic.cpp create mode 100644 smp/src/topology/hypercubic.h diff --git a/smp/src/CMakeLists.txt b/smp/src/CMakeLists.txt index ab7a306e4..a1899ccc9 100644 --- a/smp/src/CMakeLists.txt +++ b/smp/src/CMakeLists.txt @@ -26,6 +26,7 @@ set (SMP_FILE topology/complete.cpp topology/star.cpp topology/ring.cpp + topology/hypercubic.cpp ) add_library(smp STATIC ${SMP_FILE}) diff --git a/smp/src/smp.h b/smp/src/smp.h index 29ebfff45..bd89dde43 100644 --- a/smp/src/smp.h +++ b/smp/src/smp.h @@ -45,5 +45,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include #include +#include #endif diff --git a/smp/src/topology/complete.cpp b/smp/src/topology/complete.cpp index 378e034b2..19cd2b4a5 100644 --- a/smp/src/topology/complete.cpp +++ b/smp/src/topology/complete.cpp @@ -33,6 +33,11 @@ Contact: paradiseo-help@lists.gforge.inria.fr void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector>& matrix) const { matrix.clear(); + + matrix.resize(nbNode); + for(auto& line : matrix) + line.resize(nbNode); + std::vector line; line.assign(nbNode,true); matrix.assign(nbNode, line); diff --git a/smp/src/topology/hypercubic.cpp b/smp/src/topology/hypercubic.cpp new file mode 100644 index 000000000..78f8a2cba --- /dev/null +++ b/smp/src/topology/hypercubic.cpp @@ -0,0 +1,62 @@ +/* + +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012 + +Alexandre Quemy, Thibault Lasnier - INSA Rouen + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + + +#include +#include +#include + +void paradiseo::smp::Hypercubic::operator()(unsigned nbNode, std::vector>& matrix) const +{ + //Check if the number of node is coherent with an hypercube + assert((nbNode & (nbNode-1)) == 0); + + unsigned power=0,i,j; + while((nbNode & 1< +Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012 + +Alexandre Quemy, Thibault Lasnier - INSA Rouen + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can ue, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +ParadisEO WebSite : http://paradiseo.gforge.inria.fr +Contact: paradiseo-help@lists.gforge.inria.fr +*/ + +#ifndef HYPERCUBIC_H_ +#define HYPERCUBIC_H_ + +#include +#include + +namespace paradiseo +{ +namespace smp +{ + +/** +*Hypercubic: Inherit from TopologyBuilder. Represents a builder for an hypercubic topology. +*The number of nodes must be a power of 2, and will be the degree of the hpercube. If it is not the case, the topology will not be built. +*/ +class Hypercubic: public TopologyBuilder +{ +public : + /** + *Fills the given matrix for a hypercubic topology with the specified number of nodes. + */ + void operator()(unsigned nbNode, std::vector>& matrix) const; +}; + +} + +} + +#endif diff --git a/smp/src/topology/ring.cpp b/smp/src/topology/ring.cpp index 78ccccf7a..37976e91c 100644 --- a/smp/src/topology/ring.cpp +++ b/smp/src/topology/ring.cpp @@ -33,6 +33,11 @@ Contact: paradiseo-help@lists.gforge.inria.fr void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector>& matrix) const { matrix.clear(); + + matrix.resize(nbNode); + for(auto& line : matrix) + line.resize(nbNode); + std::vector line; line.assign(nbNode, false); matrix.assign(nbNode, line); diff --git a/smp/src/topology/star.cpp b/smp/src/topology/star.cpp index 50aff724b..1328d4937 100644 --- a/smp/src/topology/star.cpp +++ b/smp/src/topology/star.cpp @@ -33,6 +33,11 @@ Contact: paradiseo-help@lists.gforge.inria.fr void paradiseo::smp::Star::operator()(unsigned nbNode, std::vector>& matrix) const { matrix.clear(); + + matrix.resize(nbNode); + for(auto& line : matrix) + line.resize(nbNode); + std::vector line (nbNode,false); line[0]=true; diff --git a/smp/test/t-smpTopo.cpp b/smp/test/t-smpTopo.cpp index f1ad4ffc7..0f63c7a71 100644 --- a/smp/test/t-smpTopo.cpp +++ b/smp/test/t-smpTopo.cpp @@ -1,7 +1,4 @@ -#include -#include -#include -#include +#include #include #include @@ -10,82 +7,86 @@ using namespace paradiseo::smp; int main() { int n; + std::vector value; //Test of Complete Topology n=5; Topology topo_comp; topo_comp.construct(n); - std::cout << std::endl << "---------------" << std::endl << "Test of Complete Topology (" << n <<" nodes) :"< neighbors=topo_comp.getIdNeighbors(1); - std::cout << "neighbors of Node 1 : "< neighbors = topo_comp.getIdNeighbors(1); + + value.clear(); + value.push_back(0); + value.push_back(2); + value.push_back(3); + value.push_back(4); + assert(neighbors == value); + neighbors=topo_comp.getIdNeighbors(2); - std::cout < topo_star; topo_star.construct(n); - std::cout << std::endl << "---------------" << std::endl << "Test of Star Topology (" << n <<" nodes) :" << std::endl; - - neighbors=topo_star.getIdNeighbors(0); - std::cout < topo_ring; topo_ring.construct(n); - std::cout << std::endl << "---------------" << std::endl << "Test of Ring Topology (" << n <<" nodes) :" << std::endl; - neighbors=topo_ring.getIdNeighbors(4); - std::cout < topo_hyper; + topo_hyper.construct(n); + + neighbors=topo_hyper.getIdNeighbors(0); + + value.clear(); + value.push_back(1); + assert(neighbors == value); + + n=4; + topo_hyper.construct(n); + + neighbors=topo_hyper.getIdNeighbors(1); + + value.clear(); + value.push_back(0); + value.push_back(3); + assert(neighbors == value); + + n=8; + topo_hyper.construct(n); + + neighbors=topo_hyper.getIdNeighbors(5); + + value.clear(); + value.push_back(1); + value.push_back(4); + value.push_back(7); + assert(neighbors == value); }