KmlScadss(SPD/HPD)Solve?I
求解LLTx=b或者LLHx=b。
接口定义
C Interface:
int KmlScadssSpdSolveSI(KmlScaSolverTask **pHandle, int nb, float *x, int ldx, float *b, int ldb);
int KmlScadssSpdSolveDI(KmlScaSolverTask **pHandle, int nb, double *x, int ldx, double *b, int ldb);
int KmlScadssHpdSolveCI(KmlScaSolverTask **pHandle, int nb, kml_complex_float *x, int ldx, kml_complex_float *b, int ldb);
int KmlScadssHpdSolveZI(KmlScaSolverTask **pHandle, int nb, kml_complex_double *x, int ldx, kml_complex_double *b, int ldb);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
pHandle |
KmlScasolverTask ** |
求解器句柄,传入之前步骤的变量。 |
输入 |
nb |
int |
右端项矢量的个数。 |
输入 |
x |
|
稠密向量存储求解结果,其元素个数为ldx*nb,第k个矢量的第i个元素位置为x[i + k * ldx]。 |
输出 |
ldx |
int |
x的leading dimension大小,要求ldx ≥ max(1, n)。 |
输入 |
b |
|
稠密向量存储右端项,其元素个数为ldb*nb,第k个矢量的第i个元素位置为b[i + k * ldb]。 |
输入 |
ldb |
int |
b的leading dimension大小,要求ldb ≥ max(1, n)。 |
输入 |
返回值
返回值 |
类型 |
描述 |
---|---|---|
KMLSS_NO_ERROR |
int |
正常执行。 |
KMLSS_NULL_ARGUMENT |
int |
pHandle,x,b为空。 |
KMLSS_BAD_NB |
int |
输入参数nb小于等于0。 |
KMLSS_BAD_HANDLE |
int |
pHandle格式存在问题。 |
KMLSS_BAD_LDX |
int |
ldx取值不在有效范围内。 |
KMLSS_BAD_LDB |
int |
ldb取值不在有效范围内。 |
KMLSS_INVALID_CALL_ORDER |
int |
函数执行顺序错误,上一阶段非Factorize。 |
依赖
#include "kml_scadss.h"
示例
MPI_Init(NULL, NULL); int size, rank; MPI_Comm_size(MPI_COMM_WORLD, &size);//获取总进程数 MPI_Comm_rank(MPI_COMM_WORLD, &rank);//获取当前进程标识 int n = 8; int ia[9] = {0, 3, 7, 9, 11, 13, 15, 16, 17}; int ja[17] = {0, 3, 4, 1, 2, 3, 5, 2, 7, 3, 6, 4, 5, 5, 7, 6, 7}; double a[17] = {1.0, 1.0, 2.0, 9.0, 2.0, 1.0, -3.0, 3.0, 2.0, 9.0, -5.0, 6.0, 1.0, 4.0, 1.0, 7.0, 2.0}; double b[8] = {4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0}; double x[8]; KmlScasolverTask* matrix_handle = NULL; int ierr = KmlScadssSpdInitDI(&matrix_handle, n, a, ja, ia, MPI_COMM_WORLD); ierr = KmlScadssSpdAnalyzeDI(&matrix_handle); ierr = KmlScadssSpdFactorizeDI(&matrix_handle); int nrhs = 1; int ldx=n, ldb=n; ierr = KmlScadssSpdSolveDI(&matrix_handle, nrhs, x, ldx, b, ldb); if (ierr != 0) { printf("\nERROR in KmlScadssSpdSolveDI: %d", ierr); } if (rank == 0) { for (int i = 0; i < n; i++) { printf("%lf ", x[i]); } printf("\n"); }
1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000