3 import java.io.Serializable;
4 import org.objectweb.proactive.api.PAGroup;
5 import org.objectweb.proactive.core.group.Group;
8 * Class which manages the convergence of a problem.
9 * @author Sébastien Miquée
12 public class Convergence implements Serializable
14 /** Local variables **/
15 private static final long serialVersionUID = 1L ;
16 private boolean total[] ;
17 private short nbconv[] ;
18 private short taille ;
19 private boolean conv ;
20 private Group<AILObject> as ;
22 private short attente ;
23 private short maxIterBeforeConv ;
24 private short __tag = 999 ;
27 * Empty constructor for the stub generation.
35 * @param nb : number of worker.
37 public Convergence( short nb )
40 total = new boolean[ taille ] ;
41 nbconv = new short[ taille ] ;
44 maxIterBeforeConv = 0 ;
48 for( short i = 0 ; i < taille ; i++ )
55 * Set the ALPA group, in order to communicate with workers.
56 * @param group : AALPA group.
58 public void majGroup( AILObject group )
60 as = PAGroup.getGroup( group ) ;
64 * Method to detect convergence in asynchronous mode.
65 * @param id : rank of the worker.
66 * @param b : convergence detected by the worker.
68 public synchronized void convergeAsync( short id, boolean b )
74 if( maxIterBeforeConv != 0 )
80 if( nbconv[ id ] == maxIterBeforeConv )
88 for( short i = 0 ; i < taille ; i++ )
90 tmp = tmp && total[i] ;
98 as.get( id ).recvObject( taille, conv, __tag ) ;
104 Method to detect convergence in synchronous mode.
105 * @param id : rank of the worker.
106 * @param b : convergence detected by the worker.
108 public synchronized void convergeSync( short id, boolean b )
120 for( short i = 0 ; i < taille ; i++ )
122 tmp = tmp && total[i] ;
127 for( short i = 0 ; i < taille ; i++ )
129 as.get( i ).recvObject( taille, conv, __tag ) ;
136 as.get( id ).recvObject( taille, conv, __tag ) ;
141 * Initialization of the convergence.
145 total = new boolean[ taille ] ;
146 nbconv = new short[ taille ] ;
150 for( short i = 0 ; i < taille ; i++ )
157 * Sets the number of time the convergence should be detected by a worker.
158 * (it is in the way to avoid the yo-yo effect)
159 * It is used only in asynchronous mode.
162 public void setIterBeforeConv( short _nb )
166 maxIterBeforeConv = _nb ;
168 maxIterBeforeConv = 0 ;
173 * Indicates that all workers have stopped.
175 public void termine()
181 * Return the status of all workers, to the Main program.
182 * @return : the status of all workers.
190 /** La programmation est un art, respectons ceux qui la pratiquent !! **/