Пример #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;
 }
Пример #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);
 }
Пример #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);
 }
Пример #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());
 }
Пример #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();
 }