如何创建双精度矩阵A和向量x和b的单精度副本?

时间:2012-11-25 16:40:30

标签: cuda cusp-library

我需要在cusp库中实现混合精度迭代细化(文件cg.inl):

如何进一步计算,如何创建单个精度(浮点)副本A_sp,向量x_sp和向量b_sp(除了现有的双精度版本A,x和b,假设value_type为double)?

代码部分......

template <class LinearOperator,
          class Vector>
void cg(LinearOperator& A,
        Vector& x,
        Vector& b)
...

template <class LinearOperator,
          class Vector,
          class Monitor,
          class Preconditioner>
void cg(LinearOperator& A,
        Vector& x,
        Vector& b,
        Monitor& monitor,
        Preconditioner& M)
{
    CUSP_PROFILE_SCOPED();

    typedef typename LinearOperator::value_type   ValueType;
    typedef typename LinearOperator::memory_space MemorySpace;

    assert(A.num_rows == A.num_cols);        // sanity check

    const size_t N = A.num_rows;

    // allocate workspace
    cusp::array1d<ValueType,MemorySpace> y(N);
    cusp::array1d<ValueType,MemorySpace> z(N);
    cusp::array1d<ValueType,MemorySpace> r(N);
    cusp::array1d<ValueType,MemorySpace> p(N);

    // y <- Ax
    cusp::multiply(A, x, y);

...

0 个答案:

没有答案