Migration Procedure
Migrating the Library That Uses the C Language
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:
KSP ksp; PetscErrorCode ierr; ierr = KSPCreate(PETSC_COMM_WORLD,&ksp); ierr = KSPSetOperators(ksp,A,A);
After the migration: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:
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: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:
int *data; // user data. int nd = 1; int error = KmlIssCgGetDII(&handle, ITERATION_COUNT, data, nd);
- Clearing
After the migration:
int error = KmlIssCgCleanDI(&handle);
- Header file
#include "petscksp.h"
After the migration:
#include "kml_iss.h"
- Compiling the links
Replace the link options related to PETSc. For details, see "Installing KML > Verifying the Installation" in Kunpeng Math Library Developer Guide.
Parent topic: Single-Node Mode