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

迁移步骤

C语言迁移步骤

MUMPS提供C接口,KML_SOLVER同样也提供了C接口,但接口名及接收参数不一致,需要进行对应功能的切换,举例如下:

  1. 迁移前
    int n = 8;
    int nnz = 17;
    int irn[17] = {1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8};
    int jcn[17] = {1, 4, 5, 2, 3, 4, 6, 3, 8, 4, 7, 5, 6, 6, 8, 7, 8};
    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};
    
    MPI_Init(NULL, NULL);
    int size, rank;
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    
    DMUMPS_STRUC_C id;
    id.par = 1;
    id.sym = 1;
    id.job = -1;
    
    dmumps_c(&id);//Init
    
    if(rank == 0) {
            id.n = n;
            id.nnz = nnz;
            id.irn = irn;
            id.jcn = jcn;
            id.a = a;
            id.rhs = b;
    }
    #define ICNTL(I) icntl[(I)-1]
    id.ICNTL(1)=-1; id.ICNTL(2)=-1; id.ICNTL(3)=-1; id.ICNTL(4)=0;
    
    id.job = 6;
    dmumps_c(&id);//Analyze + Factorize + Solve
    if (id.infog[0]<0) {
        printf(" (PROC %d) ERROR RETURN: \tINFOG(1)= %d\n\t\t\t\tINFOG(2)= %d\n",
                    rank, id.infog[0], id.infog[1]);
    }
    
    if(rank == 0) {
       for (int i = 0; i < n; i++) {
           printf("%lf ", b[i]);
       }
       printf("\n");
    }
    
    id.job = -2;
    dmumps_c(&id); //clean
    
    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. 头文件。

    迁移前

    #include "dmumps_c.h"

    迁移后

    #include "kml_scadss.h"

  3. 编译链接库。

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

搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词