Page 1 of 1

Example code for solving a sparse linear system Ax=d

PostPosted: Tue Mar 12, 2013 9:40 pm
by boyfarrell
Hello,

I am interesting in solving the linear system A.x = d using cudatools (the specific example is actually sparse and tri-diagonal matrix). Is there any tutorials or example code which I can follow which will show how to set-up the matices and perform the solution?

Best wishes,

Dan

Re: Example code for solving a sparse linear system Ax=d

PostPosted: Wed Mar 13, 2013 5:44 am
by kyle
Are you interested in solving dense matrices? If so look into CULA Dense. Otherwise, we'll need a little more information to provide some help.

Re: Example code for solving a sparse linear system Ax=d

PostPosted: Wed Mar 13, 2013 7:21 am
by boyfarrell
Hello Kyle,

Thanks for the reply. No I am explicitly interested in solving sparse systems, which are tridiagonal. For example take the Poisson equation,
Image.

The matrix and vector on the left are A and x, respectively. The vector on the right is d and all the terms are known. Therefore the system has the form A.x=d, I wish to solve this system of equations to find the (only) unknown, vector x. This is quite a standard linear system.

Best wishes,

Dan.

Re: Example code for solving a sparse linear system Ax=d

PostPosted: Wed Mar 13, 2013 7:32 am
by kyle
Ah, I misunderstood your question. We have an example in the SDK demonstrating how to solve a traditional system using CULA Sparse. The bulk of the example is in a single call to:

culaSparseCudaDcooCg(...)

Which uses the Cuda platform, takes double precision (D) coordinate matrix (Coo) as input, and uses the conjugate gradient solver (Cg) to solve the system. There are also parameters to further specify options such as tolerance and maximum number of iterations.

Re: Example code for solving a sparse linear system Ax=d

PostPosted: Wed Mar 13, 2013 8:11 am
by boyfarrell
Hello Kyle,

Fantastic! I will give it a go.

Is there any example code I could follow for solving sparse system? For example, I imagine there is plenty of boilerplate that will need to be setup etc.

Best wishes,

Re: Example code for solving a sparse linear system Ax=d

PostPosted: Wed Mar 13, 2013 8:20 am
by kyle
Here is an incomplete example showing a large portion of the boilerplate needed:

Code: Select all
    // cula-specific items
    culaStatus status;
    culaIterativeConfig config;
    culaIterativeResult result;
    culaCgOptions cgOptions;
    culaEmptyOptions emptyOptions;

    // enable sparse solvers and select a GPU device
    status = culaSparseInitialize();

    // check status
    // ...

    // set configuration options to defaults
    culaIterativeConfigInit(&config);
    culaCgOptionsInit(&cgOptions);
    culaEmptyOptionsInit(&emptyOptions);

    // change configuration options if needed
    // ...

    // run routine
    status = culaDcooCg(&config, &cgOptions, &emptyOptions, N, nnz, an, colInd, rowInd, x, b, &result);

    // check status
    // ...

    // clean up
    culaSparseShutdown();