Hypercubic
This commit is contained in:
parent
ae4699176f
commit
bc769718d6
8 changed files with 238 additions and 75 deletions
|
|
@ -26,6 +26,7 @@ set (SMP_FILE
|
||||||
topology/complete.cpp
|
topology/complete.cpp
|
||||||
topology/star.cpp
|
topology/star.cpp
|
||||||
topology/ring.cpp
|
topology/ring.cpp
|
||||||
|
topology/hypercubic.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(smp STATIC ${SMP_FILE})
|
add_library(smp STATIC ${SMP_FILE})
|
||||||
|
|
|
||||||
|
|
@ -45,5 +45,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <topology/complete.h>
|
#include <topology/complete.h>
|
||||||
#include <topology/ring.h>
|
#include <topology/ring.h>
|
||||||
#include <topology/star.h>
|
#include <topology/star.h>
|
||||||
|
#include <topology/hypercubic.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Complete::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||||
{
|
{
|
||||||
matrix.clear();
|
matrix.clear();
|
||||||
|
|
||||||
|
matrix.resize(nbNode);
|
||||||
|
for(auto& line : matrix)
|
||||||
|
line.resize(nbNode);
|
||||||
|
|
||||||
std::vector<bool> line;
|
std::vector<bool> line;
|
||||||
line.assign(nbNode,true);
|
line.assign(nbNode,true);
|
||||||
matrix.assign(nbNode, line);
|
matrix.assign(nbNode, line);
|
||||||
|
|
|
||||||
62
smp/src/topology/hypercubic.cpp
Normal file
62
smp/src/topology/hypercubic.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
<hypercubic.cpp>
|
||||||
|
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 <topology/hypercubic.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
void paradiseo::smp::Hypercubic::operator()(unsigned nbNode, std::vector<std::vector<bool>>& 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<<power) == 0)
|
||||||
|
power++;
|
||||||
|
|
||||||
|
matrix.clear();
|
||||||
|
matrix.resize(nbNode);
|
||||||
|
|
||||||
|
for(auto& line : matrix)
|
||||||
|
line.resize(nbNode);
|
||||||
|
|
||||||
|
//Construction
|
||||||
|
matrix[0][0] = false;
|
||||||
|
for (unsigned dim = 1; dim <= power; dim ++)
|
||||||
|
{
|
||||||
|
int stepNbNode = 1<< (dim-1); //represents the number of nodes for the current step.
|
||||||
|
for(i=0; i <stepNbNode; i++)
|
||||||
|
for(j=0; j< stepNbNode;j++)
|
||||||
|
{
|
||||||
|
matrix[i+stepNbNode][j+stepNbNode]=matrix[i][j];//Diagonal part
|
||||||
|
matrix[i][j+stepNbNode]= matrix[i+stepNbNode][j] = (i == j);//Identity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
58
smp/src/topology/hypercubic.h
Normal file
58
smp/src/topology/hypercubic.h
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
<abstractIsland.h>
|
||||||
|
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 <vector>
|
||||||
|
#include <topology/topologyBuilder.h>
|
||||||
|
|
||||||
|
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<std::vector<bool>>& matrix) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -33,6 +33,11 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Ring::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||||
{
|
{
|
||||||
matrix.clear();
|
matrix.clear();
|
||||||
|
|
||||||
|
matrix.resize(nbNode);
|
||||||
|
for(auto& line : matrix)
|
||||||
|
line.resize(nbNode);
|
||||||
|
|
||||||
std::vector<bool> line;
|
std::vector<bool> line;
|
||||||
line.assign(nbNode, false);
|
line.assign(nbNode, false);
|
||||||
matrix.assign(nbNode, line);
|
matrix.assign(nbNode, line);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,11 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
void paradiseo::smp::Star::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
void paradiseo::smp::Star::operator()(unsigned nbNode, std::vector<std::vector<bool>>& matrix) const
|
||||||
{
|
{
|
||||||
matrix.clear();
|
matrix.clear();
|
||||||
|
|
||||||
|
matrix.resize(nbNode);
|
||||||
|
for(auto& line : matrix)
|
||||||
|
line.resize(nbNode);
|
||||||
|
|
||||||
std::vector<bool> line (nbNode,false);
|
std::vector<bool> line (nbNode,false);
|
||||||
|
|
||||||
line[0]=true;
|
line[0]=true;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,4 @@
|
||||||
#include <topology/topology.h>
|
#include <smp>
|
||||||
#include <topology/complete.h>
|
|
||||||
#include <topology/star.h>
|
|
||||||
#include <topology/ring.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -10,58 +7,69 @@ using namespace paradiseo::smp;
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
std::vector<unsigned> value;
|
||||||
|
|
||||||
//Test of Complete Topology
|
//Test of Complete Topology
|
||||||
n=5;
|
n=5;
|
||||||
Topology<Complete> topo_comp;
|
Topology<Complete> topo_comp;
|
||||||
topo_comp.construct(n);
|
topo_comp.construct(n);
|
||||||
|
|
||||||
std::cout << std::endl << "---------------" << std::endl << "Test of Complete Topology (" << n <<" nodes) :"<<std::endl;
|
|
||||||
|
|
||||||
std::vector<unsigned> neighbors=topo_comp.getIdNeighbors(1);
|
std::vector<unsigned> neighbors = topo_comp.getIdNeighbors(1);
|
||||||
std::cout << "neighbors of Node 1 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(0);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
value.push_back(2);
|
||||||
std::cout << " " << neighbors[i];
|
value.push_back(3);
|
||||||
|
value.push_back(4);
|
||||||
|
assert(neighbors == value);
|
||||||
|
|
||||||
neighbors=topo_comp.getIdNeighbors(2);
|
neighbors=topo_comp.getIdNeighbors(2);
|
||||||
std::cout <<std::endl << "Neighbors of Node 2 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(0);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
value.push_back(1);
|
||||||
std::cout << " " << neighbors[i];
|
value.push_back(3);
|
||||||
std::cout << std::endl;
|
value.push_back(4);
|
||||||
|
assert(neighbors == value);
|
||||||
|
|
||||||
//Isolate an node
|
//Isolate an node
|
||||||
topo_comp.isolateNode(2);
|
topo_comp.isolateNode(2);
|
||||||
neighbors=topo_comp.getIdNeighbors(2);
|
neighbors=topo_comp.getIdNeighbors(2);
|
||||||
std::cout <<std::endl << "Neighbors of Node 2 after isolation : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
assert(neighbors.empty());
|
||||||
std::cout <<"None";
|
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
neighbors=topo_comp.getIdNeighbors(3);
|
neighbors=topo_comp.getIdNeighbors(3);
|
||||||
std::cout <<"Neighbors of Node 3 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(0);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
value.push_back(1);
|
||||||
std::cout << " " << neighbors[i];
|
value.push_back(4);
|
||||||
std::cout << std::endl;
|
assert(neighbors == value);
|
||||||
|
|
||||||
//Re-construct Topology with different number of nodes
|
//Re-construct Topology with different number of nodes
|
||||||
n=3;
|
n=3;
|
||||||
topo_comp.construct(n);
|
topo_comp.construct(n);
|
||||||
neighbors=topo_comp.getIdNeighbors(2);
|
neighbors=topo_comp.getIdNeighbors(2);
|
||||||
std::cout <<"Changing number of nodes to "<< n <<",";
|
|
||||||
std::cout <<"Neighbors of Node 2 : "<<std::endl;
|
value.clear();
|
||||||
if(neighbors.empty())
|
value.push_back(0);
|
||||||
std::cout <<"None";
|
value.push_back(1);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
assert(neighbors == value);
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
n=8;
|
||||||
|
topo_comp.construct(n);
|
||||||
|
neighbors = topo_comp.getIdNeighbors(3);
|
||||||
|
|
||||||
|
value.clear();
|
||||||
|
value.push_back(0);
|
||||||
|
value.push_back(1);
|
||||||
|
value.push_back(2);
|
||||||
|
value.push_back(4);
|
||||||
|
value.push_back(5);
|
||||||
|
value.push_back(6);
|
||||||
|
value.push_back(7);
|
||||||
|
assert(neighbors == value);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
//Test of Star Topology
|
//Test of Star Topology
|
||||||
|
|
@ -69,23 +77,16 @@ int main()
|
||||||
Topology<Star> topo_star;
|
Topology<Star> topo_star;
|
||||||
topo_star.construct(n);
|
topo_star.construct(n);
|
||||||
|
|
||||||
std::cout << std::endl << "---------------" << std::endl << "Test of Star Topology (" << n <<" nodes) :" << std::endl;
|
|
||||||
|
|
||||||
neighbors=topo_star.getIdNeighbors(0);
|
neighbors=topo_star.getIdNeighbors(0);
|
||||||
std::cout <<std::endl << "Neighbors of Node 0 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
assert(neighbors == value);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
neighbors=topo_star.getIdNeighbors(1);
|
neighbors=topo_star.getIdNeighbors(1);
|
||||||
std::cout <<std::endl << "Neighbors of Node 1 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(0);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
assert(neighbors == value);
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
//Test of Ring Topology
|
//Test of Ring Topology
|
||||||
|
|
@ -93,29 +94,54 @@ int main()
|
||||||
Topology<Ring> topo_ring;
|
Topology<Ring> topo_ring;
|
||||||
topo_ring.construct(n);
|
topo_ring.construct(n);
|
||||||
|
|
||||||
std::cout << std::endl << "---------------" << std::endl << "Test of Ring Topology (" << n <<" nodes) :" << std::endl;
|
|
||||||
|
|
||||||
neighbors=topo_ring.getIdNeighbors(4);
|
neighbors=topo_ring.getIdNeighbors(4);
|
||||||
std::cout <<std::endl << "Neighbors of Node 4 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(5);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
assert(neighbors == value);
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
neighbors=topo_ring.getIdNeighbors(7);
|
neighbors=topo_ring.getIdNeighbors(7);
|
||||||
std::cout <<std::endl << "Neighbors of Node 7 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(0);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
assert(neighbors == value);
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
neighbors=topo_ring.getIdNeighbors(0);
|
neighbors=topo_ring.getIdNeighbors(0);
|
||||||
std::cout <<std::endl << "Neighbors of Node 0 : "<<std::endl;
|
|
||||||
if(neighbors.empty())
|
value.clear();
|
||||||
std::cout <<"None";
|
value.push_back(1);
|
||||||
for (int i=0; i < neighbors.size(); i++)
|
assert(neighbors == value);
|
||||||
std::cout << " " << neighbors[i];
|
|
||||||
std::cout << std::endl;
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
//Test of Hypercubic Topology
|
||||||
|
n=2;
|
||||||
|
Topology<Hypercubic> 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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue