Skip to content

Instantly share code, notes, and snippets.

@andr3wmac
Created July 4, 2018 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andr3wmac/78d294844484cb48342f88ef03e2776a to your computer and use it in GitHub Desktop.
Save andr3wmac/78d294844484cb48342f88ef03e2776a to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <conio.h>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include "cholmod.h"
// Test Matricies availble at: https://sparse.tamu.edu/
// nd6k: https://www.cise.ufl.edu/research/sparse/MM/ND/nd6k.tar.gz
#define USE_GPU 1
#if USE_GPU
#define CHOLMOD(x) cholmod_l_##x
#else
#define CHOLMOD(x) cholmod_##x
#endif
int main(void)
{
std::cout << "Loading matrix.." << std::endl;
const char* matFile = "Matrix/nd6k.mtx";
FILE* fp;
fopen_s(&fp, matFile, "r");
assert(fp != NULL);
cholmod_sparse *A;
cholmod_dense *x, *b;
cholmod_factor *L;
cholmod_common* c = (cholmod_common*)malloc(sizeof(cholmod_common));
CHOLMOD(start)(c); /* start CHOLMOD */
c->useGPU = 1;
c->supernodal = CHOLMOD_SUPERNODAL;
A = CHOLMOD(read_sparse)(fp, c); /* read in a matrix */
CHOLMOD(print_sparse)(A, "A", c); /* print the matrix */
fclose(fp);
if (A == NULL || A->stype == 0) /* A must be symmetric */
{
CHOLMOD(free_sparse)(&A, c);
CHOLMOD(finish)(c);
return (0);
}
b = CHOLMOD(ones)(A->nrow, 1, A->xtype, c); /* b = ones(n,1) */
clock_t pipelineStart = clock();
L = CHOLMOD(analyze)(A, c); /* analyze */
CHOLMOD(factorize)(A, L, c); /* factorize */
x = CHOLMOD(solve)(CHOLMOD_A, L, b, c); /* solve Ax=b */
double pipelineTime = (double)(clock() - pipelineStart) / CLOCKS_PER_SEC;
std::cout << "Cholesky Took: " << pipelineTime << "(s)." << std::endl;
CHOLMOD(gpu_stats)(c);
CHOLMOD(free_factor)(&L, c); /* free matrices */
CHOLMOD(free_sparse)(&A, c);
CHOLMOD(free_dense)(&x, c);
CHOLMOD(free_dense)(&b, c);
CHOLMOD(finish)(c); /* finish CHOLMOD */
std::cout << std::endl << "Hit enter to exit." << std::endl;
_getch();
return (0);
}
@YingmoWang
Copy link

Hello, Andrew Mac!
I cannot find a SuiteSparse Version support GPU in windows. The newest repo of SuiteSparse seems erase your commit in t_cholmod_gpu_c.
Could u help me for an availabel GPU-supporting SuiteSparse Version?
Best Wishes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment