Exemplo n.º 1
0
 @Override
 public void work() {
   for (int cant = 0; cant < this.cantToAnalize; cant++) {
     int positionToAnalize = this.assignedVector.getPositionToAnalize();
     if (this.mask.get(positionToAnalize) >= 0)
       this.assignedVector.set(positionToAnalize, v2.get(positionToAnalize));
     this.barrier.subCant();
   }
   return;
 }
Exemplo n.º 2
0
 /** Returns the sum of all the elements in this vector. */
 public synchronized double sum() {
   Barrier b = new Barrier(this.dimension());
   int dim;
   ConcurVector vectorResultado = this;
   ConcurVector vectorAAnalizar = this;
   while (!(vectorResultado.dimension() == 1)) {
     if (vectorAAnalizar.dimension() % 2 == 0) {
       dim = vectorAAnalizar.dimension() / 2;
     } else {
       dim = vectorAAnalizar.dimension() / 2 + 1;
     }
     vectorResultado = new ConcurVector(dim, this.maxThreads, this.load);
     for (int i = 0; i < this.maxThreads; i++)
       new WorkerSum(vectorAAnalizar, this.cantDeElementosAAnalizar(i), b, i, vectorResultado)
           .start();
     vectorAAnalizar = vectorResultado;
   }
   return vectorResultado.get(0);
 }