/*
* JCusparse - Java bindings for CUSPARSE, the NVIDIA CUDA sparse
* matrix library, to be used with JCuda
*
* Copyright (c) 2010-2012 Marco Hutter - http://www.jcuda.org
*/
import static jcuda.jcusparse.JCusparse.*;
import static jcuda.jcusparse.cusparseIndexBase.CUSPARSE_INDEX_BASE_ZERO;
import static jcuda.jcusparse.cusparseMatrixType.CUSPARSE_MATRIX_TYPE_GENERAL;
import static jcuda.jcusparse.cusparseOperation.CUSPARSE_OPERATION_NON_TRANSPOSE;
import static jcuda.runtime.JCuda.*;
import static jcuda.runtime.cudaMemcpyKind.*;
import jcuda.*;
import jcuda.jcusparse.*;
import jcuda.runtime.JCuda;
/**
* A sample application showing how to use JCusparse.
*
* This sample has been ported from the NVIDIA CUSPARSE
* documentation example.
*/
public class JCusparseSample
{
public static void main(String args[])
{
// Enable exceptions and subsequently omit error checks in this sample
JCusparse.setExceptionsEnabled(true);
JCuda.setExceptionsEnabled(true);
// Variable declarations
cusparseHandle handle = new cusparseHandle();
cusparseMatDescr descra = new cusparseMatDescr();
int cooRowIndexHostPtr[];
int cooColIndexHostPtr[];
float cooValHostPtr[];
Pointer cooRowIndex = new Pointer();
Pointer cooColIndex = new Pointer();
Pointer cooVal = new Pointer();
int xIndHostPtr[];
float xValHostPtr[];
float yHostPtr[];
Pointer xInd = new Pointer();
Pointer xVal = new Pointer();
Pointer y = new Pointer();
Pointer csrRowPtr = new Pointer();
float zHostPtr[];
Pointer z = new Pointer();
int n, nnz, nnz_vector, i, j;
System.out.println("Testing example");
// Create the following sparse test matrix in COO format
// | 1.0 2.0 3.0 |
// | 4.0 |
// | 5.0 6.0 7.0 |
// | 8.0 9.0 |
n = 4;
nnz = 9;
cooRowIndexHostPtr = new int[nnz];
cooColIndexHostPtr = new int[nnz];
cooValHostPtr = new float[nnz];
cooRowIndexHostPtr[0]=0; cooColIndexHostPtr[0]=0; cooValHostPtr[0]=1.0f;
cooRowIndexHostPtr[1]=0; cooColIndexHostPtr[1]=2; cooValHostPtr[1]=2.0f;
cooRowIndexHostPtr[2]=0; cooColIndexHostPtr[2]=3; cooValHostPtr[2]=3.0f;
cooRowIndexHostPtr[3]=1; cooColIndexHostPtr[3]=1; cooValHostPtr[3]=4.0f;
cooRowIndexHostPtr[4]=2; cooColIndexHostPtr[4]=0; cooValHostPtr[4]=5.0f;
cooRowIndexHostPtr[5]=2; cooColIndexHostPtr[5]=2; cooValHostPtr[5]=6.0f;
cooRowIndexHostPtr[6]=2; cooColIndexHostPtr[6]=3; cooValHostPtr[6]=7.0f;
cooRowIndexHostPtr[7]=3; cooColIndexHostPtr[7]=1; cooValHostPtr[7]=8.0f;
cooRowIndexHostPtr[8]=3; cooColIndexHostPtr[8]=3; cooValHostPtr[8]=9.0f;
// Print the matrix
System.out.printf("Input data:\n");
for (i=0; i