Example code for solving a sparse linear system Ax=d

General CULA Sparse support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

Example code for solving a sparse linear system Ax=d

Postby boyfarrell » Tue Mar 12, 2013 9:40 pm

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
boyfarrell
 
Posts: 3
Joined: Tue Mar 12, 2013 5:37 pm

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

Postby kyle » Wed Mar 13, 2013 5:44 am

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.
kyle
Administrator
 
Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm

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

Postby boyfarrell » Wed Mar 13, 2013 7:21 am

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.
boyfarrell
 
Posts: 3
Joined: Tue Mar 12, 2013 5:37 pm

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

Postby kyle » Wed Mar 13, 2013 7:32 am

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.
kyle
Administrator
 
Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm

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

Postby boyfarrell » Wed Mar 13, 2013 8:11 am

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,
boyfarrell
 
Posts: 3
Joined: Tue Mar 12, 2013 5:37 pm

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

Postby kyle » Wed Mar 13, 2013 8:20 am

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();
kyle
Administrator
 
Posts: 301
Joined: Fri Jun 12, 2009 7:47 pm


Return to CULA Sparse Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron