From: Sébastien Miquée Date: Mon, 22 Feb 2010 20:55:44 +0000 (+0100) Subject: Correction of bugs and new functionalities. X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/mapping.git/commitdiff_plain/c5259b6a754655006e41cae8ff32292b7eee4913?ds=sidebyside Correction of bugs and new functionalities. - Simplification of some functions and suppression of unused or not useful variables. - Correction of some functions after having done different tests of non regression. --- diff --git a/src/and/Mapping/Algo.java b/src/and/Mapping/Algo.java index e85d04f..a06171e 100644 --- a/src/and/Mapping/Algo.java +++ b/src/and/Mapping/Algo.java @@ -94,6 +94,22 @@ public abstract class Algo implements Serializable { return gr ; } + + + /** + * Update the grid status after having done the mapping. + */ + protected void updateGrid() + { + if( mp.getMappedGNodes().size() >= 0 ) + { + ArrayList 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 !! **/ diff --git a/src/and/Mapping/Cluster.java b/src/and/Mapping/Cluster.java index 0561682..a9abe87 100644 --- a/src/and/Mapping/Cluster.java +++ b/src/and/Mapping/Cluster.java @@ -14,11 +14,12 @@ public class Cluster implements Serializable { private static final long serialVersionUID = 1L; - private int nb_node ; +// private int nb_node ; private String name ; private ArrayList nodes ; + private ArrayList freenodes ; private String site ; - private int indice ; +// private int indice ; /** @@ -26,52 +27,54 @@ public class Cluster implements Serializable */ public Cluster() { - nb_node = 0 ; +// nb_node = 0 ; name = "" ; nodes = new ArrayList() ; + freenodes = new ArrayList() ; 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() ; - 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() ; +// freenodes = new ArrayList() ; +// 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() ; - 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() ; +// site = "" ; +//// indice = 0 ; +// +// for( int i = 0 ; i < nb_node ; i++ ) +// { +// nodes.add( new GNode() ) ; +// } +// } /** @@ -90,10 +93,18 @@ public class Cluster implements Serializable */ 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 ) ; + } + } } @@ -123,7 +134,8 @@ public class Cluster implements Serializable */ public int getNbGNode() { - return nb_node ; +// return nb_node ; + return nodes.size() ; } @@ -150,29 +162,35 @@ public class Cluster implements Serializable /** * 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 ; +// } /** @@ -184,10 +202,14 @@ public class Cluster implements Serializable { 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 ; @@ -206,14 +228,51 @@ public class Cluster implements Serializable { 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() ; } } diff --git a/src/and/Mapping/DefaultMapping.java b/src/and/Mapping/DefaultMapping.java index 9e10bf5..1b21ea6 100644 --- a/src/and/Mapping/DefaultMapping.java +++ b/src/and/Mapping/DefaultMapping.java @@ -42,7 +42,7 @@ public class DefaultMapping extends Algo @Override public void map() { - /* If the mapping is possible ... */ + /** If the mapping is possible ... **/ if( gr.getNbGTask() <= gl.getNbGNode() ) { atraiter = gr.getGraph() ; @@ -60,6 +60,9 @@ public class DefaultMapping extends Algo } else { System.err.println( "\n\n!!! Unable to map application !\n\n" ) ; } + + /** Update in cluster the status of nodes **/ + updateGrid() ; } @@ -85,10 +88,12 @@ public class DefaultMapping extends Algo } 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 ; } diff --git a/src/and/Mapping/Graph.java b/src/and/Mapping/Graph.java index 58a719d..3387f60 100644 --- a/src/and/Mapping/Graph.java +++ b/src/and/Mapping/Graph.java @@ -8,7 +8,7 @@ import java.util.ArrayList; /** - * Class representing the interaction graph of an application + * Class representing the application's graph * @author Sébastien Miquée */ public class Graph implements Serializable @@ -17,7 +17,7 @@ public class Graph implements Serializable private ArrayList graph ; - private int nb_task ; +// private int nb_task ; private int nb_dep_total ; @@ -27,7 +27,7 @@ public class Graph implements Serializable public Graph() { graph = new ArrayList() ; - nb_task = 0 ; +// nb_task = 0 ; nb_dep_total = 0 ; } @@ -38,21 +38,40 @@ public class Graph implements Serializable */ 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 _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 ++ ; + } } } @@ -73,18 +92,18 @@ public class Graph implements Serializable */ 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() ) ; } diff --git a/src/and/Mapping/Grid.java b/src/and/Mapping/Grid.java index eb3fb4f..0370940 100644 --- a/src/and/Mapping/Grid.java +++ b/src/and/Mapping/Grid.java @@ -15,8 +15,8 @@ public class Grid implements Serializable private static final long serialVersionUID = 1L; - private int nb_cluster ; - private int nb_node ; +// private int nb_cluster ; +// private int nb_node ; private ArrayList clusters ; private ArrayList gnodesList; private boolean gnodesList_done; @@ -27,8 +27,8 @@ public class Grid implements Serializable */ public Grid() { - nb_cluster = 0 ; - nb_node = 0 ; +// nb_cluster = 0 ; +// nb_node = 0 ; clusters = new ArrayList() ; gnodesList = new ArrayList() ; gnodesList_done = false ; @@ -44,8 +44,13 @@ public class Grid implements Serializable 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() ; } } @@ -63,9 +68,9 @@ public class Grid implements Serializable 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++ ) { @@ -82,7 +87,8 @@ public class Grid implements Serializable */ public int getNbCluster() { - return nb_cluster ; + return clusters.size() ; +// return nb_cluster ; } @@ -92,7 +98,8 @@ public class Grid implements Serializable */ public int getNbGNode() { - return nb_node ; + return gnodesList.size() ; +// return nb_node ; } @@ -106,16 +113,16 @@ public class Grid implements Serializable } - /** - * 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() ; +// } +// } /** @@ -137,13 +144,13 @@ public class Grid implements Serializable 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() ; @@ -211,7 +218,9 @@ public class Grid implements Serializable { 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() ) ; @@ -219,8 +228,11 @@ public class Grid implements Serializable _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 ; @@ -248,10 +260,10 @@ public class Grid implements Serializable _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 ) ) ; } } @@ -289,7 +301,7 @@ public class Grid implements Serializable } /** 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() ) { @@ -299,11 +311,55 @@ public class Grid implements Serializable } } - 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. @@ -311,7 +367,7 @@ public class Grid implements Serializable */ public double getHeterogenityDegre() { - if( nb_node != gnodesList.size() ) + if( ! ( gnodesList.size() > 0 ) ) { System.err.println( "Mapping - Heterogeneity degree computation! " + "List's size not corresponding!" ) ; @@ -325,22 +381,22 @@ public class Grid implements Serializable 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 @@ -359,8 +415,8 @@ public class Grid implements Serializable 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() ) ; } diff --git a/src/and/Mapping/LSM.java b/src/and/Mapping/LSM.java index 44b5676..c193bc8 100644 --- a/src/and/Mapping/LSM.java +++ b/src/and/Mapping/LSM.java @@ -224,6 +224,9 @@ public class LSM extends Algo } else { System.out.println( "\n\n!!! Mapping impossible ! There are more tasks than nodes !!!\n" ) ; } + + /** Update in cluster the status of nodes **/ + updateGrid() ; } /** @@ -405,6 +408,9 @@ public class LSM extends Algo @Override public GNode replaceNode( GNode _dead, ArrayList _ag ) { + /** Update in cluster the status of nodes **/ + updateGrid() ; + return null; } diff --git a/src/and/Mapping/Mapping.java b/src/and/Mapping/Mapping.java index 1136d55..c6ee73a 100644 --- a/src/and/Mapping/Mapping.java +++ b/src/and/Mapping/Mapping.java @@ -181,7 +181,7 @@ public class Mapping implements Serializable public void print() { System.out.println(); - System.out.println( "\t=> Mapping done :\n" ) ; + System.out.println( "\t=> Mapping done:\n" ) ; if( type == 0 ) { diff --git a/src/and/Mapping/QM.java b/src/and/Mapping/QM.java index 04f6a43..70799f2 100644 --- a/src/and/Mapping/QM.java +++ b/src/and/Mapping/QM.java @@ -208,6 +208,9 @@ public class QM extends Algo } else { System.err.println( "\n\n!!! Unable to map application !\n\n" ) ; } + + /** Update in cluster the status of nodes **/ + updateGrid() ; } /** @@ -509,6 +512,8 @@ public class QM extends Algo @Override public GNode replaceNode(GNode _dead, ArrayList _ag ) { + /** Update in cluster the status of nodes **/ + updateGrid() ; return null; } diff --git a/src/and/Mapping/Simple.java b/src/and/Mapping/Simple.java index abf443d..8bf957a 100644 --- a/src/and/Mapping/Simple.java +++ b/src/and/Mapping/Simple.java @@ -112,6 +112,9 @@ public class Simple extends Algo } else { System.err.println( "\n\n!!! Unable to map application !\n\n" ) ; } + + /** Update in cluster the status of nodes **/ + updateGrid() ; } @@ -119,6 +122,11 @@ public class Simple extends Algo public GNode replaceNode(GNode replaced, ArrayList _ag ) { // TODO + + /** Update in cluster the status of nodes **/ + updateGrid() ; + + return null ; } diff --git a/src/and/Mapping/Utils.java b/src/and/Mapping/Utils.java index 7e05ca2..ff2393a 100644 --- a/src/and/Mapping/Utils.java +++ b/src/and/Mapping/Utils.java @@ -77,6 +77,7 @@ public class Utils n.setMemory( memory ) ; n.setNb_cores( nbCore ) ; n.setName( name ) ; + n.setMapped( false ) ; return n ; } @@ -180,10 +181,10 @@ public class Utils /** * 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( "" ) ) { @@ -230,10 +231,10 @@ public class Utils /** * 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( "" ) ) {