cholmod_gpu_test

July 4, 2018 ยท View on GitHub

#include <assert.h> #include <conio.h> #include #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);

}