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);
 }
Exemplo n.º 3
0
 /** Normalizes this vector, converting it into a unit vector. */
 public synchronized void normalize() {
   ConcurVector aux = new ConcurVector(dimension());
   aux.set(this.norm());
   div(aux);
 }
Exemplo n.º 4
0
 /** Returns the norm of this vector. */
 public synchronized double norm() {
   ConcurVector aux = new ConcurVector(dimension());
   aux.assign(this);
   aux.mul(this);
   return Math.sqrt(aux.sum());
 }
Exemplo n.º 5
0
 /**
  * Returns the dot product between two vectors (this and v).
  *
  * @param v, second operand of the dot product operation.
  * @precondition dimension() == v.dimension().
  */
 public synchronized double prod(ConcurVector v) {
   ConcurVector aux = new ConcurVector(dimension());
   aux.assign(this);
   aux.mul(v);
   return aux.sum();
 }