Migration Procedure
Migrating the Library That Uses the C Language
Both PETSc and KML_SCASOLVER provide C interfaces. However, the interface names and receiving parameters are inconsistent. Therefore, the corresponding function needs to be switched. The following are examples:
- 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 nstripes = 1; int stripeWidth[1]; int stripeRow[1]; int ia[9]; int ja[17]; double a[17]; KmlScasolverTask* handle; int err; err = KmlScaissCgInitStripesDI(&handle, n, nstripes , stripeWidth, stripeRow, a, ja, ia, MPI_COMM_WORLD);
- Setting parameters for finding the solution
After the migration:
double eps = 1e-4; err = KmlScaissCgSetDID(&handle, KMLSS_THRESHOLD, &eps, 1); assert(err == 0); int max_iters = 2000; err = KmlScaissCgSetDII(&handle, KMLSS_MAX_ITERATION_COUNT, &max_iters, 1);
- 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:int nb=1; double* x[8]; double* b[8]; int ldx=4; int ldb=4; err = KmlScaissCgSolveDI(&handle, nb, x, ldx, b, ldb);
- Obtaining iteration parametersBefore the migration:
PetscInt its; PetscScalar norm; ierr = KSPGetIterationNumber(ksp,&its);CHKERRQ(ierr); ierr = KSPGetResidualNorm(ksp,&norm);CHKERRQ(ierr);
After the migration:int idata[] = {max_iters}; err = KmlScaissCgGetDII(&handle, KMLSS_ITERATION_COUNT, data, 1); double ddata[] = {eps}; err = KmlScaissCgGetDID(&handle, KMLSS_TOLERANCE, ddata, 1); - Clearing
After the migration:
err = KmlScaissCgCleanDI(&handle);
- Header file
#include "petscksp.h"
After the migration:
#include "kml_scaiss.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: Cluster Mode