OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
c_example.c
Go to the documentation of this file.
1/*
2 *
3 * This file is part of MUMPS 5.5.1, released
4 * on Tue Jul 12 13:17:24 UTC 2022
5 *
6 */
7/* Example program using the C interface to the
8 * double real arithmetic version of MUMPS, dmumps_c.
9 * We solve the system A x = RHS with
10 * A = diag(1 2) and RHS = [1 4]^T
11 * Solution is [1 2]^T */
12#include <stdio.h>
13#include <string.h>
14#include "mpi.h"
15#include "dmumps_c.h"
16#define JOB_INIT -1
17#define JOB_END -2
18#define USE_COMM_WORLD -987654
19
20#if defined(MAIN_COMP)
21/*
22 * Some Fortran compilers (COMPAQ fort) define "main" in
23 * their runtime library while a Fortran program translates
24 * to MAIN_ or MAIN__ which is then called from "main".
25 * We defined argc/argv arbitrarily in that case.
26 */
27int MAIN__();
28int MAIN_()
29 {
30 return MAIN__();
31 }
32
33int MAIN__()
34{
35 int argc=1;
36 char * name = "c_example";
37 char ** argv ;
38#else
39int main(int argc, char ** argv)
40{
41#endif
43 MUMPS_INT n = 2;
44 MUMPS_INT8 nnz = 2;
45 MUMPS_INT irn[] = {1,2};
46 MUMPS_INT jcn[] = {1,2};
47 double a[2];
48 double rhs[2];
49
50/* When compiling with -DINTSIZE64, MUMPS_INT is 64-bit but MPI
51 ilp64 versions may still require standard int for C interface. */
52/* MUMPS_INT myid, ierr; */
53 int myid, ierr;
54
55 int error = 0;
56#if defined(MAIN_COMP)
57 argv = &name;
58#endif
59 ierr = MPI_Init(&argc, &argv);
60 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid);
61 /* Define A and rhs */
62 rhs[0]=1.0;rhs[1]=4.0;
63 a[0]=1.0;a[1]=2.0;
64
65 /* Initialize a MUMPS instance. Use MPI_COMM_WORLD */
66 id.comm_fortran=USE_COMM_WORLD;
67 id.par=1; id.sym=0;
68 id.job=JOB_INIT;
69 dmumps_c(&id);
70
71 /* Define the problem on the host */
72 if (myid == 0) {
73 id.n = n; id.nnz =nnz; id.irn=irn; id.jcn=jcn;
74 id.a = a; id.rhs = rhs;
75 }
76#define ICNTL(I) icntl[(I)-1] /* macro s.t. indices match documentation */
77 /* No outputs */
78 id.ICNTL(1)=-1; id.ICNTL(2)=-1; id.ICNTL(3)=-1; id.ICNTL(4)=0;
79
80 /* Call the MUMPS package (analyse, factorization and solve). */
81 id.job=6;
82 dmumps_c(&id);
83 if (id.infog[0]<0) {
84 printf(" (PROC %d) ERROR RETURN: \tINFOG(1)= %d\n\t\t\t\tINFOG(2)= %d\n",
85 myid, id.infog[0], id.infog[1]);
86 error = 1;
87 }
88
89 /* Terminate instance. */
90 id.job=JOB_END;
91 dmumps_c(&id);
92 if (myid == 0) {
93 if (!error) {
94 printf("Solution is : (%8.2f %8.2f)\n", rhs[0],rhs[1]);
95 } else {
96 printf("An error has occured, please check error code returned by MUMPS.\n");
97 }
98 }
99 ierr = MPI_Finalize();
100 return 0;
101}
#define JOB_END
Definition c_example.c:17
#define JOB_INIT
Definition c_example.c:16
#define USE_COMM_WORLD
Definition c_example.c:18
int main()
void MUMPS_CALL dmumps_c(DMUMPS_STRUC_C *dmumps_par)
LIBSEQ_INT LIBSEQ_CALL MPI_Comm_rank(LIBSEQ_INT comm, LIBSEQ_INT *rank)
Definition mpic.c:23
LIBSEQ_INT LIBSEQ_CALL MPI_Finalize(void)
Definition mpic.c:28
static MPI_Comm MPI_COMM_WORLD
Definition mpi.h:51
LIBSEQ_INT LIBSEQ_CALL MPI_Init(LIBSEQ_INT *pargc, char ***pargv)
Definition mpic.c:18
initmumps id
#define MUMPS_INT8
#define MUMPS_INT
n