3 import java.io.FileOutputStream;
4 import java.io.OutputStreamWriter;
5 import java.io.PrintWriter;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
8 import java.rmi.UnmarshalException;
9 import java.util.Calendar;
10 import java.util.GregorianCalendar;
11 import java.util.Random;
12 import java.util.Vector;
14 import and.Mapping.Algo;
15 import and.Mapping.Utils;
17 public class JaceSpawner {
20 private Task tache = null;
21 public static JaceSpawner Instance;
22 private static String superNode_IP = null;
23 private int superNode_port = 1098;
24 private static int spawnerPort = 1098;
25 protected static JaceSuperNodeInterface centralServer = null;
26 private JaceSpawnerInterface spawnerRef = null;
28 private String appliName;
29 private String[] params = null;
30 @SuppressWarnings("unused")
31 private String protocol;
32 // private int registerVersion=0;
33 final int NB_HEART_DECONNECT = 3;
34 private int heartTime; // frequency of heartBeat
35 @SuppressWarnings("unused")
36 private int timeBeforeKill; // wait 3 non-response of heartBeat before
37 // considering de Daemon as dead
38 private boolean broadcasting = false;
39 @SuppressWarnings("unused")
41 private static int nbOfDaemonsPerSpawner;
42 private static int nbOfDeamonsPerThread;
43 private Vector<Object> spawnersList;
45 private int nbSavingNodes;
47 // Variables for Mapping
49 private double paramAlgo ;
50 private String idAlgo ;
55 protected int nbFault ;
56 protected int faultTime ;
58 public JaceSpawner(String superNode, int port, String comProtocol,
59 String[] args, int nbDaemonPerSpawner, int nbDaemonPerThread,
60 int nbSavingNodes, int _algo, double _paramAlgo, int _test, int _nbF, int _fT) {
61 // superNode_IP = LocalHost.Instance().resolve(superNode);
63 paramAlgo = _paramAlgo ;
71 superNode_IP = superNode;
73 protocol = comProtocol;
74 nbOfDaemonsPerSpawner = nbDaemonPerSpawner;
75 nbOfDeamonsPerThread = nbDaemonPerThread;
76 this.nbSavingNodes = nbSavingNodes;
79 // if less than 2 params (nb of tasks and name of the appli), error
80 System.err.println( "Parameters error !" ) ;
84 nbTasks = new Integer(args[0]).intValue(); // nb of tasks
87 } catch (Exception e) {
88 System.err.println("Number format exception :" + e ) ;
91 appliName = args[1]; // name of the class to launch
92 if (args.length > 2) { // get the eventual param of the appli
93 params = new String[args.length - 2];
94 for (int i = 0; i < params.length; i++) {
95 params[i] = args[2 + i];
99 c = load.load(appliName);
101 tache = ((Task) c.newInstance());
102 tache.setParam(params);
103 tache.setJaceSize(nbTasks);
105 // ****************//
107 } catch (Exception e) {
108 System.err.println( "Unable to instantiate the class " + e ) ;
118 public JaceSpawner(String[] params, String appliName, Register reg,
119 int nbTasks, JaceSuperNodeInterface snodeStub, int rank,
120 int heartTime, int tag, int nbdc, int nbsdc,
121 int nbDaemonPerSpawner, int nbDaemonPerThread, String _idAlgo) {
123 nbOfDaemonsPerSpawner = nbDaemonPerSpawner;
124 nbOfDeamonsPerThread = nbDaemonPerThread;
125 if (params.length != 0) {
126 this.params = new String[params.length];
127 for (int i = 0; i < params.length; i++)
128 this.params[i] = params[i];
131 System.err.println( "There is no parameter !" ) ;
133 } catch (Exception e) {
134 System.err.println("Error in copying the parameters: " + e ) ;
139 this.appliName = appliName;
141 this.nbTasks = nbTasks;
142 this.heartTime = heartTime;
143 LocalHost.Instance().setSuperNodeStub(snodeStub);
144 centralServer = snodeStub;
146 Register.Instance().replaceBy(reg);
147 Register.Instance().setSpawnerStub(this.spawnerRef);
148 Register.Instance().getListeOfTasks().viewAll();
152 c = load.load(appliName);
154 tache = ((Task) c.newInstance());
155 tache.setParam(params);
156 tache.setJaceSize(nbTasks);
157 // ****************//
159 } catch (Exception e) {
160 System.err.println("Unable to instantiate the class " + e);
162 RunningApplication.Instance().getChrono().start();
164 RunningApplication.Instance().setName(appliName);
165 RunningApplication.Instance().setNbTasks(nbTasks);
166 RunningApplication.Instance().setRunning(true);
167 RunningApplication.Instance().setNumberOfDisconnections(nbdc);
168 RunningApplication.Instance().setNumberOfSpawnerDisconnections(nbsdc);
172 broadcastRegister(1);
175 * x=Register.Instance().getListeOfTasks().getSize()/nbOfDaemonsPerSpawner
176 * ; int s; if(rank==x)
177 * s=(reg.getListeOfTasks().getSize()%nbOfDaemonsPerSpawner
178 * )/nbOfDeamonsPerThread; else
179 * s=nbOfDaemonsPerSpawner/nbOfDeamonsPerThread;
181 * int debut=nbOfDaemonsPerSpawnerrank;
184 * for(int i=0;i<s+1;i++){
186 * new BroadcastSpawner(i,
187 * debut,nbOfDaemonsPerSpawner,nbOfDeamonsPerThread).start(); }
191 System.out.println("########################");
194 public synchronized static JaceSpawner Instance() {
198 public int getNbOfDeamonsPerThread() {
199 return nbOfDeamonsPerThread;
202 public int getNbOfDeamonsPerSpawner() {
203 return nbOfDaemonsPerSpawner;
206 public void startProcess(Vector<Object> spawnersList) {
207 this.spawnersList = spawnersList;
209 int is = spawnersList.indexOf((Object) Register.Instance()
214 if (is == spawnersList.size() - 1)
217 nextNeighbour = is + 1;
219 * while((spawnersList.elementAt(nextNeighbour) instanceof Node))
221 * System.out.println("waiting till transform of spawner "+nextNeighbour
222 * +" is finished, for setServer"); Thread.sleep(20);
223 * }catch(Exception e1){}
225 HeartBeatSpawner.Instance().setServer(
226 (JaceSpawnerInterface) spawnersList.get(nextNeighbour));
227 HeartBeatSpawner.Instance().setHeartTime(heartTime);
228 HeartBeatSpawner.Instance().start();
229 int previousNeighbour;
231 previousNeighbour = spawnersList.size() - 1;
233 previousNeighbour = is - 1;
234 ScanThreadSpawner.Instance().setHeartTime(heartTime);
235 ScanThreadSpawner.Instance().setServer(
236 (JaceSpawnerInterface) spawnersList.get(previousNeighbour));
237 ScanThreadSpawner.Instance().start();
241 new StartScanning().start();
243 System.err.println("Cannot find myself in the spawnersList !");
248 public void setBroadcasting(boolean bool) {
252 public void initialize() {
253 // if(protocol.equals("rmi")){
254 // launch the JaceSpawnerServer
255 if (System.getSecurityManager() == null) {
256 System.setSecurityManager(new SecurityManager());
265 // get a Register on the Super Node
266 // completed with the required number of Daemons
267 getRegisterOnSuperNode();
270 createSpawnerNetwork();
273 new FaultMake().run() ;
277 public void startScanning() {
279 long time = RunningApplication.Instance().getChrono().getValue() / 1000;
280 System.out.println("Start scanning at time: " + time + "s");
281 // lancer le chrono qui gere les heart beat
282 while (RunningApplication.Instance().isRunning() == true) {
283 // 1 etape : scaner tous les "heartTime" milisecondes si les noeuds
284 // enregistes sont encore vivants
285 // res = scanConnectedHosts();
287 // 2 etape : a garder ou pas !!!!! regarder si l'appli est en
288 // attente de noeud pr lui en attribuer 1 nvx
291 Thread.sleep(heartTime);
292 } catch (Exception e) {
295 // /System.out.println("is running = false");
296 if (!JaceDaemon.Instance().isRunning())
300 public synchronized void signalDeadNode(JaceInterface host, int rankOfDead) {
303 TaskId myTaskId = null;
307 RunningApplication.Instance().incrementNumberOfDisconnections();
309 time = RunningApplication.Instance().getChrono().getValue() / 1000;
310 nb = RunningApplication.Instance().getNumberOfDisconnections();
311 nbC = RunningApplication.Instance().getNumberOfCouilles();
312 System.out.println("At time = " + time + "s, NbDisconnection = "
313 + nb + ", NbProblem = " + nbC);
316 System.err.println( "SIGNAL DE NODE NULL" ) ;
318 // !!!!!!!!!!!!!!actualiser le ListeTask ds le Register
320 myTaskId = Register.Instance().getListeOfTasks()
321 .getTaskIdOfHostStub(host);
322 } catch( Exception e ) {}
324 if (myTaskId == null) {
325 myTaskId = Register.Instance().getListeOfTasks()
326 .getTaskIdOfRank(rankOfDead);
327 if( myTaskId == null )
329 System.err.println("Houston we have a serious problem!!");
333 JaceInterface deadStub = myTaskId.getHostStub();
335 if( deadStub != null )
338 deadStub.suicide2("Not doing a good work");
339 }catch(Exception e){}
341 System.err.println( "Dead node stub unavailable!" );
345 Node noeud = Register.Instance().getNodeOfName( myTaskId.getHostName() ) ;
347 int rankDeaD = myTaskId.getRank();
349 String nomNoeud = "" ;
353 nomNoeud = noeud.getName();
358 if( ! nomNoeud.equals( "" ) )
360 b = Register.Instance().removeNodeOfName( nomNoeud ) ;
362 System.err.println( "Dead node name unknown!!" ) ;
367 b = Register.Instance().removeNode( noeud ) ;
372 System.out.println("Removing Node of rank "
373 + rankDeaD + " : size = "
374 + Register.Instance().getSize());
377 .println("Cannot remove the Node, it doesn't exist anymore: size = "
378 + Register.Instance().getSize());
381 Calendar cal = new GregorianCalendar();
382 System.out.println("At time=" + cal.get(Calendar.MINUTE) + ":"
383 + cal.get(Calendar.SECOND));
385 /**** Sébastien Miquée **/
386 Node tmpNode = null ;
387 int retry = 0, retryMax = 4 ;
389 while( tmpNode == null )
391 tmpNode = foundToReplaceThisNode(rankDeaD, nomNoeud, noeud);
393 if( tmpNode == null )
396 Thread.sleep( 1000 ) ;
397 } catch( Exception e ) {}
401 if( retry > retryMax )
403 System.err.println( "Unable to replace the dead node "+nomNoeud ) ;
410 updateConcernedNodes(rankDeaD, noeud, tmpNode);
413 System.out.println("Set scanning on "+tmpNode.getName());
414 tmpNode.getStub().setScanning( true ) ;
415 } catch (Exception e) {
417 Thread.sleep( 2000 ) ;
419 tmpNode.getStub().setScanning( true ) ;
420 } catch (InterruptedException e1) {
421 } catch (RemoteException e2) {
422 System.err.println( "Unable to setScanning on for the new node: " + e2 ) ;
424 System.err.println("Unable to setScanning on for the new node: "
428 for (int z = 0; z < spawnersList.size(); z++)
430 if (!((JaceSpawnerInterface) spawnersList.get(z))
431 .equals(Register.Instance().getSpawnerStub()))
434 ((JaceSpawnerInterface) spawnersList.get(z))
435 .replaceDeamonBy(noeud, tmpNode, rankDeaD);
437 } catch (Exception e) {
439 .println("Unable to broadcast the modifications to all the spawners: "
446 // verifie si les noeud notes vivant ds le Register.Instance() du SuperNode
448 // retourne 0 si erreur, 1 sinon
450 * private synchronized int scanConnectedHosts() { long time = 0; Node host;
451 * Node tmpNode; long workerTime; long currentTime; int rank; int restempo;
452 * int nb = 0; int nbC = 0; boolean changed = false; int index=0; try{
453 * JaceSpawnerInterface spawnerStub=Register.Instance().getSpawnerStub();
454 * if(spawnerStub.getFinished()==true){
455 * System.out.println("nbre de taches="+Register.Instance().getSize());
456 * ListeTask t=Register.Instance().getListeOfTasks();
457 * for(index=z;index<t.getSize();index++){ TaskId recev = null;
458 * System.out.println("deleting Task************"+index);
460 * recev = t.get(index); JaceInterface stub=recev.getHostStub();
461 * spawnerStub.killApplication(stub); }
465 * } }catch(Exception e){
466 * System.out.println("w aiiiiiiiiiiiiiirrrr"+e+" index="+index); z=index;
469 * if (Register.Instance().getSize() == 0) {
470 * System.out.println("aucun noeuds a scanner");
471 * RunningApplication.Instance().purge(); System.exit(0);
478 // trouver un noeud sur les superNode
479 // pr les requisitionner
481 /*** Sébastien Miquée ***/
482 private synchronized Node foundToReplaceThisNode(int theRank, String nom, Node _n)
484 boolean found = false ;
488 while( found == false ) {
492 node = centralServer.getNewNode( idAlgo, theRank ) ;
494 if( node != null && ! node.getIP().isEmpty() && node.getIP() != null
495 && ! node.getIP().equals( "" ) )
499 System.err.println("Returned node is null!");
502 Thread.sleep( 2000 ) ;
503 } catch( Exception e ) {}
505 } catch (Exception e) {
506 // trouver un autre superNode et lui demander le noeud a lui
508 System.err.println("Cannot localize SuperNode ! " + e);
513 if( Register.Instance().existNode( node ) != -1 )
522 System.out.println( "Using Node " + node.getName() + " in order to replace " + nom + "\n" ) ;
524 node.setAliveFlag(true);
527 // rajouter le noeud ds le Register
528 node.setAppliName(RunningApplication.Instance().getName());
530 // lui envoyer mon stub pr qu'il commence a me pinguer des
532 // TODO a mettre ds un thread ????
536 * neighborTask=Register.Instance().getListeOfTasks().getTaskIdOfRank
537 * ((theRank+1)%Register.Instance().getListeOfTasks().getSize());
538 * try{ node.getStub().updateHeart(neighborTask.getHostStub()); }
539 * catch(Exception e) {
540 * System.out.println("nvx noeud deja plu dispo2"); //node = null; }
542 // TODO verif pourkoi superNode me le redonne
543 // alors qu'il fait deja du calcul
544 // int is = Register.Instance().existNode(node.getIP());
545 int is = Register.Instance().existNode( node ) ;
549 System.out.println("The Node is already in the register ! I don't add it.");
550 System.out.println("Node " + node.getName() + " not added !") ;
553 Register.Instance().addNode(node);
555 // !!!!!!!!!!!!!!actualiser le ListeTask
556 TaskId myTaskId = Register.Instance().getListeOfTasks()
557 .getTaskIdOfRank(theRank);
558 myTaskId.setHostIP(node.getIP());
559 myTaskId.setHostName(node.getName());
560 myTaskId.setHostStub(node.getStub());
565 neighborRank = Register.Instance().getSize() - 1;
567 neighborRank = theRank - 1;
570 TaskId neighborTask2 = Register.Instance().getListeOfTasks()
571 .getTaskIdOfRank( neighborRank ) ;
573 int loop = 0, MAX_LOOP = 1 ;
575 JaceInterface jaceStub = null ;
577 while( !ok && loop < MAX_LOOP )
580 jaceStub = neighborTask2.getHostStub();
581 jaceStub.updateHeart(node.getStub());
584 } catch( Exception e ) {
587 if( loop < MAX_LOOP )
590 Thread.sleep( loop * 2000 ) ;
591 } catch (InterruptedException e1) {}
594 if( loop == MAX_LOOP )
596 System.err.println( "Next node unreachable! " + e ) ;
601 if( loop == MAX_LOOP )
605 node.getStub().suicide2( "Not reachable!" ) ;
606 } catch (RemoteException e1) {
607 System.err.println( "Unable to suicide the node!\n"+e1 );
608 signalDeadNode( null, neighborTask2.getRank() ) ;
615 System.out.println("I didn't receive a new Node !");
620 public void replaceBy(JaceSpawnerInterface oldStub,
621 JaceSpawnerInterface stub) {
622 int index = spawnersList.indexOf((Object) oldStub);
624 spawnersList.setElementAt(stub, index);
626 System.err.println("Spawner's stub not foud in spawnersList !");
629 public void getNewSpawner(JaceSpawnerInterface previousSpawner) {
630 //boolean found = false;
633 JaceSpawnerInterface spawnerStub = null;
635 // while (found == false) {
637 // TODO : trouver l'erreur !!!
639 // "pas localise le super node java.lang.NullPointerException"
640 if (centralServer == null) {
641 System.err.println("Central Server not localized !");
643 node = centralServer.getNewNode( idAlgo, -2 ) ;
644 RunningApplication.Instance()
645 .incrementNumberOfSpawnerDisconnections();
647 } catch (Exception e) {
648 // trouver un autre superNode et lui demander le noeud a lui
649 System.err.println("Super Node not localized !\n " + e);
650 System.err.println("My IP : " + LocalHost.Instance().getIP());
651 if (centralServer == null) {
652 System.err.println("CentralServer is NULL !");
658 index = spawnersList.indexOf((Object) previousSpawner);
660 System.out.println("Using Node " + node.getName()
662 + LocalHost.Instance().resolve(node.getName())
663 + ") to replace a dead spawner\n\n");
665 spawnerStub = node.getStub().transformIntoSpawner(
674 RunningApplication.Instance()
675 .getNumberOfDisconnections(),
676 RunningApplication.Instance()
677 .getNumberOfSpawnerDisconnections(),
678 nbOfDaemonsPerSpawner, nbOfDeamonsPerThread
680 spawnersList.setElementAt(spawnerStub, index);
683 new StartProcessThread(index).start();
685 } catch (Exception e) {
686 System.err.println("Unable to reach the new spawner: " + e);
688 for (int j = 0; j < spawnersList.size(); j++)
690 if (!((JaceSpawnerInterface) spawnersList.get(j))
691 .equals(Register.Instance().getSpawnerStub())
692 && !((JaceSpawnerInterface) spawnersList.get(j))
693 .equals(spawnerStub)) {
695 .println("Trying to broadcast to spawner of rank "
698 ((JaceSpawnerInterface) spawnersList.get(j))
699 .replaceBy(previousSpawner, spawnerStub);
701 } catch (Exception e) {
703 .println("Unable to broadcast to spawner of rank: "
704 + j + ". Error:" + e);
706 ScanThreadSpawner.Instance().setServer(spawnerStub);
710 previous = spawnersList.size() - 1;
712 previous = index - 1;
714 ((JaceSpawnerInterface) spawnersList.get(previous))
715 .updateHeart(spawnerStub);
716 } catch (Exception e) {
718 .println("Unable to change the server of the heartbeatThread for the previous node of rank "
719 + previous + ". error:" + e);
723 System.err.println("Node is null !");
728 public void broadcastFinished(boolean bool) {
729 for (int i = 0; i < spawnersList.size(); i++)
731 ((JaceSpawnerInterface) spawnersList.get(i)).setFinished(bool);
732 } catch (Exception e) {
734 .println("Unable to propagate the end of the application :"
739 private synchronized void scanAppliNodes() {
742 //ListeTask tskList = null;
746 JaceSpawnerInterface spawnerStub = Register.Instance()
748 if (spawnerStub.getFinished() == true) {
749 System.out.println("Number of tasks ="
750 + Register.Instance().getSize());
752 int x = Register.Instance().getListeOfTasks().getSize()
753 / nbOfDaemonsPerSpawner;
756 s = (Register.Instance().getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
757 / nbOfDeamonsPerThread;
759 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread;
761 int debut = nbOfDaemonsPerSpawner * rank;
763 // for(int i=debut;i<nbOfDaemonsPerSpawner*(rank+1) &&
764 // i<reg.getSize();i++)
765 // System.out.println(((Node)nodes.elementAt(i)).getName());
767 ListeTask t = Register.Instance().getListeOfTasks();
768 ScanThreadSpawner.Instance().kill();
769 HeartBeatSpawner.Instance().kill();
771 for (int i = 0; i < s + 1; i++) {
773 new KillThread(i, debut, nbOfDaemonsPerSpawner,
774 nbOfDeamonsPerThread, t).start();
779 long finalTime = RunningApplication.Instance().getChrono()
782 int nbe = RunningApplication.Instance()
783 .getNumberOfDisconnections();
785 int nbsdc = RunningApplication.Instance()
786 .getNumberOfSpawnerDisconnections();
788 System.out.println("Application finished successfully !");
790 System.out.println("TOTAL TIME in s : " + (finalTime / 1000));
791 System.out.println("nb of desconnections: " + nbe);
792 System.out.println("nb of spawners desconnections: " + nbsdc);
795 String path = "/home/lyon/smiquee/resultats/execTime_"+algo+"_"+test ;
796 PrintWriter ecrivain = null ;
797 ecrivain = new PrintWriter( new OutputStreamWriter( new FileOutputStream( path ), "UTF8" ) ) ;
799 ecrivain.println( "TOTAL TIME in s : " + (finalTime / 1000));
800 ecrivain.println( "nb of desconnections: " + nbe);
801 ecrivain.println( "nb of spawners desconnections: " + nbsdc);
802 ecrivain.println( "DH = "+dh ) ;
808 if (JaceDaemon.Instance().isRunning()) {
809 JaceDaemon.Instance().reconnectSuperNode();
811 RunningApplication.Instance().purge();
816 RunningApplication.Instance().purge();
819 /** Suprresion of the mapping algorithm on the SuperNode **/
820 centralServer.removeAlgo( idAlgo, 0 ) ;
822 } catch( Exception e ) {
823 System.err.println( "Error the application nodes scan!\n " + e ) ;
827 * if (Register.Instance().getSize() == 0) {
828 * System.out.println("aucun noeuds a scanner");
829 * RunningApplication.Instance().purge(); System.exit(0); return 0;
831 * } else{ tskList = Register.Instance().getListeOfTasks();
833 * //si mon appli a besoin d'un noeud //sinon, on fait rien if ((nbTasks
834 * - Register.Instance().getSize()) > 0) { cptReplaced = 0;
836 * //TODO demander des paquet de nodes, pas qu'un //on scanne toutes les
837 * taches de cette appli for (int ind = 0; ind < tskList.getSize();
838 * ind++) { //si 1 tache a pas de noeud, on trouve 1 remplacant
840 * //if (tskList.get(ind).getHostIP() == null) { if
841 * (tskList.get(ind).getHostStub() == null) { rank =
842 * tskList.get(ind).getRank(); node = foundToReplaceThisNodeTMP(rank);
843 * if (node != null) { cptReplaced++; }
847 * //qd fini de scanner taches, envoyer Register //si remplacement de
848 * noeud (c a d si Register modifier) if (cptReplaced != 0) {
849 * broadcastRegister(0); } try { Thread.currentThread().yield(); } catch
852 * }// fin if(appli.getNeededNodes() > 0) {
853 * //System.out.println("SCAN APPLI : taille : " +
854 * Register.Instance().getSize()); return 1; }
858 // @SuppressWarnings("unused")
859 // private synchronized Node foundToReplaceThisNodeTMP(int theRank) {
861 // boolean found = false;
863 // // while (found == false) {
865 // // TODO : trouver l'erreur !!!
867 // // "pas localise le super node java.lang.NullPointerException"
868 // if (centralServer == null) {
869 // System.out.println("centralServer est NUUUUUUUUULL");
871 // node = centralServer.getNewNode(LocalHost.Instance().getIP());
874 // } catch (Exception e) {
875 // // trouver un autre superNode et lui demander le noeud a lui
876 // System.out.println("TMP pas localise le super node " + e);
877 // System.out.println("TMP pas localise le super node " + e);
878 // System.out.println("TMP pas localise le super node " + e);
879 // System.out.println("TMP pas localise le super node " + e);
880 // System.out.println("TMP pas localise le super node " + e);
881 // System.out.println("TMP pas localise le super node " + e);
882 // System.out.println("TMP pas localise le super node " + e);
883 // System.out.println("mon IP : " + LocalHost.Instance().getIP());
884 // if (centralServer == null) {
885 // System.out.println("centralServer : NULL");
887 // connectSuperNode();
890 // if (node != null) {
891 // System.out.println("COOOOOOOOOOOOOOOOOOOOOOL : requisition de "
892 // + node.getName() + " taille avt add: "
893 // + Register.Instance().getSize() + "\n\n");
894 // node.setAliveFlag(true);
895 // node.setAliveTime();
897 // // rajouter le noeud ds le Register
898 // System.out.println("ds Register, manque "
899 // + (nbTasks - Register.Instance().getSize()));
900 // node.setAppliName(RunningApplication.Instance().getName());
902 // // lui envoyer mon stub pr qu'il commence a me pinguer des
904 // // TODO a mettre ds un thread ????
906 // TaskId neighborTask = Register.Instance().getListeOfTasks()
909 // % Register.Instance().getListeOfTasks()
911 // node.getStub().updateHeart(neighborTask.getHostStub());
912 // // node.getStub().updateHeart(this.spawnerRef);
914 // // int is = Register.Instance().existNode(node.getIP());
915 // int is = Register.Instance().existNode(node);
916 // // TODO verif pourkoi superNode me le redonne
917 // // alors qu'il fait deja du calcul
919 // System.out.println("j'ajoute pas le noeud, il y est deja");
920 // System.out.println("PAS AJOUTEE TMP " + node.getName());
921 // System.out.println("PAS AJOUTEE TMP " + node.getName());
922 // System.out.println("PAS AJOUTEE TMP " + node.getName());
923 // System.out.println("PAS AJOUTEE TMP " + node.getName());
924 // System.out.println("PAS AJOUTEE TMP " + node.getName());
927 // Register.Instance().addNode(node);
929 // // !!!!!!!!!!!!!!actualiser le ListeTask
930 // TaskId myTaskId = Register.Instance().getListeOfTasks()
931 // .getTaskIdOfRank(theRank);
932 // myTaskId.setHostIP(node.getIP());
933 // myTaskId.setHostName(node.getName());
934 // myTaskId.setHostStub(node.getStub());
935 // // Register.Instance().getListeOfTasks().getTaskIdOfRank(theRank).setHostIP(node.getIP());
936 // // Register.Instance().getListeOfTasks().getTaskIdOfRank(theRank).setHostName(node.getName());
937 // // Register.Instance().getListeOfTasks().getTaskIdOfRank(theRank).setHostStub(node.getStub());
939 // } catch (Exception e) {
940 // System.out.println("nvx noeud deja plu dispo");
944 // System.out.println("RADINNNNNNNNNNNNNN TMP ");
949 private void exportObject() {
951 JaceSpawnerServer spawnerServer = null;
953 System.out.println("Name of local machine is: "
954 + LocalHost.Instance().getName());
955 System.out.println("IP of local machine is: "
956 + LocalHost.Instance().getIP());
958 // launch the JaceSpawnerServer
959 spawnerServer = new JaceSpawnerServer();
960 java.rmi.registry.LocateRegistry.createRegistry(spawnerPort);
961 java.rmi.registry.LocateRegistry.getRegistry(spawnerPort).rebind(
962 "JaceSpawnerServer", spawnerServer);
963 spawnerRef = (JaceSpawnerInterface) Naming.lookup("rmi://"
964 + LocalHost.Instance().getIP() + ":" + spawnerPort
965 + "/JaceSpawnerServer");
967 } catch (Exception e) {
969 .println("JaceP2P_Error in JaceSpawner.exportObject() when creating the local JaceSpawnerServer "
971 // System.err.println("exit ds JaceSpawner.exportObject");
977 public void connectSuperNode() {
978 System.out.println("I'm looking for a super node");
979 boolean connected = false;
980 if (!(superNode_IP == null)) {
982 centralServer = null ;
985 System.out.println("Trying to invoke super node "
987 centralServer = (JaceSuperNodeInterface) Naming.lookup("rmi://"
988 + superNode_IP + ":" + superNode_port
990 System.out.println("Succesfully located " + superNode_IP);
992 // add stub and IP in LocalHost to store it until super node
994 LocalHost.Instance().setSuperNodeStub(centralServer);
995 LocalHost.Instance().setSuperNodeIP(superNode_IP);
996 heartTime = centralServer.getSuperNodeBeat();
997 timeBeforeKill = NB_HEART_DECONNECT * heartTime;
1000 } catch (Exception e) {
1001 System.err.println("Super Node not accessible, try another one (1/2s)");
1004 } catch (Exception e1) {
1009 if (connected == false) {
1011 SuperNodeListe.Instance().staticInitialization();
1012 while (connected == false
1013 && i < SuperNodeListe.Instance().getListe().size()) {
1014 SuperNodeData d = null;
1015 d = SuperNodeListe.Instance().getSuperNodeData(i);
1017 superNode_IP = LocalHost.Instance().resolve(d.getIP());
1018 superNode_port = d.getPort();
1019 // superNode_port = d.getPort();
1021 System.out.println("Trying to invoke Super Node "
1023 centralServer = (JaceSuperNodeInterface) Naming
1024 .lookup("rmi://" + superNode_IP + ":"
1025 + superNode_port + "/JaceSuperNode");
1026 System.out.println("Succesfully located SuperNode "
1028 LocalHost.Instance().setSuperNodeStub(centralServer);
1029 LocalHost.Instance().setSuperNodeIP(superNode_IP);
1030 heartTime = centralServer.getSuperNodeBeat();
1031 timeBeforeKill = NB_HEART_DECONNECT * heartTime;
1034 } catch (Exception e) {
1036 .println("SuperNode "
1038 + " not accessible, trying to locate another one in 0.5s\n");
1042 } catch (Exception e1) {
1048 if (connected == false) {
1049 System.err.println("All the Super Nodes in the list are not accessible. I'm unable to connect to the platform !");
1055 // get a Register on the SuperNode
1056 // completed with the required number of Daemons
1058 public synchronized void getRegisterOnSuperNode() {
1059 Register registerSpawner = null;
1061 boolean recieved = false;
1063 idAlgo = LocalHost.Instance().getIP() + ":" + LocalHost.Instance().getPort() ;
1065 System.out.println("Trying to get a Register on the SuperNode");
1066 int nbExtraSpawners = 0;
1067 if (nbTasks > nbOfDaemonsPerSpawner) {
1068 nbExtraSpawners = (nbTasks - 1) / nbOfDaemonsPerSpawner;
1073 registerSpawner = centralServer.getRegisterSpawner(idAlgo,
1074 nbTasks, (Task) tache, nbTasks
1075 + nbExtraSpawners, algo, paramAlgo);
1077 } catch (Exception e) {
1079 .println("Unable to recieve a register from superNode "
1087 Algo al = centralServer.getAlgo( idAlgo ) ;
1089 dh = al.getGrid().getHeterogenityDegre() ;
1090 System.out.println( "### DH = " + dh ) ;
1092 Utils.writeGraph( al.getGraph(), "/home/lyon/smiquee/resultats/",
1093 "graph_"+algo+"_"+test+".xml" ) ;
1094 Utils.writeGrid( al.getGrid(), "/home/lyon/smiquee/resultats/",
1095 "grid_"+algo+"_"+test+".xml") ;
1096 Utils.writeMapping( al.getMapping(), "/home/lyon/smiquee/resultats/",
1097 "mapping_"+algo+"_"+test+".xml" ) ;
1098 } catch (RemoteException e1) {
1099 System.err.println( "Problème avec Algo dans Spawner !" ) ;
1100 e1.printStackTrace();
1103 if (registerSpawner.getSize() != (nbTasks + nbExtraSpawners)) {
1104 System.err.println("I did not recieve enough nodes from superNode!!!! \n killing application !!!!");
1105 for (int i = 0; i < registerSpawner.getSize(); i++) {
1107 registerSpawner.getNodeAt(i).getStub().suicide( "Not enough nodes for the application" ) ;
1109 } catch (Exception e) {
1110 System.err.println("The reserved node was unable to reconnect to the super node");
1116 spawnersList = new Vector<Object>();
1117 for (int i = 0; i < nbExtraSpawners && i < registerSpawner.getSize(); i++) {
1118 spawnersList.add(registerSpawner.getNodeAt(0));
1120 registerSpawner.removeNodeOfName(registerSpawner.getNodeAt(0).getName());
1124 registerSpawner.setNbOfTasks(nbTasks);
1125 registerSpawner.setNumBackupNeighbors(nbSavingNodes);
1127 * System.out.println("Trying to connect another SuperNode");
1128 * connectSuperNode(); try { registerSpawner =
1129 * centralServer.getRegisterSpawner(LocalHost.Instance().getIP(),
1130 * nbTasks); } catch(Exception e1) {}
1133 if (registerSpawner != null) {
1134 System.out.println("I received the register");
1135 // registerSpawner.setVersion(registerVersion);
1136 // registerVersion++;
1137 Register.Instance().replaceBy(registerSpawner);
1138 System.out.println("It contains " + Register.Instance().getSize()
1139 + " Nodes" + " " + nbExtraSpawners + " ExtraSpawners");
1141 // set each Node aliveTime value to the Spawner current time
1142 for (int i = 0; i < Register.Instance().getSize(); i++) {
1143 noeud = Register.Instance().getNodeAt(i);
1144 noeud.setAliveFlag(true);
1145 noeud.setAliveTime();
1149 System.err.println("\n---------------WARNING--------------");
1150 System.err.println("No Daemon available on the SuperNode dispo, try later, please");
1156 public class TransformThread extends Thread {
1160 public TransformThread(int i, Node n) {
1168 System.out.println("Trying to transform the spawner ("
1169 + n.getName() + ") of rank " + i);
1170 spawnersList.setElementAt(n.getStub().transformIntoSpawner(
1171 params, appliName, Register.Instance(), nbTasks,
1172 centralServer, i, heartTime, 0, 0, 0,
1173 nbOfDaemonsPerSpawner, nbOfDeamonsPerThread, idAlgo), i);
1174 } catch (Exception e) {
1175 System.err.println("Error while contacting newly acquired spawner ("
1176 + n.getName() + "): " + e);
1178 n = centralServer.getNewNode( LocalHost.Instance().getIP(), null ) ;
1180 new TransformThread(i, n).start();
1181 } catch (Exception e1) {
1182 System.err.println("The Super Node is maybe dead: " + e1) ;
1183 for (int z = 0; z < Register.Instance().getSize(); z++) {
1185 Register.Instance().getNodeAt(z).getStub().suicide2("Problem") ;
1187 } catch (Exception ez) {
1188 System.err.println("The reserved node was unable to reconnect to the super node: \n"
1199 public class FaultMake extends Thread {
1201 public FaultMake(){}
1205 ListeTask t = null ;
1207 int next, old = -1 ;
1209 System.out.println( "Starting fault tolerance !" ) ;
1211 while( ! RunningApplication.Instance().isRunning() )
1213 /** Waiting some time the beginning of the computation **/
1216 } catch (InterruptedException e) {
1220 while( RunningApplication.Instance().isRunning() )
1222 /** Waiting some time ... **/
1224 sleep( faultTime * 1000 ) ;
1225 } catch (InterruptedException e) {
1228 /** ... and kill some daemons ! **/
1229 t = Register.Instance().getListeOfTasks();
1232 for( int i = 0 ; i < nbFault ; i++ )
1234 next = r.nextInt( t.getSize() ) ;
1236 while( next == old )
1238 next = r.nextInt( t.getSize() ) ;
1244 TaskId recev = null;
1245 System.out.println("Making fault on Task" + next);
1247 recev = t.getTaskIdOfRank( next );
1249 JaceInterface stub = recev.getHostStub();
1250 System.out.println("name = " + recev.getHostName());
1251 noeud = Register.Instance().getNodeOfStub( stub ) ;
1253 stub.suicide2( "Test fault tolerance" ) ;
1255 } catch (UnmarshalException ue ){
1256 } catch (Exception e) {
1258 System.err.println("Error in FaultMake on node: "
1259 + noeud.getName() + ". " + e);
1260 } catch (Exception e2) {
1261 System.err.println("(Fault)Error in error:" + e2);
1267 } catch (InterruptedException e) {
1276 public class StartProcessThread extends Thread {
1279 public StartProcessThread(int i) {
1287 * while((spawnersList.elementAt(i) instanceof Node)) try{
1288 * System.out.println("waiting till transform of spawner "+i+
1289 * " is finished"); Thread.sleep(20); }catch(Exception e1){}
1291 // System.out.println("start process on spawner of rank "+i);
1292 JaceSpawnerInterface spawnerStub = (JaceSpawnerInterface) spawnersList.get(i);
1293 spawnerStub.startProcess(spawnersList);
1294 } catch (Exception e) {
1295 e.printStackTrace(System.out);
1296 System.err.println("Unable to start the process on the spawner of rank "
1297 + i + ".error: " + e);
1302 public void createSpawnerNetwork() {
1305 for (i = 0; i < spawnersList.size(); i++) {
1306 n = (Node) spawnersList.elementAt(i);
1308 // Register.Instance().getListeOfTasks().viewAll();
1309 // spawnersList.setElementAt(n.getStub().transformIntoSpawner(
1310 // params, appliName, Register.Instance(),nbTasks, centralServer,i,
1311 // heartTime,0,0),i);
1312 new TransformThread(i, n).start();
1315 // broadcast the Register.Instance() to all the JaceServer
1316 // in order to start each task on the Daemons
1318 spawnersList.add(Register.Instance().getSpawnerStub());
1319 System.out.println(" rank="+rank+" spawnersList.size()=" + spawnersList.size());
1320 rank = spawnersList.size() - 1;
1322 broadcastRegister(1);
1324 for (int j = 0; j < spawnersList.size(); j++) {
1325 System.out.println("waiting till transform of spawner " + j
1327 while ((spawnersList.elementAt(j) instanceof Node))
1332 } catch (Exception e) {
1337 // for (int k = 0; k < spawnersList.size(); k++)
1340 // ((JaceSpawnerInterface) spawnersList.get( k )).setIdAlgo( idAlgo ) ;
1341 // } catch (Exception e) {
1342 // System.err.println("Unable to propagate the mapping algorithm identifier:" + e) ;
1346 System.out.println("End Transformation of all spawners. Beginning the computing processes");
1348 for (i = 0; i < spawnersList.size(); i++) {
1350 // while(!(spawnersList.elementAt(i) instanceof
1351 // JaceSpawnerInterface))
1353 new StartProcessThread(i).start();
1356 System.out.println("End create Spawner Network!!!!!!!!!");
1359 public JaceSpawnerInterface getSpawnerResponsibleOn(int rank) {
1360 int id = rank / nbOfDaemonsPerSpawner;
1361 return (JaceSpawnerInterface) spawnersList.get(id);
1364 public void createAppli() {
1369 ListeTask tsk = new ListeTask();
1371 JaceInterface nodeStub = null;
1372 TaskId myTask = null;
1374 System.out.println("Application launched, starting the chronometer");
1375 RunningApplication.Instance().getChrono().start();
1377 RunningApplication.Instance().setName(appliName);
1378 RunningApplication.Instance().setNbTasks(nbTasks);
1379 // RunningApplication.Instance().setRegister(Register.Instance());
1381 Register.Instance().setParams(params);
1382 Register.Instance().setAppliName(appliName);
1383 Register.Instance().setSpawnerStub(this.spawnerRef);
1385 // assign a TaskId to each Node of the Register
1386 // and insert the TaskId in tke ListTask
1387 while (i < Register.Instance().getSize() && count < nbTasks) {
1388 tmpNode = Register.Instance().getNodeAt(i);
1389 if (tmpNode.getAliveFlag() == true) {
1390 tmpNode.setAppliName(appliName);
1391 nodeStub = tmpNode.getStub();
1392 nodeName = tmpNode.getName();
1393 nodeIP = tmpNode.getIP();
1395 myTask = new TaskId(appliName, count, nodeStub);
1396 myTask.setHostIP(nodeIP);
1397 myTask.setHostName(nodeName);
1399 tsk.addTask(myTask);
1405 // if not enough Nodes in the Register,
1406 // insert not assigned TaskId in the ListTask
1407 if (count < nbTasks) {
1408 for (int j = count; j < nbTasks; j++) {
1409 tsk.addTask(new TaskId(appliName, j, null));
1411 System.out.println("in Register, misses "
1412 + (nbTasks - Register.Instance().getSize()) + " nodes");
1415 // insert the ListeTask in the Register of the appli
1416 Register.Instance().setListeOfTasks(tsk);
1417 // Register.Instance().getListeOfTasks().viewAll();
1418 RunningApplication.Instance().setRunning(true);
1419 System.out.println("fin create appli");
1422 public class BroadcastSpawner extends Thread {
1425 int nbOfDaemonsPerThread, nbOfDeamonsPerSpawner;
1427 public BroadcastSpawner(int i, int debut, int nbOfDeamonsPerSpawner,
1428 int nbOfDaemonsPerThread) {
1431 this.nbOfDaemonsPerThread = nbOfDaemonsPerThread;
1432 this.nbOfDeamonsPerSpawner = nbOfDeamonsPerSpawner;
1437 for (int index = debut + i * nbOfDaemonsPerThread; index < debut
1438 + i * nbOfDeamonsPerThread + nbOfDeamonsPerThread
1439 && index < debut + nbOfDeamonsPerSpawner
1440 && index < Register.Instance().getListeOfTasks().getSize(); index++) {
1442 Register.Instance().getNodeAt(index).getStub().setSpawner(
1443 Register.Instance().getSpawnerStub());
1444 } catch (Exception e) {
1445 System.out.println("can't change spawner stub on node: "
1446 + Register.Instance().getNodeAt(i).getName()
1453 public class KillThread extends Thread {
1456 int nbOfDaemonsPerThread, nbOfDeamonsPerSpawner;
1459 public KillThread(int i, int debut, int nbOfDeamonsPerSpawner,
1460 int nbOfDaemonsPerThread, ListeTask t) {
1463 this.nbOfDaemonsPerThread = nbOfDaemonsPerThread;
1464 this.nbOfDeamonsPerSpawner = nbOfDeamonsPerSpawner;
1471 for (int index = debut + i * nbOfDaemonsPerThread; index < debut
1472 + i * nbOfDeamonsPerThread + nbOfDeamonsPerThread
1473 && index < debut + nbOfDeamonsPerSpawner
1474 && index < t.getSize(); index++) {
1477 TaskId recev = null;
1478 System.out.println("deleting Task" + index);
1480 recev = t.getTaskIdOfRank(index);
1482 JaceInterface stub = recev.getHostStub();
1483 System.out.println("name=" + recev.getHostName());
1484 noeud = Register.Instance().getNodeOfStub(stub);
1485 noeud.setAppliName(null);
1486 new ReconnectThread(stub, noeud.getName()).start();
1487 Register.Instance().removeNode(noeud);
1488 // LocalHost.Instance().getSpawnerStub().killApplication(stub);
1490 } catch (Exception e) {
1492 System.err.println("error in killThread on node "
1493 + noeud.getName() + ". " + e);
1494 } catch (Exception e2) {
1495 System.err.println("error in error :" + e2);
1501 class ReconnectThread extends Thread {
1502 JaceInterface stub = null;
1505 public ReconnectThread(JaceInterface s, String name) {
1512 // System.out.println("reconnexion SuperNode");
1513 // Register.Instance().getNode(workerIP).getWorkerStub().reconnectSuperNode();
1515 // stub.reconnectSuperNode();
1516 stub.suicide("End of application");
1517 } catch (Exception e) {
1518 System.err.println("Cannot kill node " + name);
1526 // faire une copie du Register et l'envoyer aux noeuds qui le compose
1527 // car si il est modif en meme tmp, on envoi pas un truc coherent
1528 private synchronized void broadcastRegister(int requete) {
1529 // Register reg = Register.Instance().clone();
1530 Register reg = Register.Instance();
1533 System.out.println("name of spawner: "
1534 + Register.Instance().getSpawnerStub().getName());
1535 // launch 1 thread to send the Register to all the nodes
1536 while (broadcasting == true)
1538 broadcasting = true;
1539 // Register.Instance().setSpawnerStub(
1540 // Register.Instance().getSpawnerStub());
1541 int x = reg.getListeOfTasks().getSize() / nbOfDaemonsPerSpawner;
1544 if ((reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1545 % nbOfDeamonsPerThread == 0)
1546 s = (reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1547 / nbOfDeamonsPerThread;
1549 s = (reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1550 / nbOfDeamonsPerThread + 1;
1551 else if ((nbOfDaemonsPerSpawner % nbOfDeamonsPerThread) == 0)
1552 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread;
1554 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread + 1;
1555 int debut = nbOfDaemonsPerSpawner * rank;
1556 System.out.println("rank=" + rank + " debut=" + debut + " s=" + s
1557 + " nbOfDaemonsPerSpawner=" + nbOfDaemonsPerSpawner
1558 + " nbOfDeamonsPerThread=" + nbOfDeamonsPerThread + " x="
1560 for (int i = 0; i < s; i++)
1561 new UpdateRegisterThread(tache, reg, requete, i, debut).start();
1563 * This thread : -updates the goal of the Node beats if necessary
1564 * (stub.updateHeart) -updates the Register on each Node
1565 * (stub.updateRegister)
1567 JaceSpawner.Instance().setBroadcasting(false);
1570 } catch (Exception e) {
1573 } catch (Exception e) {
1575 .println("\n1 node has died during JaceSpawner.broadcastRegister()");
1579 private synchronized void broadcastScanning() {
1580 Register reg = Register.Instance();
1581 while (broadcasting == true)
1584 } catch (Exception e) {
1586 // Register.Instance().viewAll();
1587 Vector<?> nodes = (Vector<?>) Register.Instance().getListOfNodes().clone();
1588 int x = reg.getListeOfTasks().getSize() / nbOfDaemonsPerSpawner;
1591 s = (reg.getListeOfTasks().getSize() % nbOfDaemonsPerSpawner)
1592 / nbOfDeamonsPerThread;
1594 s = nbOfDaemonsPerSpawner / nbOfDeamonsPerThread;
1596 int debut = nbOfDaemonsPerSpawner * rank;
1598 // for(int i=debut;i<nbOfDaemonsPerSpawner*(rank+1) &&
1599 // i<reg.getSize();i++)
1600 // System.out.println(((Node)nodes.elementAt(i)).getName());
1602 for (int i = 0; i < s + 1; i++) {
1604 new StartScanThread(i, nodes, debut).start();
1609 @SuppressWarnings("unchecked")
1610 public synchronized Register getRegister( int rank ) {
1612 ListeTask listOfTasks = Register.Instance().getListeOfTasks();
1613 Vector dependencies = getDependencies(rank, listOfTasks.getSize());
1614 Register g = new Register();
1615 ListeTask newListOfTasks = new ListeTask();
1617 g.setAppliName(Register.Instance().getAppliName());
1618 g.setParams(Register.Instance().getParams());
1619 g.setSpawnerStub(Register.Instance().getSpawnerStub());
1620 g.setNbOfTasks(Register.Instance().getNbOfTasks());
1621 // g.setVersion(reg.getVersion());
1623 for (int j = 0; j < dependencies.size(); j++) {
1624 TaskId id = listOfTasks.getTaskIdOfRank(((Integer) dependencies
1625 .elementAt(j)).intValue());
1626 newListOfTasks.addTask(id);
1627 if (id.getHostStub() != null) {
1628 Node noeud = Register.Instance()
1629 .getNodeOfName( id.getHostName() ) ;// (id.getHostStub());
1631 g.addNode( noeud ) ;
1633 System.err.println( "PAS BON DU TOUT" ) ;
1636 g.setListeOfTasks(newListOfTasks);
1640 @SuppressWarnings("unchecked")
1641 private void updateConcernedNodes(int rank, Node oldNode, Node node) {
1642 ListeTask listOfTasks = Register.Instance().getListeOfTasks();
1643 Vector dependencies = getDependencies(rank, listOfTasks.getSize());
1644 System.out.println("List of concerned neighbors of task " + rank+": ");
1645 for (int z = 0; z < dependencies.size(); z++)
1646 System.out.print(((Integer) dependencies.elementAt(z)).intValue()
1648 System.out.println();
1649 // Register.Instance().setVersion(registerVersion);
1650 // registerVersion++;
1651 // Register.Instance()
1652 // .setSpawnerStub(Register.Instance().getSpawnerStub());
1654 if ((dependencies.size() % nbOfDeamonsPerThread) == 0)
1655 s = dependencies.size() / nbOfDeamonsPerThread;
1657 s = dependencies.size() / nbOfDeamonsPerThread + 1;
1658 Register reg = Register.Instance();
1660 for (int j = 0; j < s; j++) {
1661 new UpdateRegisterConcernedThread(dependencies, reg, j, rank,
1662 oldNode, node).start();
1666 private Vector<Integer> getDependencies(int id, int jaceSize) {
1667 // get computing dependencies
1668 Vector<Integer> neighbors = new Vector<Integer>();
1669 int[] dep = tache.getDependencies(id);
1670 for (int z = 0; z < taille(dep); z++)
1671 neighbors.add(dep[z]);
1672 // System.out.println("la liste des voisins de calcul de: "+id+" concerne");
1673 // for(int z=0;z<neighbors.size();z++)
1674 // System.out.print(((Integer)neighbors.elementAt(z)).intValue()+" ");
1675 // System.out.println();
1677 // get convergence neighbors
1679 while (Math.pow(2, d) < jaceSize) {
1680 if (id < Math.pow(2, d) && ((id + Math.pow(2, d)) < jaceSize))
1681 if (!neighbors.contains((Object) ((int) (id + Math.pow(2, d)))))
1682 neighbors.add((int) (id + Math.pow(2, d)));
1683 if (id < Math.pow(2, d + 1) && id >= Math.pow(2, d))
1684 if (!neighbors.contains((Object) ((int) (id - Math.pow(2, d)))))
1685 neighbors.add((int) (id - Math.pow(2, d)));
1689 // get backup neighbors
1690 int nb = Register.Instance().getNumBackupNeighbors();
1693 for (int j = 1; j <= nb; j++) {
1694 // ------------ 1 - for backups "j + n" (to the right of j)
1695 rankOfBackTask = (id + j) % jaceSize;
1696 if (!neighbors.contains((Object) rankOfBackTask))
1697 neighbors.add(rankOfBackTask);
1699 // ------------ 2 - for backups "j - n" (to the left of j)
1702 rankOfBackTask = tmp % jaceSize;
1704 rankOfBackTask = jaceSize - (Math.abs(tmp) % jaceSize);
1706 if (!neighbors.contains((Object) rankOfBackTask))
1707 neighbors.add(rankOfBackTask);
1715 public static int taille(int[] vect) {
1718 while (x < vect.length && vect[x] >= 0) {
1725 class StartScanning extends Thread {
1727 public StartScanning() {
1737 class StartScanThread extends Thread {
1740 int nbOfDeamonsPerThread, nbOfDeamonsPerSpawner;
1742 StartScanThread(int i, Vector<?> nodes, int debut) {
1746 nbOfDeamonsPerThread = JaceSpawner.Instance().getNbOfDeamonsPerThread();
1747 nbOfDeamonsPerSpawner = JaceSpawner.Instance()
1748 .getNbOfDeamonsPerSpawner();
1753 for (index = debut + i * nbOfDeamonsPerThread; index < debut + i
1754 * nbOfDeamonsPerThread + nbOfDeamonsPerThread
1755 && index < debut + nbOfDeamonsPerSpawner
1756 && index < nodes.size(); index++) {
1758 Node node = (Node) nodes.elementAt(index);
1759 JaceInterface stub = node.getStub();
1760 String name = node.getName();
1763 stub.setScanning(true);
1764 // System.out.println("modify scanning to "+name);
1766 } catch (Exception e) {
1767 System.err.println("Unable to modify scanning to " + name + ":"
1771 // for(int x=0;x<nodes.size();x++)
1772 // System.out.println(((Node)nodes.elementAt(x)).getName());
1773 // System.out.println("nbre total: "+(index-1));