Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
Add "take_ownership" constructor parameter to cpu_csr_sparse_matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Kloeckner committed Aug 1, 2009
1 parent e79d43b commit 12ecb8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion example/solve.cpp
Expand Up @@ -60,8 +60,11 @@ int main(int argc, char **argv)
std::cerr << "usage: " << argv[0] << " matrix.mtx" << std::endl;
return 1;
}
// typedef double value_type;
#if 0
typedef float value_type;
#else
typedef double value_type;
#endif
typedef cpu_sparse_csr_matrix<value_type> cpu_mat_type;
typedef gpu_sparse_pkt_matrix<value_type> gpu_mat_type;
typedef gpu_vector<value_type> gvec_t;
Expand Down Expand Up @@ -105,6 +108,7 @@ int main(int argc, char **argv)
gvec_t x_perm_gpu(n);
x_perm_gpu.fill(0);

// perform solve
value_type tol;
if (sizeof(value_type) < sizeof(double))
tol = 1e-4;
Expand All @@ -120,6 +124,7 @@ int main(int argc, char **argv)
gvec_t x_gpu(n);
gpu_mat.unpermute(x_gpu, x_perm_gpu);

// compute residual on cpu
value_type *x = new value_type[n];
x_gpu.to_cpu(x);
double stop = get_time();
Expand Down
3 changes: 2 additions & 1 deletion include/iterative-cuda.hpp
Expand Up @@ -133,7 +133,8 @@ namespace iterative_cuda
index_type nonzero_count,
const index_type *csr_row_pointers,
const index_type *csr_column_indices,
const value_type *csr_nonzeros);
const value_type *csr_nonzeros,
bool take_ownership=true);
~cpu_sparse_csr_matrix();

index_type row_count() const;
Expand Down
8 changes: 6 additions & 2 deletions src/cpu-sparse-matrix.hpp
Expand Up @@ -43,6 +43,7 @@ namespace iterative_cuda
struct cpu_sparse_csr_matrix_pimpl
{
csr_matrix<IndexType, ValueType> matrix;
bool own_matrix;
};


Expand All @@ -55,7 +56,8 @@ namespace iterative_cuda
index_type nonzero_count,
const index_type *csr_row_pointers,
const index_type *csr_column_indices,
const value_type *csr_nonzeros)
const value_type *csr_nonzeros,
bool take_ownership)
: pimpl(new cpu_sparse_csr_matrix_pimpl<VT, IT>)
{
pimpl->matrix.num_rows = row_count;
Expand All @@ -64,6 +66,7 @@ namespace iterative_cuda
pimpl->matrix.Ap = const_cast<index_type *>(csr_row_pointers);
pimpl->matrix.Aj = const_cast<index_type *>(csr_column_indices);
pimpl->matrix.Ax = const_cast<value_type *>(csr_nonzeros);
pimpl->own_matrix = take_ownership;
}


Expand All @@ -72,7 +75,8 @@ namespace iterative_cuda
template <typename VT, typename IT>
cpu_sparse_csr_matrix<VT, IT>::~cpu_sparse_csr_matrix()
{
delete_csr_matrix(pimpl->matrix, HOST_MEMORY);
if (pimpl->own_matrix)
delete_csr_matrix(pimpl->matrix, HOST_MEMORY);
}


Expand Down

0 comments on commit 12ecb8c

Please sign in to comment.