3 import java.util.Vector;
5 class UpdateRegisterConcernedThread extends Thread {
11 int nbOfDeamonsPerThread;
14 public UpdateRegisterConcernedThread(Vector<?> neighbors, Register r, int i,
15 int rank, Node noeud, Node tmpNode) {
21 this.neighbors = neighbors;
24 nbOfDeamonsPerThread = JaceSpawner.Instance().getNbOfDeamonsPerThread();
28 ListeTask listOfTasks = Register.Instance().getListeOfTasks().clone();
29 // listOfTasks.viewAll();
30 for (int index = i * nbOfDeamonsPerThread; index < i
31 * nbOfDeamonsPerThread + nbOfDeamonsPerThread
32 && index < neighbors.size(); index++) {
35 if (((Integer) neighbors.elementAt(index)).intValue() == rank) {
36 Register g = new Register();
37 ListeTask newListOfTasks = new ListeTask();
38 g.setAppliName(reg.getAppliName());
39 g.setParams(reg.getParams());
41 g.setSpawnerStub(JaceSpawner.Instance()
42 .getSpawnerResponsibleOn(rank));
43 g.setNbOfTasks(reg.getNbOfTasks());
45 for (int j = 0; j < neighbors.size(); j++) {
46 TaskId id = listOfTasks
47 .getTaskIdOfRank(((Integer) neighbors
48 .elementAt(j)).intValue());
49 newListOfTasks.addTask(id);
50 if (id.getHostStub() != null) {
51 Node noeud = reg.getNodeOfStub(id.getHostStub());
57 g.setListeOfTasks(newListOfTasks);
59 TaskId neighborTask = listOfTasks
60 .getTaskIdOfRank((((Integer) neighbors
61 .elementAt(index)).intValue() + 1)
62 % listOfTasks.getSize());
63 JaceInterface stubVoisin = neighborTask.getHostStub();
64 JaceInterface stub = listOfTasks.getTaskIdOfRank(
65 ((Integer) neighbors.elementAt(index)).intValue())
67 if (stub == null || stubVoisin == null) {
68 System.out.println("stub NULL");
71 String name = listOfTasks.getTaskIdOfRank(
72 ((Integer) neighbors.elementAt(index))
73 .intValue()).getHostName();
76 // whatever the case, update the Register on each Node
78 // JaceSpawnerInterface
79 // ja=Register.Instance().getSpawnerStub();
80 // System.out.println("avant update register");
82 stub.updateRegister(g, stubVoisin, 0);
84 // System.out.println(" after update register");
85 // if updateRegister worked, that means Node is
87 Node noeud = Register.Instance()
90 noeud.setAliveFlag(true);
94 } catch (Exception e) {
98 + LocalHost.Instance()
102 + ") cannot be reached by UpdateRegisterConcernedThread for new node "
104 + Register.Instance().getSize()
111 TaskId id = listOfTasks
112 .getTaskIdOfRank(((Integer) neighbors
113 .elementAt(index)).intValue());
114 String name = id.getHostName();
118 JaceInterface stub = id.getHostStub();
119 stub.updateRegister(oldNode, node);
120 } catch (Exception e) {
124 + LocalHost.Instance().resolve(name)
127 + ") cannot be reached by UpdateRegisterConcernedThread "
129 + Register.Instance().getSize() + " :"
133 } catch (Exception e2) {
134 System.err.println("Error in updateRegisterConcernedThread :"
138 // System.out.println("at the end of an updateRegisterCon. j="+i);
139 // Register.Instance().getListeOfTasks().viewAll();
142 @SuppressWarnings("unused")
143 private Vector<Integer> getDependencies(int id, int jaceSize) {
144 // get computing dependencies
145 Vector<Integer> neighbors = new Vector<Integer>();
146 int[] dep = tache.getDependencies(id);
147 for (int z = 0; z < taille(dep); z++)
148 neighbors.add(dep[z]);
149 // System.out.println("la liste des voisins de calcul de: "+id);
150 // for(int z=0;z<neighbors.size();z++)
151 // System.out.print(((Integer)neighbors.elementAt(z)).intValue()+" ");
152 // System.out.println();
153 // get convergence neighbors
155 while (Math.pow(2, d) < jaceSize) {
156 if (id < Math.pow(2, d) && ((id + Math.pow(2, d)) < jaceSize))
157 if (!neighbors.contains((Object) ((int) (id + Math.pow(2, d)))))
158 neighbors.add((int) (id + Math.pow(2, d)));
159 if (id < Math.pow(2, d + 1) && id >= Math.pow(2, d))
160 if (!neighbors.contains((Object) ((int) (id - Math.pow(2, d)))))
161 neighbors.add((int) (id - Math.pow(2, d)));
165 // get backup neighbors
166 int nb = reg.getNumBackupNeighbors();
169 for (int j = 1; j <= nb; j++) {
170 // ------------ 1 - for backups "j + n" (to the right of j)
171 rankOfBackTask = (id + j) % jaceSize;
172 if (!neighbors.contains((Object) rankOfBackTask))
173 neighbors.add(rankOfBackTask);
175 // ------------ 2 - for backups "j - n" (to the left of j)
178 rankOfBackTask = tmp % jaceSize;
180 rankOfBackTask = jaceSize - (Math.abs(tmp) % jaceSize);
182 if (!neighbors.contains((Object) rankOfBackTask))
183 neighbors.add(rankOfBackTask);
191 public static int taille(int[] vect) {
194 while (x < vect.length && vect[x] >= 0) {