Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

How to add the row-major rule to dss_solve_real?

Tang_S_
Beginner
354 Views
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "mkl_dss.h"
#include "mkl_types.h"
/*
** Define the array and rhs vectors
 [9  1.5  6  0.75   3]   [ ]   [1  6]
 [  0.5              ]   [ ]   [2  7]
 [       12          ]   [ ] = [3  8]
 [          0.625    ]   [ ]   [4  9]
 [	           16]   [ ]   [5 10]

*/
#define NROWS       5
#define NCOLS       5
#define NNONZEROS   9
#define NRHS        2
static const MKL_INT nRows = NROWS;
static const MKL_INT nCols = NCOLS;
static const MKL_INT nNonZeros = NNONZEROS;
static const MKL_INT nRhs = NRHS;
//zero-base indexing
static _INTEGER_t rowIndex[NROWS + 1] = { 0, 5, 6, 7, 8, 9 };
static _INTEGER_t columns[NNONZEROS] = { 0, 1, 2, 3, 4, 1, 2, 3, 4 };

static _DOUBLE_PRECISION_t values[NNONZEROS] = { 9, 1.5, 6, .75, 3, 0.5, 12, .625, 16 };

static _DOUBLE_PRECISION_t rhs[NCOLS*NRHS] = { 1, 2, 3, 4, 5 ,6, 7, 8, 9, 10};


MKL_INT main() {
	MKL_INT i;
	/* Allocate storage for the solver handle and the right-hand side. */
	_DOUBLE_PRECISION_t solValues[NROWS];
	_MKL_DSS_HANDLE_t handle;
	_INTEGER_t error;

	MKL_INT opt = MKL_DSS_DEFAULTS;
	MKL_INT opt_handle = MKL_DSS_ZERO_BASED_INDEXING;
	MKL_INT sym = MKL_DSS_SYMMETRIC;
	MKL_INT type = MKL_DSS_POSITIVE_DEFINITE;
	/* --------------------- */
	/* Initialize the solver */
	/* --------------------- */
	error = dss_create(handle, opt_handle);
	if (error != MKL_DSS_SUCCESS)
		goto printError;
	/* ------------------------------------------- */
	/* Define the non-zero structure of the matrix */
	/* ------------------------------------------- */
	error = dss_define_structure(handle, sym, rowIndex, nRows, nCols, columns, nNonZeros);
	if (error != MKL_DSS_SUCCESS)
		goto printError;
	/* ------------------ */
	/* Reorder the matrix */
	/* ------------------ */
	error = dss_reorder(handle, opt, 0);
	if (error != MKL_DSS_SUCCESS)
		goto printError;
	/* ------------------ */
	/* Factor the matrix  */
	/* ------------------ */
	error = dss_factor_real(handle, type, values);
	if (error != MKL_DSS_SUCCESS)
		goto printError;
	/* ------------------------ */
	/* Get the solution vector  */
	/* ------------------------ */
	error = dss_solve_real(handle, opt, rhs, nRhs, solValues);
	if (error != MKL_DSS_SUCCESS)
		goto printError;
	/* -------------------------- */
	/* Deallocate solver storage  */
	/* -------------------------- */
	error = dss_delete(handle, opt);
	if (error != MKL_DSS_SUCCESS)
		goto printError;
	/* ---------------------- */
	/* Print solution vector  */
	/* ---------------------- */
	printf(" Solution array: ");
	for (i = 0; i < nCols * nRhs; i++)
		printf(" %g", solValues);
	printf("\n");
	system("Pause");
	exit(0);
printError:
	printf("Solver returned error code %d\n", error);
	system("Pause");
	exit(1);
}

By running the above code, I discovered that the solution  `solValues` and `rhs` are column-major.

 

0 Kudos
0 Replies
Reply