How to use the control parameters to distribute the input matrix across processors in MUMPS 5.5.1?

30 Views Asked by At

So here's the code that I've written in C using MUMPS to solve a linear system.

#include<stdio.h>
#include<mpi.h>
#include<dmumps_c.h>
#define JOB_INIT -1
#define JOB_END -2
#define USE_COMM_WORLD -987654
#define N 100000

int main(int argc, char ** argv)
{
    DMUMPS_STRUC_C id;
    int n = N;
    int64_t nnz = N;
    int64_t nnz_loc = N/4;
    int irn[N], irn_loc[nnz_loc];
    int jcn[N], jcn_loc[nnz_loc];
    double a[N], a_loc[nnz_loc];
    double rhs[N];

    int i,j;

    for(i = 0; i<N; i++)
    {
        irn[i] = i+1;
        jcn[i] = i+1;
        a[i] = i+1;
    }

    int myid, ierr;
    ierr = MPI_Init(&argc, &argv);
    ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid);

    if(myid == 0)
    {
        for(i = 0; i<nnz_loc; i++)
        {
            irn_loc[i] = irn[i];
            jcn_loc[i] = jcn[i];
            a_loc[i] = a[i];
        }
    }

    else if(myid == 1)
    {
        for(i = 0; i<nnz_loc; i++)
        {
            irn_loc[i] = irn[(N/4)+i];
            jcn_loc[i] = jcn[(N/4)+i];
            a_loc[i] = a[(N/4)+i];
        }
    }

    else if(myid == 2)
    {
        for(i = 0; i<nnz_loc; i++)
        {
            irn_loc[i] = irn[(N/2)+i];
            jcn_loc[i] = jcn[(N/2)+i];
            a_loc[i] = a[(N/2)+i];
        }
    }

    else if(myid == 3)
    {
        for(i = 0; i<nnz_loc; i++)
        {
            irn_loc[i] = irn[(3*N/4)+i];
            jcn_loc[i] = jcn[(3*N/4)+i];
            a_loc[i] = a[(3*N/4)+i];
        }
    }

    for(i = 0; i<N; i++)
    {
        rhs[i] = a[i];
    }

    id.job = JOB_INIT;
    id.par = 1;
    id.sym = 1;
    id.comm_fortran = USE_COMM_WORLD;

    dmumps_c(&id);

    if(myid == 0)
    {
        id.n = N;
        id.nnz = nnz;
        id.irn = irn;
        id.jcn = jcn;
        id.a = a;
        id.rhs = rhs;
    }

    id.nnz_loc = nnz_loc;
    id.irn_loc = irn_loc;
    id.jcn_loc = jcn_loc;
    id.a_loc = a_loc;

    dmumps_c(&id);

    #define ICNTL(I) icntl[(I)-1]

    id.ICNTL(1) = -1;
    id.ICNTL(2) = -1;
    id.ICNTL(3) = -1;
    id.ICNTL(4) = 0;
    id.ICNTL(5) = 0;
    id.ICNTL(18) = 3;

    id.job = 1;
    dmumps_c(&id);

    id.job = 2;
    dmumps_c(&id);
    id.job = 3;
    dmumps_c(&id);

    id.job = JOB_END;

    if (myid == 0)
    {
        for(i=0 ; i<N; i++)
        {
        printf("%f ", rhs[i]);
        }
        printf("\n\n");
    }

    ierr = MPI_Finalize();

    return 0 ;
}

And I'm compiling it using

mpicc -o mumps_ex_diag mumps_ex_diag.c -ldmumps -lmumps_common -lpord -lmetis -lscotch -lscotcherr -lmpi

and running it as

mpirun -np 4 ./mumps_ex_diag

However this is just giving me the input RHS as the output. It's not solving anything. I'm fairly new to MUMPS and I've done all this just by reading the documentation. The parameter ICNTL(18) is used to distribute the given matrix to each processor but something seems to be going wrong somewhere and I'm not able to pinpoint it out.

0

There are 0 best solutions below