예제 #1
0
void LocalVector<ValueType>::MoveToHostAsync(void) {

    LOG_DEBUG(this, "LocalVector::MoveToHostAsync()",
              "");

    assert(this->asyncf == false);

    if (_paralution_available_accelerator() == false)
        LOG_VERBOSE_INFO(4,"*** info: LocalVector::MoveToAcceleratorAsync() no accelerator available - doing nothing");

    if ( (_paralution_available_accelerator() == true) &&
         (this->vector_ == this->vector_accel_)) {

        this->vector_host_ = new HostVector<ValueType>(this->local_backend_);

        // Copy to host
        this->vector_host_->CopyFromAsync(*this->vector_accel_);

        this->asyncf = true;

        LOG_VERBOSE_INFO(4, "*** info: LocalVector::MoveToHostAsync() accelerator to host transfer (started)");

    }

}
예제 #2
0
bool HostVector<ValueType>::Check(void) const {

  bool check = true;

  if (this->size_ > 0) {

    for (int i=0; i<this->size_; ++i)
      if ((paralution_abs(this->vec_[i]) ==
           std::numeric_limits<ValueType>::infinity()) || // inf
          (this->vec_[i] != this->vec_[i])) { // NaN
        LOG_VERBOSE_INFO(2,"*** error: Vector:Check - problems with vector data");
        return false;
      }

    if ((paralution_abs(this->size_) ==
         std::numeric_limits<int>::infinity()) || // inf
        ( this->size_ != this->size_)) { // NaN
      LOG_VERBOSE_INFO(2,"*** error: Vector:Check - problems with vector size");
      return false;
    }

  } else {

    assert(this->size_ == 0);
    assert(this->vec_ == NULL);

  }
  return check;

}
예제 #3
0
void LocalVector<ValueType>::MoveToHost(void) {

    LOG_DEBUG(this, "LocalVector::MoveToHost()",
              "");

    if (_paralution_available_accelerator() == false)
        LOG_VERBOSE_INFO(4,"*** info: LocalVector::MoveToHost() no accelerator available - doing nothing");

    if ( (_paralution_available_accelerator() == true) &&
         (this->vector_ == this->vector_accel_)) {

        this->vector_host_ = new HostVector<ValueType>(this->local_backend_);

        // Copy to host
        this->vector_host_->CopyFrom(*this->vector_accel_);

        this->vector_ = this->vector_host_;
        delete this->vector_accel_;
        this->vector_accel_ = NULL;

        LOG_VERBOSE_INFO(4, "*** info: LocalVector::MoveToHost() accelerator to host transfer");

    }

}
예제 #4
0
void LocalVector<ValueType>::Sync(void) {

    LOG_DEBUG(this, "LocalVector::Sync()",
              "");

    // check for active async transfer
    if (this->asyncf == true) {

        // The Move*Async function is active
        if ( (this->vector_accel_ != NULL) &&
             (this->vector_host_  != NULL)) {

            // MoveToHostAsync();
            if ( (_paralution_available_accelerator() == true) &&
                 (this->vector_ == this->vector_accel_)) {

                _paralution_sync();

                this->vector_ = this->vector_host_;
                delete this->vector_accel_;
                this->vector_accel_ = NULL;

                LOG_VERBOSE_INFO(4, "*** info: LocalVector::MoveToHostAsync() accelerator to host transfer (synced)");

            }

            // MoveToAcceleratorAsync();
            if ( (_paralution_available_accelerator() == true) &&
                 (this->vector_ == this->vector_host_)) {

                _paralution_sync();

                this->vector_ = this->vector_accel_;
                delete this->vector_host_;
                this->vector_host_ = NULL;
                LOG_VERBOSE_INFO(4, "*** info: LocalVector::MoveToAcceleratorAsync() host to accelerator transfer (synced)");

            }

        } else {

            // The Copy*Async function is active
            _paralution_sync();
            LOG_VERBOSE_INFO(4, "*** info: LocalVector::Copy*Async() transfer (synced)");

        }

    }

    this->asyncf = false;

}
예제 #5
0
void LocalVector<ValueType>::SetRandom(const ValueType a, const ValueType b, const int seed) {

    LOG_DEBUG(this, "LocalVector::SetRandom()",
              "");

    if (this->get_size() > 0) {

        // host only
        bool on_host = this->is_host();
        if (on_host == false)
            this->MoveToHost();

        assert(this->vector_ == this->vector_host_);
        this->vector_host_->SetRandom(a, b, seed);

        if (on_host == false) {

            LOG_VERBOSE_INFO(2, "*** warning: LocalVector::SetRandom() is performed on the host");

            this->MoveToAccelerator();

        }

    }

}
예제 #6
0
bool LocalVector<ValueType>::Check(void) const {

    LOG_DEBUG(this, "LocalVector::Check()",
              "");

    bool check = false;

    if (this->is_accel() == true) {

        LocalVector<ValueType> vec;
        vec.CopyFrom(*this);

        check = vec.Check();

        LOG_VERBOSE_INFO(2, "*** warning: LocalVector::Check() is performed on the host");

    } else {

        check = this->vector_->Check();

    }

    return check;

}
예제 #7
0
void MixedPrecisionDC<OperatorTypeH, VectorTypeH, ValueTypeH, 
                      OperatorTypeL, VectorTypeL, ValueTypeL>::MoveToAcceleratorLocalData_(void) {

  if (this->build_ == true) {

    LOG_VERBOSE_INFO(2, "MixedPrecisionDC: the inner solver is always performed on the accel; this function does nothing");

  }

}
예제 #8
0
void LocalVector<ValueType>::Prolongation(const LocalVector<ValueType> &vec_coarse, const LocalVector<int> &map) {

    LOG_DEBUG(this, "LocalVector::Prolongation()",
              "");

    assert(&vec_coarse != NULL);
    assert(&map != NULL);
    assert(&vec_coarse != this);
    assert( ( (this->vector_ == this->vector_host_)  && (vec_coarse.vector_ == vec_coarse.vector_host_)) ||
            ( (this->vector_ == this->vector_accel_) && (vec_coarse.vector_ == vec_coarse.vector_accel_) ) );
    assert( ( (this->vector_ == this->vector_host_)  && (map.vector_ == map.vector_host_)) ||
            ( (this->vector_ == this->vector_accel_) && (map.vector_ == map.vector_accel_) ) );

    if (this->get_size() > 0) {

        bool err = this->vector_->Prolongation(*vec_coarse.vector_, *map.vector_);

        if ((err == false) && (this->is_host() == true)) {
            LOG_INFO("Computation of LocalVector::Prolongation() fail");
            this->info();
            FATAL_ERROR(__FILE__, __LINE__);
        }

        if (err == false) {

            this->MoveToHost();

            LocalVector<int> map_tmp;
            map_tmp.CopyFrom(map);

            LocalVector<ValueType> vec_coarse_tmp;
            vec_coarse_tmp.CopyFrom(vec_coarse);

            if (this->vector_->Prolongation(*vec_coarse_tmp.vector_, *map_tmp.vector_) == false) {
                LOG_INFO("Computation of LocalVector::Prolongation() fail");
                this->info();
                FATAL_ERROR(__FILE__, __LINE__);
            }

            LOG_VERBOSE_INFO(2, "*** warning: LocalVector::Prolongation() is performed on the host");

            this->MoveToAccelerator();

        }

    }

}
예제 #9
0
void MixedPrecisionDC<OperatorTypeH, VectorTypeH, ValueTypeH, 
                      OperatorTypeL, VectorTypeL, ValueTypeL>::SolveNonPrecond_(const VectorTypeH &rhs,
                                                                                VectorTypeH *x) {

  assert(x != NULL);
  assert(x != &rhs);
  assert(this->op_  != NULL);
  assert(this->Solver_L_  != NULL);
  assert(this->build_ == true);


  this->x_h_ = x;

  // initial residual = b - Ax
  this->op_h_->Apply(*this->x_h_, &this->r_h_); 
  this->r_h_.ScaleAdd(ValueTypeH(-1.0), rhs);

  this->iter_ctrl_.InitResidual(this->Norm(this->r_h_));

  while (!this->iter_ctrl_.CheckResidual(this->Norm(this->r_h_))) {

  // cast to lower precision 

  // TODO 
  // use template
  this->r_l_.CopyFromDouble(this->r_h_);

  this->r_l_.MoveToAccelerator();

  this->d_l_.Clear();
  this->d_l_.MoveToAccelerator();

  LOG_VERBOSE_INFO(2, "MixedPrecisionDC: starting the internal solver [" << 8*sizeof(ValueTypeL) << "bit]");

  // set the initial solution to zero
  this->d_l_.Allocate("d_l",this->r_l_.get_size());
  this->d_l_.Zeros();
  // solver the inner problem (low)
  this->Solver_L_->Solve(this->r_l_,
                         &this->d_l_);


  this->r_l_.Clear();
  this->r_l_.MoveToHost();
  this->d_l_.MoveToHost();

  LOG_VERBOSE_INFO(2, "MixedPrecisionDC: defect correcting on the host [" << 8*sizeof(ValueTypeH) << "bit]");

  // TODO 
  // use template
  this->d_h_.CopyFromFloat(this->d_l_);

  this->x_h_->AddScale(this->d_h_, ValueTypeH(1.0));

  // initial residual = b - Ax
  this->op_h_->Apply(*this->x_h_, &this->r_h_); 
  this->r_h_.ScaleAdd(ValueTypeH(-1.0), rhs);

  }

}