A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
mapping.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
Adding new functionalities.
[mapping.git]
/
src
/
and
/
Mapping
/
Grid.java
diff --git
a/src/and/Mapping/Grid.java
b/src/and/Mapping/Grid.java
index
16e46b1
..
2451b95
100644
(file)
--- a/
src/and/Mapping/Grid.java
+++ b/
src/and/Mapping/Grid.java
@@
-14,9
+14,6
@@
public class Grid implements Serializable
{
private static final long serialVersionUID = 1L;
-
- private int nb_cluster ;
- private int nb_node ;
private ArrayList<Cluster> clusters ;
private ArrayList<GNode> gnodesList;
private boolean gnodesList_done;
@@
-27,8
+24,6
@@
public class Grid implements Serializable
*/
public Grid()
{
- nb_cluster = 0 ;
- nb_node = 0 ;
clusters = new ArrayList<Cluster>() ;
gnodesList = new ArrayList<GNode>() ;
gnodesList_done = false ;
@@
-44,8
+39,11
@@
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 ) ) ;
+ }
}
}
@@
-63,9
+61,7
@@
public class Grid implements Serializable
for( int i = 0 ; i < al.size() ; i++ )
{
clusters.add( al.get( i ) ) ;
- nb_cluster ++ ;
nbCLusterNodes = al.get( i ).getNbGNode() ;
- nb_node += nbCLusterNodes ;
for( int j = 0 ; j < nbCLusterNodes ; j++ )
{
@@
-82,7
+78,7
@@
public class Grid implements Serializable
*/
public int getNbCluster()
{
- return
nb_cluster
;
+ return
clusters.size()
;
}
@@
-92,7
+88,7
@@
public class Grid implements Serializable
*/
public int getNbGNode()
{
- return
nb_node
;
+ return
gnodesList.size()
;
}
@@
-106,18
+102,6
@@
public class Grid implements Serializable
}
- /**
- * Initialization of clusters.
- */
- public void initClusters()
- {
- for( int i = 0 ; i < nb_cluster ; i++ )
- {
- clusters.get( i ).initIndice() ;
- }
- }
-
-
/**
* Compute and return the distance between two clusters.
* @param _g1 First cluster
@@
-137,30
+121,28
@@
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() ;
}
}
- //
-
if( cluster1.compareTo( cluster2 ) == 0 )
{
- d = 1 ;
+ d = 1
0
;
} else {
if( site1.compareTo( site2 ) == 0 )
{
- d = 2 ;
+ d = 2
0
;
} else {
- d = 3 ;
+ d = 3
0
;
}
}
@@
-196,8
+178,8
@@
public class Grid implements Serializable
/**
- *
Plop !!
- * @param _gnodes
+ *
Upgrade the grid with new nodes.
+ * @param _gnodes
The list of new nodes
*/
public void updateGrid( ArrayList<GNode> _gnodes )
{
@@
-205,7
+187,57
@@
public class Grid implements Serializable
{
for( int i = 0 ; i < _gnodes.size() ; i++ )
{
+ /** Searching the cluster in which the node should be added **/
+ int j = 0 ;
+ for( j = 0; j < clusters.size(); j++ )
+ {
+ if( _gnodes.get( i ).getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
+ {
+ 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 ).setInCluster( true ) ;
+ _gnodes.get( i ).setMapped( false ) ;
+
+ clusters.get( j ).addGNode( _gnodes.get( i ) ) ;
+ gnodesList.add( _gnodes.get( i ) ) ;
+
+ } else {
+ clusters.get( j ).setGNodeStatus( _gnodes.get( i ), _gnodes.get( i ).getMapped() ) ;
+ }
+
+ break ;
+ }
+ }
+ /** The cluster was not found, so it is a new one **/
+ if( j == clusters.size() )
+ {
+ String site = "", cluster = "" ;
+ Cluster nClust = new Cluster() ;
+
+
+ String names[] = Utils.decodeG5Knames( _gnodes.get( i ).getName() ) ;
+
+ cluster = names[ 1 ] ;
+ site = names[ 2 ] ;
+
+ nClust.setName( cluster ) ;
+ nClust.setSite( site ) ;
+
+ _gnodes.get( i ).setInCluster( true ) ;
+ _gnodes.get( i ).setMapped( false ) ;
+ _gnodes.get( i ).setSite( site ) ;
+ _gnodes.get( i ).setCluster( cluster ) ;
+
+ nClust.addGNode( _gnodes.get( i ) ) ;
+
+ clusters.add( nClust ) ;
+ gnodesList.add( _gnodes.get( i ) ) ;
+ }
}
gnodesList_done = false ;
@@
-214,34
+246,92
@@
public class Grid implements Serializable
/**
- *
Remove a computing node from the grid
.
- * @param _
dead The node to be removed
+ *
Upgrade the grid with a new node
.
+ * @param _
g The new node
*/
- public void
removeGNode( GNode _dead )
+ public void
addGNode( GNode _g )
{
- if( _
dead
!= null )
+ if( _
g
!= null )
{
- if( _dead.getMapped() )
+ /** Searching the cluster in which the node should be added **/
+ int j = 0 ;
+ for( j = 0; j < clusters.size(); j++ )
{
- String site = "", cluster = "" ;
-
- site = _dead.getSite() ;
- cluster = _dead.getCluster() ;
-
- /* Removing GNode from its cluster */
- for( int j = 0 ; j < clusters.size() ; j++ )
+ if( _g.getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
{
- if( clusters.get( j ).getName().equals( cluster ) && clusters.get( j ).getSite().equals( site ))
+ int pos = clusters.get( j ).isIn( _g ) ;
+
+ if( pos == -1 )
{
- clusters.get( j ).removeGNode( _dead ) ;
-
- break ;
+ _g.setSite( clusters.get( j ).getSite() ) ;
+ _g.setInCluster( true ) ;
+ _g.setMapped( false ) ;
+
+ clusters.get( j ).addGNode( _g ) ;
+ gnodesList.add( _g ) ;
+
+ } else {
+ clusters.get( j ).removeGNode( _g ) ;
+ clusters.get( j ).addGNode( _g ) ;
}
+
+ break ;
}
}
+
+ /** The cluster was not found, so it is a new one **/
+ if( j == clusters.size() )
+ {
+ String site = "", cluster = "" ;
+ Cluster nClust = new Cluster() ;
+
+ String names[] = Utils.decodeG5Knames( _g.getName() ) ;
+
+ cluster = names[ 1 ] ;
+ site = names[ 2 ] ;
+
+ System.out.println("** (Grid) Creation of cluster: "+cluster);
+
+ nClust.setName( cluster ) ;
+ nClust.setSite( site ) ;
+
+ _g.setInCluster( true ) ;
+ _g.setMapped( false ) ;
+ _g.setSite( site ) ;
+ _g.setCluster( cluster ) ;
+
+ nClust.addGNode( _g ) ;
+
+ clusters.add( nClust ) ;
+ gnodesList.add( _g ) ;
+ }
+ }
+
+ gnodesList_done = false ;
+ }
+
+
+ /**
+ * Remove a computing node from the grid.
+ * @param _dead The node to be removed
+ */
+ public void removeGNode( GNode _dead )
+ {
+ if( _dead != null )
+ {
+ /** Removing GNode from its cluster **/
+ int id = getClusterOfNode( _dead ) ;
- /* Removing the dead node from the global list */
- for( int i = 0 ; i < nb_node ; i++ )
+ if( id != -1 )
+ {
+ clusters.get( id ).removeGNode( _dead ) ;
+ } else {
+ System.err.println( "(Grid) Cluster of dead node not found!" ) ;
+ }
+
+ /** Removing the dead node from the global list **/
+ int i = 0 ;
+ for( i = 0 ; i < gnodesList.size() ; i++ )
{
if( _dead.getId() == gnodesList.get( i ).getId() )
{
@@
-249,13
+339,75
@@
public class Grid implements Serializable
break ;
}
}
+
+ } else {
+ System.err.println( "(Grid) The GNode to be deleted is null!" ) ;
}
-
- 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 )
+ {
+ /** Change in the cluster **/
+ int id = getClusterOfNode( _g ) ;
+
+ if( id != -1 )
+ {
+ clusters.get(id).setGNodeStatus( _g, _status ) ;
+ } else {
+ System.err.println( "(Grid) Cluster "+_g.getCluster()+" not found!" ) ;
+ }
+
+ /** Change in local list **/
+ 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 int getClusterOfNode( GNode _g )
+ {
+ int ret = -1 ;
+
+ if( _g != null )
+ {
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ if( _g.getCluster().equalsIgnoreCase( clusters.get( i ).getName() ) )
+ {
+ if( _g.getSite().equalsIgnoreCase( clusters.get( i ).getSite() ) )
+ {
+ ret = i ;
+ break ;
+ }
+ }
+ }
+ }
+
+ return ret ;
+ }
+
+
/**
* Compute the heterogeneity degree of the grid.
* This is based on the relative standard deviation.
@@
-263,7
+415,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!" ) ;
@@
-275,50
+427,175
@@
public class Grid implements Serializable
double average = 0 ;
double std = 0 ;
double temp = 0 ;
+ long nb_freenodes = 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() ;
+ if( ! gnodesList.get(i).getMapped() )
+ {
+ temp += gnodesList.get(i).getPower() ;
+ nb_freenodes++ ;
+ }
}
- average = temp / nb_
node
;
+ average = temp / nb_
freenodes ; //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 ) ;
+ if( ! gnodesList.get(i).getMapped() )
+ {
+ temp += Math.pow( ( gnodesList.get(i).getPower() - average ), 2 ) ;
+ }
}
/** Computation of the standard deviation **/
- temp = temp / nb_
node
;
+ temp = temp / nb_
freenodes ; //gnodesList.size()
;
std = Math.sqrt( temp ) ;
- /** Computation of the relative standard deviation
- * plus modifications
- */
- hd = 100 * std / average / 10 ;
+ /** Computation of the relative standard deviation **/
+ hd = std / average ;
+
+ /** Correction of the maximum value **/
+ if( hd > 1 )
+ {
+ hd = 1 ;
+ }
return hd ;
}
+ /**
+ * Return the amount of nodes available in the cluster containing the
+ * maximum of available nodes.
+ * @return The maximum available nodes of the architecture
+ */
+ public int getMaxClusterNode()
+ {
+ int max = 0 ;
+
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ if( max < clusters.get( i ).getNbFreeNodes() )
+ {
+ max = clusters.get( i ).getNbFreeNodes() ;
+ }
+ }
+
+ return max ;
+ }
+
+
+ /**
+ * Initialization of computing nodes in the grid. Set all
+ * of these nodes to be not mapped on, and do the same thing in each
+ * of its clusters.
+ */
+ public void initGNodes()
+ {
+ /** Initialization of the local nodes **/
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
+ {
+ gnodesList.get( i ).setMapped( false ) ;
+ }
+
+ /** Initialization in clusters **/
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ clusters.get( i ).initGNodes() ;
+ }
+ }
+
+
+
+ /**
+ * Initialization of a set of computing nodes in the grid. Set all
+ * of these given nodes to be not mapped on, and propagates in each
+ * of its clusters.
+ * @param _ag The nodes' list to initialize
+ */
+ public void initGNodes( ArrayList<GNode> _ag )
+ {
+ if( _ag != null && _ag.size() > 0 )
+ {
+ /** Initialization of the local and clusters nodes **/
+ for( int i = 0 ; i < _ag.size() ; i++ )
+ {
+ setMappedStatus( _ag.get( i ), false ) ;
+
+ int id = getClusterOfNode( _ag.get( i ) ) ;
+
+ if( id != -1 )
+ {
+ clusters.get(id).setGNodeStatus( _ag.get( i ), false ) ;
+ } else {
+ System.err.println( "Cluster not found" ) ;
+ }
+ }
+ }
+ }
+
+
+
/**
* Print a comprehensible text version of the grid.
*/
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() ) ;
}
System.out.println();
}
+
+
+ /**
+ * Return the average power of the grid, by computing the average for
+ * eac cluster.
+ * @return The average power of the grid
+ */
+ public double getAvgFreePower()
+ {
+ double ret = 0 ;
+ int nb = 0 ;
+
+ if( clusters != null && clusters.size() > 0 )
+ {
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ nb++ ;
+
+ ret += clusters.get( i ).getAvailablePower() / clusters.get( i ).getNbFreeNodes() ;
+ }
+
+ ret = ret / nb ;
+
+ }
+
+ return ret ;
+ }
+
+
+ /**
+ * Return the amount of freenodes available in the whole grid.
+ * @return The amount of available nodes
+ */
+ public int getNbFreenodes()
+ {
+ int ret = 0 ;
+
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ ret += clusters.get(i).getNbFreeNodes() ;
+ return ret ;
+ }
}