中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

迁移步骤

C语言迁移步骤

  1. 迁移前(调用PARDISO)。
    int n = 8;
    int nnz = 17;
    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};
    
    int nrhs = 1;     // Number of right hand sides.
    double b[8]={4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0};
    double x[8];
    
    int mtype = 2;
    void *pt[64];
    int iparm[64];
    int maxfct, mnum, phase, error, msglvl, perm;
    pardisoinit(pt, &mtype, iparm);
    iparm[34] = 1;
    maxfct = 1;       // Maximum number of numerical factorizations.
    mnum = 1;         // Which factorization to use.
    msglvl = 0;       // Print statistical information in file.
    error = 0;        // Initialize error flag.
    
    phase = 11;
    pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error); // Analyze
    printf ("Reordering completed ... ");
    
    phase = 22;
    pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error); // Factorize
    printf ("\nFactorization completed ... ");
    
    phase = 33;
    pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error); // Solve
    printf("\nSolve completed ... ");
    
    printf("\nThe solution of the system is: ");
    for(int i = 0; i < n; i++){
        printf ("\n x [%d] = % f", i, x[i]);
    }
    printf("\n");
    
    phase = -1;      // Release internal memory.
    pardiso(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &error);
    迁移前(调用PARDISO-Cluster)
    int n = 8;
    int nnz = 17;
    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};
    
    /* RHS and solution vectors. */
    int nrhs = 1;     /* Number of right hand sides. */
    double b[8]={4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0};
    double x[8];
    
    int mtype = 2;
    void *pt[64];
    int iparm[64];
    int maxfct, mnum, phase, error, msglvl, perm;
    for (int i = 0; i < 64; i++) {
        iparm[i] = 0;
        pt[i] = 0;
    }
    iparm[0] = 1;
    iparm[1] = 2;
    iparm[17] = -1;
    iparm[18] = -1;
    iparm[34] = 1;
    maxfct = 1;       // Maximum number of numerical factorizations.
    mnum = 1;         // Which factorization to use.
    msglvl = 0;       // Print statistical information in file.
    error = 0;        // Initialize error flag.
    
    MPI_Init(NULL, NULL);
    int size, rank;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Fint comm = MPI_Comm_c2f(MPI_COMM_WORLD);
    
    phase = 11;
    cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); // Analyze
    
    phase = 22;
    cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); // Factorize
    
    phase = 33;
    cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error); // Solve
    
    if (rank == 0){
        printf("The solution of the system is: ");
        for(int i = 0; i < n; i++){
            printf ("\n x [%d] = % f", i, x[i]);
        }
        printf("\n");
    }
    
    phase = -1;      // Release internal memory.
    cluster_sparse_solver(pt, &maxfct, &mnum, &mtype, &phase, &n, a, ia, ja, &perm, &nrhs, iparm, &msglvl, b, x, &comm, &error);
    
    MPI_Finalize();
    迁移后
    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};
    
    MPI_Init(NULL, NULL);
    int size, rank;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    
    KmlScasolverTask* matrix_handle = NULL;
    int ierr = KmlScadssSpdInitDI(&matrix_handle, n, a, ja, ia, MPI_COMM_WORLD); //Init
    if (ierr != 0) {
        printf("\nERROR in KmlScadssSpdInitDI: %d", ierr);
    }
    ierr = KmlScadssSpdAnalyzeDI(&matrix_handle); //Analyze phase
    if (ierr != 0) {
        printf("\nERROR in KmlScadssSpdAnalyzeDI: %d", ierr);
    }
    ierr = KmlScadssSpdFactorizeDI(&matrix_handle); //Factorize phase
    if (ierr != 0) {
        printf("\nERROR in KmlScadssSpdFactorizeDI: %d", ierr);
    }
    
    int nrhs = 1;
    int ldx=n, ldb=n;
    double b[8]={4.0, 9.0, 7.0, 6.0, 9.0, 3.0, 2.0, 5.0};
    double x[8];
    
    ierr = KmlScadssSpdSolveDI(&matrix_handle, nrhs, x, ldx, b, ldb); //Solve phase
    if (ierr != 0) {
        printf("\nERROR in KmlScadssSpdSolveDI: %d", ierr);
    }
    ierr = KmlScadssSpdCleanDI(&matrix_handle); //clean
    if (ierr != 0) {
        printf("\nERROR in KmlScadssSpdcleanDI: %d", ierr);
    }
    MPI_Finalize();
  2. 头文件

    迁移前(PARDISO)

    #include "mkl_types.h"

    #include "mkl_cluster_sparse_solver.h"

    迁移前(PARDISO-Cluster)

    #include "mkl_pardiso.h"

    #include "mkl_types.h"

    迁移后

    #include "kml_scadss.h

  3. 编译链接库。

    替换MKL相关的链接选项, 具体选项请参见《鲲鹏数学库 开发指南》中的“安装KML”章节。