---
title: KmlScadssGENInit?I
description: "初始化数据结构，并将用户提供的系数矩阵关联到求解系统中，初始化集群版的LU方法时使用上三角的CSR格式。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1021.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1021.html
indexId: 6d5a111d4d9e2098949b94ab7b57c71f25e4b856b724978e2d011e78fa39d47d61
---
# KmlScadssGENInit?I

初始化数据结构，并将用户提供的系数矩阵关联到求解系统中，初始化集群版的LU方法时使用上三角的CSR格式。

#### 接口定义

C Interface：

int KmlScadssGenInitSI(KmlScasolverTask **pHandle, int n, float *a, int *ja, int *ia, MPI_Comm comm);

int KmlScadssGenInitDI(KmlScasolverTask **pHandle, int n, double *a, int *ja, int *ia, MPI_Comm comm);

int KmlScadssGenInitCI(KmlScasolverTask **pHandle, int n, kml_complex_float *a, int *ja, int *ia, MPI_Comm comm);

int KmlScadssGenInitZI(KmlScasolverTask **pHandle, int n, kml_complex_double *a, int *ja, int *ia, MPI_Comm comm);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| pHandle | KmlScasolverTask \*\* | 求解器句柄，传入之前步骤的变量。 | 输入/输出 |
| n | int | n为矩阵A的维度 | 输入 |
| a | 在KmlScadssGenInitSI中为float \*。 在KmlScadssGenInitDI中为double \*。 在KmlScadssGenInitCI中为kml\_complex\_float \*。 在KmlScadssGenInitZI中为kml\_complex\_double \*。 | a为维度为非零元素的个数的数组，a[i]为第i个非零元的值。该数组的生命周期与handle相同。 | 输入 |
| ja | int \* | ja为CSR格式的列索引数组，ja[i]为第i个非零元的列号。该数组的生命周期与handle相同。 | 输入 |
| ia | int \* | ia为CSR格式的行偏移数组，ia[i]为第i行第一个非零元在所有非零元中的索引，ia[0]=0。该数组的生命周期与handle相同。 | 输入 |
| comm | MPI\_Comm | 为MPI进程通信域。 | 输入 |


#### 返回值

| 返回值 | 类型 | 描述 |
| --- | --- | --- |
| KMLSS\_NO\_ERROR | int | 正常执行。 |
| KMLSS\_NULL\_ARGUMENT | int | 无效的参数。 |
| KMLSS\_BAD\_HANDLE | int | pHandle格式存在问题。 |


#### 依赖

#include "kml_scadss.h"


#### 示例

C Interface：

```
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 = KmlScadssGenInitDI(&matrix_handle, n, a, ja, ia, MPI_COMM_WORLD);
ierr = KmlScadssGenAnalyzeDI(&matrix_handle);
ierr = KmlScadssGenFactorizeDI(&matrix_handle);
int nrhs = 1;
int ldx=n, ldb=n;
ierr = KmlScadssGenSolveDI(&matrix_handle, nrhs, x, ldx, b, ldb);
ierr = KmlScadssGenCleanDI(&matrix_handle);
if (ierr != 0) {
printf("\nERROR in KmlScadssGenCleanDI: %d", ierr);
}
```
