{
return gr ;
}
+
+
+ /**
+ * Update the grid status after having done the mapping.
+ */
+ protected void updateGrid()
+ {
+ if( mp.getMappedGNodes().size() >= 0 )
+ {
+ ArrayList<GNode> temp = mp.getMappedGNodes() ;
+ for( int i = 0 ; i < temp.size() ; i++ )
+ {
+ gl.getClusterOfNode( temp.get( i ) ).setGNodeStatus( temp.get( i ), true ) ;
+ }
+ }
+ }
}
/** La programmation est un art, respectons ceux qui la pratiquent !! **/
{
private static final long serialVersionUID = 1L;
- private int nb_node ;
+// private int nb_node ;
private String name ;
private ArrayList<GNode> nodes ;
+ private ArrayList<GNode> freenodes ;
private String site ;
- private int indice ;
+// private int indice ;
/**
*/
public Cluster()
{
- nb_node = 0 ;
+// nb_node = 0 ;
name = "" ;
nodes = new ArrayList<GNode>() ;
+ freenodes = new ArrayList<GNode>() ;
site = "" ;
- indice = 0 ;
+// indice = 0 ;
}
- /**
- * Constructor.
- * @param _nb The amount of computing nodes in the cluster
- */
- public Cluster( int _nb )
- {
- nb_node = _nb ;
- name = "" ;
- nodes = new ArrayList<GNode>() ;
- site = "" ;
- indice = 0 ;
-
-
- for( int i = 0 ; i < nb_node ; i++ )
- {
- nodes.add( new GNode() ) ;
- }
- }
+// /**
+// * Constructor.
+// * @param _nb The amount of computing nodes in the cluster
+// */
+// public Cluster( int _nb )
+// {
+// nb_node = _nb ;
+// name = "" ;
+// nodes = new ArrayList<GNode>() ;
+// freenodes = new ArrayList<GNode>() ;
+// site = "" ;
+//// indice = 0 ;
+//
+//
+// for( int i = 0 ; i < nb_node ; i++ )
+// {
+// nodes.add( new GNode() ) ;
+// }
+// }
- /**
- * Constructor.
- * @param _nb The amount of computing nodes in the cluster
- * @param _name Cluster's name
- */
- public Cluster( int _nb, String _name )
- {
- nb_node = _nb ;
- name = _name ;
- nodes = new ArrayList<GNode>() ;
- site = "" ;
- indice = 0 ;
-
- for( int i = 0 ; i < nb_node ; i++ )
- {
- nodes.add( new GNode() ) ;
- }
- }
+// /**
+// * Constructor.
+// * @param _nb The amount of computing nodes in the cluster
+// * @param _name Cluster's name
+// */
+// public Cluster( int _nb, String _name )
+// {
+//// nb_node = _nb ;
+// name = _name ;
+// nodes = new ArrayList<GNode>() ;
+// site = "" ;
+//// indice = 0 ;
+//
+// for( int i = 0 ; i < nb_node ; i++ )
+// {
+// nodes.add( new GNode() ) ;
+// }
+// }
/**
*/
public void addGNode( GNode _n )
{
- _n.setInCluster( true ) ;
- nodes.add( _n ) ;
+ if( _n != null )
+ {
+ _n.setInCluster( true ) ;
+ nodes.add( _n ) ;
- nb_node++ ;
+// nb_node++ ;
+
+ if( ! _n.getMapped() )
+ {
+ freenodes.add( _n ) ;
+ }
+ }
}
*/
public int getNbGNode()
{
- return nb_node ;
+// return nb_node ;
+ return nodes.size() ;
}
/**
* Test if a computing node is in the cluster.
* @param _g The node to be tested
- * @return True is _g is in, False else
+ * @return The position of the node
*/
- public boolean isIn( GNode _g )
+ public int isIn( GNode _g )
{
+ int pos = -1 ;
+
if( _g != null )
{
- for( int i = 0; i < nodes.size(); i ++ )
+ for( int i = 0 ; i < nodes.size() ; i ++ )
{
if( nodes.get( i ).getId() == _g.getId() )
- return true ;
+ {
+ pos = i ;
+ break ;
+ }
+
}
}
- return false ;
+ return pos ;
}
- /**
- * Initialization of indice variable.
- */
- public void initIndice()
- {
- indice = 0 ;
- }
+// /**
+// * Initialization of indice variable.
+// */
+// public void initIndice()
+// {
+// indice = 0 ;
+// }
/**
{
GNode ret = null ;
- if( indice < nb_node )
+// if( indice < nb_node )
+// {
+// ret = nodes.get( indice ) ;
+// indice++ ;
+// }
+ if( freenodes.size() > 0 )
{
- ret = nodes.get( indice ) ;
- indice++ ;
+ ret = freenodes.remove( 0 ) ;
}
return ret ;
{
if( _dead.getId() == nodes.get( i ).getId() )
{
- nodes.remove( i ) ;
- nb_node-- ;
+ freenodes.remove( nodes.remove( i ) ) ;
+// nb_node-- ;
break ;
}
}
}
-
+ }
+
+
+ /**
+ * Set the mapped status of a node of the cluster.
+ * @param _g The mapped node
+ * @param _status The status of the node
+ */
+ public void setGNodeStatus( GNode _g, boolean _status )
+ {
+ if( _g != null )
+ {
+ for( int i = 0 ; i < nodes.size() ; i++ )
+ {
+ if( nodes.get( i ).getId() == _g.getId() )
+ {
+ nodes.get( i ).setMapped( _status ) ;
+
+ if( _status )
+ {
+ freenodes.remove( nodes.get(i) ) ;
+ } else {
+ if( ! freenodes.contains( nodes.get( i ) ) )
+ freenodes.add( nodes.get( i ) ) ;
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Return the amount of available free nodes in the cluster.
+ * @return The amount of free nodes
+ */
+ public int getNbFreeNodes()
+ {
+ return freenodes.size() ;
}
}
@Override
public void map()
{
- /* If the mapping is possible ... */
+ /** If the mapping is possible ... **/
if( gr.getNbGTask() <= gl.getNbGNode() )
{
atraiter = gr.getGraph() ;
} else {
System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
}
+
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
}
} else {
System.err.println( "Not enought available nodes in gnodes to replace one !" ) ;
return null ;
- }
-
+ }
}
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
+
return ret ;
}
/**
- * Class representing the interaction graph of an application
+ * Class representing the application's graph
* @author Sébastien Miquée
*/
public class Graph implements Serializable
private ArrayList<GTask> graph ;
- private int nb_task ;
+// private int nb_task ;
private int nb_dep_total ;
public Graph()
{
graph = new ArrayList<GTask>() ;
- nb_task = 0 ;
+// nb_task = 0 ;
nb_dep_total = 0 ;
}
*/
public int getNbGTask()
{
- return nb_task ;
+ return graph.size() ;
+// return nb_task ;
}
/**
- * Add a task in the interaction graph.
+ * Add a task into the graph.
* @param t Task to be add
*/
- public void addGTask( GTask t )
+ public void addGTask( GTask _t )
{
- if( t != null )
+ if( _t != null )
{
- graph.add( t.getNum(), t ) ;
- nb_dep_total += t.getNbDep() ;
- nb_task ++ ;
+ graph.add( _t.getNum(), _t ) ;
+ nb_dep_total += _t.getNbDep() ;
+// nb_task ++ ;
+ }
+ }
+
+
+ /**
+ * Add a list of tasks into the graph.
+ * @param _lt : Tasks list to be added
+ */
+ public void addGTasks( ArrayList<GTask> _lt )
+ {
+ if( _lt != null )
+ {
+ for( int i = 0 ; i < _lt.size() ; i++ )
+ {
+ graph.add( _lt.get( i ).getNum(), _lt.get( i ) ) ;
+ nb_dep_total += _lt.get( i ).getNbDep() ;
+// nb_task ++ ;
+ }
}
}
*/
public double getAverageDep()
{
- return nb_dep_total / nb_task ;
+ return nb_dep_total / graph.size() ;
}
/**
- * Print the graph in a text version.
+ * Print the graph in a comprehensible text version.
*/
public void print()
{
System.out.println();
System.out.println( "\t=> Composition of interaction graph:\n" ) ;
- for( int i = 0 ; i < nb_task ; i++ )
+ for( int i = 0 ; i < graph.size() ; i++ )
{
System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
}
private static final long serialVersionUID = 1L;
- private int nb_cluster ;
- private int nb_node ;
+// private int nb_cluster ;
+// private int nb_node ;
private ArrayList<Cluster> clusters ;
private ArrayList<GNode> gnodesList;
private boolean gnodesList_done;
*/
public Grid()
{
- nb_cluster = 0 ;
- nb_node = 0 ;
+// nb_cluster = 0 ;
+// nb_node = 0 ;
clusters = new ArrayList<Cluster>() ;
gnodesList = new ArrayList<GNode>() ;
gnodesList_done = false ;
if( c != null )
{
clusters.add( c ) ;
- nb_cluster ++ ;
- nb_node += c.getNbGNode() ;
+
+ for( int i = 0 ; i < c.getNbGNode() ; i++ )
+ {
+ gnodesList.add( c.getGNodes().get( i ) ) ;
+ }
+// nb_cluster++ ;
+// nb_node += c.getNbGNode() ;
}
}
for( int i = 0 ; i < al.size() ; i++ )
{
clusters.add( al.get( i ) ) ;
- nb_cluster ++ ;
+// nb_cluster++ ;
nbCLusterNodes = al.get( i ).getNbGNode() ;
- nb_node += nbCLusterNodes ;
+// nb_node += nbCLusterNodes ;
for( int j = 0 ; j < nbCLusterNodes ; j++ )
{
*/
public int getNbCluster()
{
- return nb_cluster ;
+ return clusters.size() ;
+// return nb_cluster ;
}
*/
public int getNbGNode()
{
- return nb_node ;
+ return gnodesList.size() ;
+// return nb_node ;
}
}
- /**
- * Initialization of clusters.
- */
- public void initClusters()
- {
- for( int i = 0 ; i < nb_cluster ; i++ )
- {
- clusters.get( i ).initIndice() ;
- }
- }
+// /**
+// * Initialization of clusters.
+// */
+// public void initClusters()
+// {
+// for( int i = 0 ; i < nb_cluster ; i++ )
+// {
+// clusters.get( i ).initIndice() ;
+// }
+// }
/**
for( int i = 0 ; i < clusters.size() ; i++ )
{
- if( clusters.get( i ).isIn( _g1) )
+ if( clusters.get( i ).isIn( _g1 ) != -1 )
{
cluster1 = clusters.get( i ).getName() ;
site1 = clusters.get( i ).getSite() ;
}
- if( clusters.get( i ).isIn( _g2) )
+ if( clusters.get( i ).isIn( _g2 ) != -1 )
{
cluster2 = clusters.get( i ).getName() ;
site2 = clusters.get( i ).getSite() ;
{
if( _gnodes.get( i ).getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
{
- if( ! clusters.get( j ).isIn( _gnodes.get( i ) ) )
+ int pos = clusters.get( j ).isIn( _gnodes.get( i ) ) ;
+
+ if( pos == -1 )
{
_gnodes.get( i ).setCluster( clusters.get( j ).getName() ) ;
_gnodes.get( i ).setSite( clusters.get( j ).getSite() ) ;
_gnodes.get( i ).setMapped( false ) ;
clusters.get( i ).addGNode( _gnodes.get( j ) ) ;
- nb_node++ ;
+// nb_node++ ;
gnodesList.add( _gnodes.get( i ) ) ;
+
+ } else {
+ clusters.get( j ).setGNodeStatus( _gnodes.get( i ), _gnodes.get( i ).getMapped() ) ;
}
break ;
_gnodes.get( i ).setCluster( cluster ) ;
nClust.addGNode( _gnodes.get( i ) ) ;
- nb_cluster++ ;
+// nb_cluster++ ;
clusters.add( nClust ) ;
- nb_node++ ;
+// nb_node++ ;
gnodesList.add( _gnodes.get( i ) ) ;
}
}
}
/** Removing the dead node from the global list **/
- for( int i = 0 ; i < nb_node ; i++ )
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
{
if( _dead.getId() == gnodesList.get( i ).getId() )
{
}
}
- nb_node-- ;
+// nb_node-- ;
gnodesList_done = false ;
}
+ /**
+ * Change the mapping status of a node in the grid and in its cluster.
+ * @param _g The node to change the mapping status
+ * @param _status The node's mapping status
+ */
+ public void setMappedStatus( GNode _g, boolean _status )
+ {
+ if( _g != null )
+ {
+ getClusterOfNode( _g ).setGNodeStatus( _g, _status ) ;
+
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
+ {
+ if( _g.getId() == gnodesList.get( i ).getId() )
+ {
+ gnodesList.get( i ).setMapped( _status ) ;
+ break ;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Search and return the cluster containing the specified node.
+ * @param _g A node
+ * @return The cluster containing the node
+ */
+ public Cluster getClusterOfNode( GNode _g )
+ {
+ if( _g != null )
+ {
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ if( _g.getCluster().equalsIgnoreCase( clusters.get( i ).getName() ) )
+ {
+ return clusters.get( i ) ;
+ }
+ }
+ }
+
+ return null ;
+ }
+
/**
* Compute the heterogeneity degree of the grid.
* This is based on the relative standard deviation.
*/
public double getHeterogenityDegre()
{
- if( nb_node != gnodesList.size() )
+ if( ! ( gnodesList.size() > 0 ) )
{
System.err.println( "Mapping - Heterogeneity degree computation! " +
"List's size not corresponding!" ) ;
double temp = 0 ;
/** Computation of the average power of computing nodes **/
- for( int i = 0 ; i < nb_node ; i++ )
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
{
temp += gnodesList.get(i).getPower() ;
}
- average = temp / nb_node ;
+ average = temp / gnodesList.size() ;
/** Computation of the variance **/
temp = 0 ;
- for( int i = 0 ; i < nb_node ; i++ )
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
{
temp += Math.pow( ( gnodesList.get(i).getPower() - average ), 2 ) ;
}
/** Computation of the standard deviation **/
- temp = temp / nb_node ;
+ temp = temp / gnodesList.size() ;
std = Math.sqrt( temp ) ;
/** Computation of the relative standard deviation
public void print()
{
System.out.println();
- System.out.println( "\t=> Grid composition :\n" ) ;
- for( int i = 0 ; i < nb_cluster ; i++ )
+ System.out.println( "\t=> Grid composition:\n" ) ;
+ for( int i = 0 ; i < clusters.size() ; i++ )
{
System.out.println( "\t\tCluster \""+ clusters.get(i).getName() +"\" : " + clusters.get(i).getNbGNode() ) ;
}
} else {
System.out.println( "\n\n!!! Mapping impossible ! There are more tasks than nodes !!!\n" ) ;
}
+
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
}
/**
@Override
public GNode replaceNode( GNode _dead, ArrayList<GNode> _ag )
{
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
+
return null;
}
public void print()
{
System.out.println();
- System.out.println( "\t=> Mapping done :\n" ) ;
+ System.out.println( "\t=> Mapping done:\n" ) ;
if( type == 0 )
{
} else {
System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
}
+
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
}
/**
@Override
public GNode replaceNode(GNode _dead, ArrayList<GNode> _ag )
{
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
return null;
}
} else {
System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
}
+
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
}
public GNode replaceNode(GNode replaced, ArrayList<GNode> _ag )
{
// TODO
+
+ /** Update in cluster the status of nodes **/
+ updateGrid() ;
+
+
return null ;
}
n.setMemory( memory ) ;
n.setNb_cores( nbCore ) ;
n.setName( name ) ;
+ n.setMapped( false ) ;
return n ;
}
/**
* Write the Grid object in an XML file.
* @param _gl Grid graph to be write
- * @param _file File's name
* @param _path File's path
+ * @param _file File's name
*/
- public static void writeGrid( Grid _gl, String _file, String _path )
+ public static void writeGrid( Grid _gl, String _path, String _file )
{
if( _file.equals( "" ) )
{
/**
* Write an application Graph in a file.
* @param _gr Application Graph to be write
- * @param _file File's name
* @param _path File's path
+ * @param _file File's name
*/
- public static void writeGraph( Graph _gr, String _file, String _path )
+ public static void writeGraph( Graph _gr, String _path, String _file )
{
if( _file.equals( "" ) )
{