@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();
 }