OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
c_example_save_restore.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_save_restore";
37 char ** argv ;
38#else
39int main(int argc, char ** argv)
40{
41#endif
42 DMUMPS_STRUC_C id_save,id_restore;
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 int error = 0;
51/* When compiling with -DINTSIZE64, MUMPS_INT is 64-bit but MPI
52 ilp64 versions may still require standard int for C interface. */
53/* MUMPS_INT myid, ierr; */
54 int myid, ierr;
55#if defined(MAIN_COMP)
56 argv = &name;
57#endif
58 ierr = MPI_Init(&argc, &argv);
59 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid);
60 /* Define A and rhs */
61 rhs[0]=1.0;rhs[1]=4.0;
62 a[0]=1.0;a[1]=2.0;
63
64 /* Initialize MUMPS save instance. Use MPI_COMM_WORLD */
66 id_save.par=1; id_save.sym=0;
67 id_save.job=JOB_INIT;
68 dmumps_c(&id_save);
69 /* Define the problem on the host */
70 if (myid == 0) {
71 id_save.n = n; id_save.nnz =nnz; id_save.irn=irn; id_save.jcn=jcn;
72 id_save.a = a;
73 }
74#define ICNTL(I) icntl[(I)-1] /* macro s.t. indices match documentation */
75 /* No outputs */
76 id_save.ICNTL(1)=-1; id_save.ICNTL(2)=-1;
77 id_save.ICNTL(3)=-1; id_save.ICNTL(4)=0;
78 /* Call the MUMPS package on the save instance (analyse and factorization). */
79 id_save.job=4;
80 dmumps_c(&id_save);
81
82 /* MUMPS save feature on the save instance. */
83 strcpy(id_save.save_prefix,"csave_restore");
84 strcpy(id_save.save_dir,"/tmp");
85 if (myid == 0) {
86 printf("Saving MUMPS instance in %s with prefix %s.\n",
87 id_save.save_dir, id_save.save_prefix);
88 }
89 id_save.job=7;
90 dmumps_c(&id_save);
91 if (id_save.infog[0]<0) {
92 printf("\n (PROC %d) ERROR RETURN: \tINFOG(1)= %d\n\t\t\t\tINFOG(2)= %d\n",
93 myid, id_save.infog[0], id_save.infog[1]);
94 error = 1;
95 } else if (myid == 0) {
96 printf(" DONE\n\n");
97 }
98
99 /* Terminate the save instance. */
100 id_save.job=JOB_END;
101 dmumps_c(&id_save);
102
103
104
105 if (!error) {
106 /* Initialize MUMPS restore instance. Use MPI_COMM_WORLD */
107 id_restore.comm_fortran=USE_COMM_WORLD;
108 id_restore.par=1; id_restore.sym=0;
109 id_restore.job=JOB_INIT;
110 dmumps_c(&id_restore);
111 /* Define the rhs on the host */
112 if (myid == 0) {
113 id_restore.rhs = rhs;
114 }
115
116 /* No outputs */
117 id_save.ICNTL(1)=-1; id_save.ICNTL(2)=-1;
118 id_save.ICNTL(3)=-1; id_save.ICNTL(4)=0;
119
120 /* MUMPS restore feature on restore instance. */
121 if (myid == 0) {
122 printf("Restoring MUMPS instance in %s with prefix %s.\n",
123 id_save.save_dir, id_save.save_prefix);
124 }
125 strcpy(id_restore.save_prefix,"csave_restore");
126 strcpy(id_restore.save_dir,"/tmp");
127 id_restore.job=8;
128 dmumps_c(&id_restore);
129 if (id_save.infog[0]<0) {
130 printf("\n (PROC %d) ERROR RETURN: \tINFOG(1)= %d\n\t\t\t\tINFOG(2)= %d\n",
131 myid, id_save.infog[0], id_save.infog[1]);
132 error = 1;
133 } else if (myid == 0) {
134 printf(" DONE\n\n");
135 }
136 }
137
138 if (!error) {
139 /* Call the MUMPS package on restore instance (solve). */
140 if (myid == 0) {
141 printf("Calling MUMPS package (solve).\n");
142 }
143 id_restore.job=3;
144 dmumps_c(&id_restore);
145 if (id_save.infog[0]<0) {
146 printf("=> (PROC %d) ERROR RETURN: \tINFOG(1)= %d\n\t\t\t\tINFOG(2)= %d\n",
147 myid, id_save.infog[0], id_save.infog[1]);
148 error = 1;
149 } else if (myid == 0) {
150 printf(" DONE\n\n");
151 }
152
153 /* Deletes the saved and the OOC files. */
154 if (myid == 0) {
155 printf("Removing save files.\n");
156 }
157 id_restore.job=-3;
158 dmumps_c(&id_restore);
159 if (id_save.infog[0]<0) {
160 printf("=> (PROC %d) ERROR RETURN: \tINFOG(1)= %d\n\t\t\t\tINFOG(2)= %d\n",
161 myid, id_save.infog[0], id_save.infog[1]);
162 error = 1;
163 } else if (myid == 0) {
164 printf(" DONE\n\n");
165 }
166
167 /* Terminate the restore instance. */
168 id_restore.job=JOB_END;
169 dmumps_c(&id_restore);
170 }
171
172 if (myid == 0) {
173 if (!error) {
174 printf("Solution is : (%8.2f %8.2f)\n", rhs[0],rhs[1]);
175 } else {
176 printf("An error has occured, please check error code returned by MUMPS.\n");
177 }
178 }
179 ierr = MPI_Finalize();
180 return 0;
181}
#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
#define MUMPS_INT8
#define MUMPS_INT
n
DMUMPS_COMPLEX * rhs
Definition dmumps_c.h:95
MUMPS_INT infog[80]
Definition dmumps_c.h:100
MUMPS_INT job
Definition dmumps_c.h:44
MUMPS_INT * irn
Definition dmumps_c.h:60
MUMPS_INT n
Definition dmumps_c.h:51
DMUMPS_COMPLEX * a
Definition dmumps_c.h:62
MUMPS_INT sym
Definition dmumps_c.h:44
char save_dir[256]
Definition dmumps_c.h:126
char save_prefix[256]
Definition dmumps_c.h:127
MUMPS_INT par
Definition dmumps_c.h:44
MUMPS_INT * jcn
Definition dmumps_c.h:61
MUMPS_INT8 nnz
Definition dmumps_c.h:59
MUMPS_INT comm_fortran
Definition dmumps_c.h:45