scivision / mumps

MUMPS via CMake
http://mumps-solver.org
MIT License
115 stars 46 forks source link

I dont know how to compile mumps with c++ code #89

Closed xiaorong117 closed 4 months ago

xiaorong117 commented 4 months ago

// based on d_example.c from MUMPS 5.5.1

/* Example program using the C interface to the

include

include "mpi.h"

include "dmumps_c.h"

include "TEST.h"

define JOB_INIT -1

define JOB_END -2

define USE_COMM_WORLD -987654

int main(int argc, char ** argv) { DMUMPS_STRUC_C id; MUMPS_INT n = 2; MUMPS_INT8 nnz = 2; MUMPS_INT irn[] = {1,2}; MUMPS_INT jcn[] = {1,2}; double a[2]; double rhs[2];

/ When compiling with -DINTSIZE64, MUMPS_INT is 64-bit but MPI ilp64 versions may still require standard int for C interface. / / MUMPS_INT myid, ierr; / int myid, ierr; int error = 0;

ierr = MPI_Init(&argc, &argv); ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid); / Define A and rhs / rhs[0]=1.0;rhs[1]=4.0; a[0]=1.0;a[1]=2.0;

/ Initialize a MUMPS instance. Use MPI_COMM_WORLD / id.comm_fortran=USE_COMM_WORLD; id.par=1; id.sym=0; id.job=JOB_INIT; DMUMPS_C(&id);

/ Define the problem on the host / if (myid == 0) { id.n = n; id.nnz =nnz; id.irn=irn; id.jcn=jcn; id.a = a; id.rhs = rhs; }

define ICNTL(I) icntl[(I)-1] / macro s.t. indices match documentation /

/ No outputs / id.ICNTL(1)=-1; id.ICNTL(2)=-1; id.ICNTL(3)=-1; id.ICNTL(4)=0;

/ Call the MUMPS package (analyse, factorization and solve). / id.job=6; DMUMPS_C(&id);

if (id.infog[0]<0) { std::cerr << " (PROC " << myid << ") ERROR RETURN: \tINFOG(1)= " << id.infog[0] << "\n\t\t\t\tINFOG(2)= " << id.infog[1] << "\n"; error = 1; }

/ Terminate instance. / id.job=JOB_END; DMUMPS_C(&id); if (myid == 0) { if (!error) std::cout << "Solution is : (" << rhs[0] << " " << rhs[1] << ")\n"; else std::cerr << "An error has occured, please check error code returned by MUMPS.\n"; } ierr = MPI_Finalize(); return 0; }

scivision commented 4 months ago

closed as duplicate of #88