Single-Node Mode
Replaceability
Currently, KML_SOLVER supports multiple threads on a single node and cannot replace the multi-node function of PETSc.
Table 1 describes the mapping between replaceable interfaces and corresponding interfaces of PETSc (only optimized interfaces are provided).
PETSc Interface |
KML_SOLVER Interface |
|---|---|
KSPCreate |
KmlIssCgInitDI |
KSPSolve |
KmlIssCgSolveDI |
KSPDestroy |
KmlIssCgCleanDI |
The preceding interfaces are C interfaces. For details, see "Kunpeng Math Library Developer Guide" > "Applied Math Libraries" > "KML_SOLVER Library Functions" > "Function Syntax (Single-node Edition)" in Kunpeng HPCKit 26.1.RC1 Developer Guide.
Migrating the C-based Library
Both PETSc and KML_SOLVER provide C interfaces. However, the interface names and receiving parameters are inconsistent. Therefore, the corresponding function needs to be switched. The following is an example:
- InitializationBefore the migration:
1 2 3 4
KSP ksp; PetscErrorCode ierr; ierr = KSPCreate(PETSC_COMM_WORLD,&ksp); ierr = KSPSetOperators(ksp,A,A);
After the migration:1 2 3 4 5 6
int n = 8; int ia[9]; int ja[17]; double a[17]; void* handle; int error = KmlIssCgInitDI(&handle, &n, a, ja, ia);
- Finding the solutionBefore the migration:
1 2 3 4 5 6 7 8
Vec u,x,b; ierr = VecCreate(PETSC_COMM_WORLD,&u); ierr = VecSetSizes(u,PETSC_DECIDE,rdim); ierr = VecSetFromOptions(u);CHKERRQ(ierr); ierr = VecDuplicate(u,&b);CHKERRQ(ierr); ierr = VecDuplicate(b,&x);CHKERRQ(ierr); ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
After the migration:1 2 3 4 5 6
double b[8]; /* Solution vector */ double x[8]; int nrhs = 1; /* Number of right-hand sides */ int ldx=n, ldb=n; /* Leading dimension of B and X */ int error = KmlIssCgSolveDI(&handle, &nrhs, x, &ldx, b, &ldb);
- Obtaining iteration parameters
After the migration:
1 2 3
int *data; // user data. int nd = 1; int error = KmlIssCgGetDII(&handle, ITERATION_COUNT, data, nd);
- Clearing
After the migration:
1int error = KmlIssCgCleanDI(&handle);
- Header files
#include "petscksp.h"
After the migration:
#include "kml_iss.h"
- Compiling the links
Replace the PETSc-related link options. For details, see "Installing KML" in Kunpeng HPCKit 26.1.RC1 Installation Guide.