pinit.c (e366c154b69cf29c88be23f768f0f07dd2b3250c) pinit.c (5e71baeff2f3138f93cd4f5927dfd596eb8325cc)
1
2/*
3 This file defines the initialization of PETSc, including PetscInitialize()
4*/
1
2/*
3 This file defines the initialization of PETSc, including PetscInitialize()
4*/
5#define PETSC_DESIRE_COMPLEX
6#include <petsc-private/petscimpl.h> /*I "petscsys.h" I*/
5#include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/
6#include <petscvalgrind.h>
7#include <petscviewer.h>
8
7#include <petscviewer.h>
8
9#if defined(PETSC_HAVE_CUDA)
10#include <cublas.h>
11#endif
12
13#include <petscthreadcomm.h>
14
15#if defined(PETSC_USE_LOG)
9#if defined(PETSC_USE_LOG)
16extern PetscErrorCode PetscLogBegin_Private(void);
10extern PetscErrorCode PetscLogInitialize(void);
17#endif
11#endif
18extern PetscBool PetscHMPIWorker;
19
12
20
21#if defined(PETSC_SERIALIZE_FUNCTIONS)
22PetscFPT PetscFPTData = 0;
23#endif
24
13#if defined(PETSC_SERIALIZE_FUNCTIONS)
14PetscFPT PetscFPTData = 0;
15#endif
16
17#if defined(PETSC_HAVE_CUDA)
18cublasHandle_t cublasv2handle = NULL;
19#endif
20
21#if defined(PETSC_HAVE_SAWS)
22#include <petscviewersaws.h>
23#endif
25/* -----------------------------------------------------------------------------------------*/
26
27extern FILE *petsc_history;
28
29extern PetscErrorCode PetscInitialize_DynamicLibraries(void);
30extern PetscErrorCode PetscFinalize_DynamicLibraries(void);
31extern PetscErrorCode PetscFunctionListPrintAll(void);
32extern PetscErrorCode PetscSequentialPhaseBegin_Private(MPI_Comm,int);

--- 13 unchanged lines hidden (view full) ---

46const char *const PetscBools[] = {"FALSE","TRUE","PetscBool","PETSC_",0};
47const char *const PetscCopyModes[] = {"COPY_VALUES","OWN_POINTER","USE_POINTER","PetscCopyMode","PETSC_",0};
48const char *const PetscDataTypes[] = {"INT","DOUBLE","COMPLEX","LONG","SHORT","FLOAT",
49 "CHAR","LOGICAL","ENUM","BOOL","LONGDOUBLE","OBJECT","FUNCTION","PetscDataType","PETSC_",0};
50
51PetscBool PetscPreLoadingUsed = PETSC_FALSE;
52PetscBool PetscPreLoadingOn = PETSC_FALSE;
53
24/* -----------------------------------------------------------------------------------------*/
25
26extern FILE *petsc_history;
27
28extern PetscErrorCode PetscInitialize_DynamicLibraries(void);
29extern PetscErrorCode PetscFinalize_DynamicLibraries(void);
30extern PetscErrorCode PetscFunctionListPrintAll(void);
31extern PetscErrorCode PetscSequentialPhaseBegin_Private(MPI_Comm,int);

--- 13 unchanged lines hidden (view full) ---

45const char *const PetscBools[] = {"FALSE","TRUE","PetscBool","PETSC_",0};
46const char *const PetscCopyModes[] = {"COPY_VALUES","OWN_POINTER","USE_POINTER","PetscCopyMode","PETSC_",0};
47const char *const PetscDataTypes[] = {"INT","DOUBLE","COMPLEX","LONG","SHORT","FLOAT",
48 "CHAR","LOGICAL","ENUM","BOOL","LONGDOUBLE","OBJECT","FUNCTION","PetscDataType","PETSC_",0};
49
50PetscBool PetscPreLoadingUsed = PETSC_FALSE;
51PetscBool PetscPreLoadingOn = PETSC_FALSE;
52
53PetscInt PetscHotRegionDepth;
54
55#if defined(PETSC_HAVE_THREADSAFETY)
56PetscSpinlock PetscViewerASCIISpinLockOpen;
57PetscSpinlock PetscViewerASCIISpinLockStdout;
58PetscSpinlock PetscViewerASCIISpinLockStderr;
59PetscSpinlock PetscCommSpinLock;
60#endif
61
54/*
55 Checks the options database for initializations related to the
56 PETSc components
57*/
62/*
63 Checks the options database for initializations related to the
64 PETSc components
65*/
58#undef __FUNCT__
59#define __FUNCT__ "PetscOptionsCheckInitial_Components"
60PetscErrorCode PetscOptionsCheckInitial_Components(void)
61{
62 PetscBool flg1;
63 PetscErrorCode ierr;
64
65 PetscFunctionBegin;
66PetscErrorCode PetscOptionsCheckInitial_Components(void)
67{
68 PetscBool flg1;
69 PetscErrorCode ierr;
70
71 PetscFunctionBegin;
66 ierr = PetscOptionsHasName(NULL,"-help",&flg1);CHKERRQ(ierr);
72 ierr = PetscOptionsHasName(NULL,NULL,"-help",&flg1);CHKERRQ(ierr);
67 if (flg1) {
68#if defined(PETSC_USE_LOG)
69 MPI_Comm comm = PETSC_COMM_WORLD;
70 ierr = (*PetscHelpPrintf)(comm,"------Additional PETSc component options--------\n");CHKERRQ(ierr);
73 if (flg1) {
74#if defined(PETSC_USE_LOG)
75 MPI_Comm comm = PETSC_COMM_WORLD;
76 ierr = (*PetscHelpPrintf)(comm,"------Additional PETSc component options--------\n");CHKERRQ(ierr);
71 ierr = (*PetscHelpPrintf)(comm," -log_summary_exclude: <vec,mat,pc.ksp,snes>\n");CHKERRQ(ierr);
77 ierr = (*PetscHelpPrintf)(comm," -log_exclude: <vec,mat,pc.ksp,snes>\n");CHKERRQ(ierr);
72 ierr = (*PetscHelpPrintf)(comm," -info_exclude: <null,vec,mat,pc,ksp,snes,ts>\n");CHKERRQ(ierr);
73 ierr = (*PetscHelpPrintf)(comm,"-----------------------------------------------\n");CHKERRQ(ierr);
74#endif
75 }
76 PetscFunctionReturn(0);
77}
78
78 ierr = (*PetscHelpPrintf)(comm," -info_exclude: <null,vec,mat,pc,ksp,snes,ts>\n");CHKERRQ(ierr);
79 ierr = (*PetscHelpPrintf)(comm,"-----------------------------------------------\n");CHKERRQ(ierr);
80#endif
81 }
82 PetscFunctionReturn(0);
83}
84
79#undef __FUNCT__
80#define __FUNCT__ "PetscInitializeNoPointers"
81/*
82 PetscInitializeNoPointers - Calls PetscInitialize() from C/C++ without the pointers to argc and args
83
84 Collective
85
86 Level: advanced
87
88 Notes: this is called only by the PETSc MATLAB and Julia interface. Even though it might start MPI it sets the flag to

--- 12 unchanged lines hidden (view full) ---

101
102 PetscFunctionBegin;
103 ierr = PetscInitialize(&myargc,&myargs,filename,help);CHKERRQ(ierr);
104 ierr = PetscPopSignalHandler();CHKERRQ(ierr);
105 PetscBeganMPI = PETSC_FALSE;
106 PetscFunctionReturn(ierr);
107}
108
85/*
86 PetscInitializeNoPointers - Calls PetscInitialize() from C/C++ without the pointers to argc and args
87
88 Collective
89
90 Level: advanced
91
92 Notes: this is called only by the PETSc MATLAB and Julia interface. Even though it might start MPI it sets the flag to

--- 12 unchanged lines hidden (view full) ---

105
106 PetscFunctionBegin;
107 ierr = PetscInitialize(&myargc,&myargs,filename,help);CHKERRQ(ierr);
108 ierr = PetscPopSignalHandler();CHKERRQ(ierr);
109 PetscBeganMPI = PETSC_FALSE;
110 PetscFunctionReturn(ierr);
111}
112
109#undef __FUNCT__
110#define __FUNCT__ "PetscGetPETSC_COMM_SELF"
111/*
112 Used by MATLAB and Julia interface to get communicator
113*/
114PetscErrorCode PetscGetPETSC_COMM_SELF(MPI_Comm *comm)
115{
116 PetscFunctionBegin;
117 *comm = PETSC_COMM_SELF;
118 PetscFunctionReturn(0);
119}
120
113/*
114 Used by MATLAB and Julia interface to get communicator
115*/
116PetscErrorCode PetscGetPETSC_COMM_SELF(MPI_Comm *comm)
117{
118 PetscFunctionBegin;
119 *comm = PETSC_COMM_SELF;
120 PetscFunctionReturn(0);
121}
122
121#undef __FUNCT__
122#define __FUNCT__ "PetscInitializeNoArguments"
123/*@C
124 PetscInitializeNoArguments - Calls PetscInitialize() from C/C++ without
125 the command line arguments.
126
127 Collective
128
129 Level: advanced
130

--- 5 unchanged lines hidden (view full) ---

136 int argc = 0;
137 char **args = 0;
138
139 PetscFunctionBegin;
140 ierr = PetscInitialize(&argc,&args,NULL,NULL);
141 PetscFunctionReturn(ierr);
142}
143
123/*@C
124 PetscInitializeNoArguments - Calls PetscInitialize() from C/C++ without
125 the command line arguments.
126
127 Collective
128
129 Level: advanced
130

--- 5 unchanged lines hidden (view full) ---

136 int argc = 0;
137 char **args = 0;
138
139 PetscFunctionBegin;
140 ierr = PetscInitialize(&argc,&args,NULL,NULL);
141 PetscFunctionReturn(ierr);
142}
143
144#undef __FUNCT__
145#define __FUNCT__ "PetscInitialized"
146/*@
147 PetscInitialized - Determine whether PETSc is initialized.
148
149 Level: beginner
150
151.seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran()
152@*/
153PetscErrorCode PetscInitialized(PetscBool *isInitialized)
154{
155 *isInitialized = PetscInitializeCalled;
156 return 0;
157}
158
144/*@
145 PetscInitialized - Determine whether PETSc is initialized.
146
147 Level: beginner
148
149.seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran()
150@*/
151PetscErrorCode PetscInitialized(PetscBool *isInitialized)
152{
153 *isInitialized = PetscInitializeCalled;
154 return 0;
155}
156
159#undef __FUNCT__
160#define __FUNCT__ "PetscFinalized"
161/*@
162 PetscFinalized - Determine whether PetscFinalize() has been called yet
163
164 Level: developer
165
166.seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran()
167@*/
168PetscErrorCode PetscFinalized(PetscBool *isFinalized)
169{
170 *isFinalized = PetscFinalizeCalled;
171 return 0;
172}
173
174extern PetscErrorCode PetscOptionsCheckInitial_Private(void);
175
176/*
177 This function is the MPI reduction operation used to compute the sum of the
178 first half of the datatype and the max of the second half.
179*/
157/*@
158 PetscFinalized - Determine whether PetscFinalize() has been called yet
159
160 Level: developer
161
162.seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran()
163@*/
164PetscErrorCode PetscFinalized(PetscBool *isFinalized)
165{
166 *isFinalized = PetscFinalizeCalled;
167 return 0;
168}
169
170extern PetscErrorCode PetscOptionsCheckInitial_Private(void);
171
172/*
173 This function is the MPI reduction operation used to compute the sum of the
174 first half of the datatype and the max of the second half.
175*/
180MPI_Op PetscMaxSum_Op = 0;
176MPI_Op MPIU_MAXSUM_OP = 0;
181
177
182#undef __FUNCT__
183#define __FUNCT__ "PetscMaxSum_Local"
184PETSC_EXTERN void MPIAPI PetscMaxSum_Local(void *in,void *out,int *cnt,MPI_Datatype *datatype)
178PETSC_INTERN void MPIAPI MPIU_MaxSum_Local(void *in,void *out,int *cnt,MPI_Datatype *datatype)
185{
186 PetscInt *xin = (PetscInt*)in,*xout = (PetscInt*)out,i,count = *cnt;
187
188 PetscFunctionBegin;
189 if (*datatype != MPIU_2INT) {
190 (*PetscErrorPrintf)("Can only handle MPIU_2INT data types");
191 MPI_Abort(MPI_COMM_WORLD,1);
192 }

--- 4 unchanged lines hidden (view full) ---

197 }
198 PetscFunctionReturnVoid();
199}
200
201/*
202 Returns the max of the first entry owned by this processor and the
203sum of the second entry.
204
179{
180 PetscInt *xin = (PetscInt*)in,*xout = (PetscInt*)out,i,count = *cnt;
181
182 PetscFunctionBegin;
183 if (*datatype != MPIU_2INT) {
184 (*PetscErrorPrintf)("Can only handle MPIU_2INT data types");
185 MPI_Abort(MPI_COMM_WORLD,1);
186 }

--- 4 unchanged lines hidden (view full) ---

191 }
192 PetscFunctionReturnVoid();
193}
194
195/*
196 Returns the max of the first entry owned by this processor and the
197sum of the second entry.
198
205 The reason nprocs[2*i] contains lengths nprocs[2*i+1] contains flag of 1 if length is nonzero
206is so that the PetscMaxSum_Op() can set TWO values, if we passed in only nprocs[i] with lengths
199 The reason sizes[2*i] contains lengths sizes[2*i+1] contains flag of 1 if length is nonzero
200is so that the MPIU_MAXSUM_OP() can set TWO values, if we passed in only sizes[i] with lengths
207there would be no place to store the both needed results.
208*/
201there would be no place to store the both needed results.
202*/
209#undef __FUNCT__
210#define __FUNCT__ "PetscMaxSum"
211PetscErrorCode PetscMaxSum(MPI_Comm comm,const PetscInt nprocs[],PetscInt *max,PetscInt *sum)
203PetscErrorCode PetscMaxSum(MPI_Comm comm,const PetscInt sizes[],PetscInt *max,PetscInt *sum)
212{
204{
213 PetscMPIInt size,rank;
214 struct {PetscInt max,sum;} *work;
215 PetscErrorCode ierr;
216
217 PetscFunctionBegin;
205 PetscErrorCode ierr;
206
207 PetscFunctionBegin;
218 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
219 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
220 ierr = PetscMalloc(size*sizeof(*work),&work);CHKERRQ(ierr);
221 ierr = MPI_Allreduce((void*)nprocs,work,size,MPIU_2INT,PetscMaxSum_Op,comm);CHKERRQ(ierr);
222 *max = work[rank].max;
223 *sum = work[rank].sum;
224 ierr = PetscFree(work);CHKERRQ(ierr);
208#if defined(PETSC_HAVE_MPI_REDUCE_SCATTER_BLOCK)
209 {
210 struct {PetscInt max,sum;} work;
211 ierr = MPI_Reduce_scatter_block((void*)sizes,&work,1,MPIU_2INT,MPIU_MAXSUM_OP,comm);CHKERRQ(ierr);
212 *max = work.max;
213 *sum = work.sum;
214 }
215#else
216 {
217 PetscMPIInt size,rank;
218 struct {PetscInt max,sum;} *work;
219 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
220 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
221 ierr = PetscMalloc1(size,&work);CHKERRQ(ierr);
222 ierr = MPIU_Allreduce((void*)sizes,work,size,MPIU_2INT,MPIU_MAXSUM_OP,comm);CHKERRQ(ierr);
223 *max = work[rank].max;
224 *sum = work[rank].sum;
225 ierr = PetscFree(work);CHKERRQ(ierr);
226 }
227#endif
225 PetscFunctionReturn(0);
226}
227
228/* ----------------------------------------------------------------------------*/
228 PetscFunctionReturn(0);
229}
230
231/* ----------------------------------------------------------------------------*/
229MPI_Op PetscADMax_Op = 0;
230
232
231#undef __FUNCT__
232#define __FUNCT__ "PetscADMax_Local"
233PETSC_EXTERN void MPIAPI PetscADMax_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
234{
235 PetscScalar *xin = (PetscScalar*)in,*xout = (PetscScalar*)out;
236 PetscInt i,count = *cnt;
237
238 PetscFunctionBegin;
239 if (*datatype != MPIU_2SCALAR) {
240 (*PetscErrorPrintf)("Can only handle MPIU_2SCALAR data (i.e. double or complex) types");
241 MPI_Abort(MPI_COMM_WORLD,1);
242 }
243
244 for (i=0; i<count; i++) {
245 if (PetscRealPart(xout[2*i]) < PetscRealPart(xin[2*i])) {
246 xout[2*i] = xin[2*i];
247 xout[2*i+1] = xin[2*i+1];
248 }
249 }
250 PetscFunctionReturnVoid();
251}
252
253MPI_Op PetscADMin_Op = 0;
254
255#undef __FUNCT__
256#define __FUNCT__ "PetscADMin_Local"
257PETSC_EXTERN void MPIAPI PetscADMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
258{
259 PetscScalar *xin = (PetscScalar*)in,*xout = (PetscScalar*)out;
260 PetscInt i,count = *cnt;
261
262 PetscFunctionBegin;
263 if (*datatype != MPIU_2SCALAR) {
264 (*PetscErrorPrintf)("Can only handle MPIU_2SCALAR data (i.e. double or complex) types");
265 MPI_Abort(MPI_COMM_WORLD,1);
266 }
267
268 for (i=0; i<count; i++) {
269 if (PetscRealPart(xout[2*i]) > PetscRealPart(xin[2*i])) {
270 xout[2*i] = xin[2*i];
271 xout[2*i+1] = xin[2*i+1];
272 }
273 }
274 PetscFunctionReturnVoid();
275}
276/* ---------------------------------------------------------------------------------------*/
277
278#if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128)
233#if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
279MPI_Op MPIU_SUM = 0;
280
234MPI_Op MPIU_SUM = 0;
235
281#undef __FUNCT__
282#define __FUNCT__ "PetscSum_Local"
283PETSC_EXTERN void PetscSum_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
284{
285 PetscInt i,count = *cnt;
286
287 PetscFunctionBegin;
288 if (*datatype == MPIU_REAL) {
289 PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
290 for (i=0; i<count; i++) xout[i] += xin[i];

--- 7 unchanged lines hidden (view full) ---

298 else {
299 (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types");
300 MPI_Abort(MPI_COMM_WORLD,1);
301 }
302 PetscFunctionReturnVoid();
303}
304#endif
305
236PETSC_EXTERN void PetscSum_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
237{
238 PetscInt i,count = *cnt;
239
240 PetscFunctionBegin;
241 if (*datatype == MPIU_REAL) {
242 PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
243 for (i=0; i<count; i++) xout[i] += xin[i];

--- 7 unchanged lines hidden (view full) ---

251 else {
252 (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types");
253 MPI_Abort(MPI_COMM_WORLD,1);
254 }
255 PetscFunctionReturnVoid();
256}
257#endif
258
306#if defined(PETSC_USE_REAL___FLOAT128)
259#if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
307MPI_Op MPIU_MAX = 0;
308MPI_Op MPIU_MIN = 0;
309
260MPI_Op MPIU_MAX = 0;
261MPI_Op MPIU_MIN = 0;
262
310#undef __FUNCT__
311#define __FUNCT__ "PetscMax_Local"
312PETSC_EXTERN void PetscMax_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
313{
314 PetscInt i,count = *cnt;
315
316 PetscFunctionBegin;
317 if (*datatype == MPIU_REAL) {
318 PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
319 for (i=0; i<count; i++) xout[i] = PetscMax(xout[i],xin[i]);

--- 8 unchanged lines hidden (view full) ---

328#endif
329 else {
330 (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types");
331 MPI_Abort(MPI_COMM_WORLD,1);
332 }
333 PetscFunctionReturnVoid();
334}
335
263PETSC_EXTERN void PetscMax_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
264{
265 PetscInt i,count = *cnt;
266
267 PetscFunctionBegin;
268 if (*datatype == MPIU_REAL) {
269 PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
270 for (i=0; i<count; i++) xout[i] = PetscMax(xout[i],xin[i]);

--- 8 unchanged lines hidden (view full) ---

279#endif
280 else {
281 (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types");
282 MPI_Abort(MPI_COMM_WORLD,1);
283 }
284 PetscFunctionReturnVoid();
285}
286
336#undef __FUNCT__
337#define __FUNCT__ "PetscMin_Local"
338PETSC_EXTERN void PetscMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
339{
340 PetscInt i,count = *cnt;
341
342 PetscFunctionBegin;
343 if (*datatype == MPIU_REAL) {
344 PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
345 for (i=0; i<count; i++) xout[i] = PetscMin(xout[i],xin[i]);

--- 9 unchanged lines hidden (view full) ---

355 else {
356 (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_SCALAR data (i.e. double or complex) types");
357 MPI_Abort(MPI_COMM_WORLD,1);
358 }
359 PetscFunctionReturnVoid();
360}
361#endif
362
287PETSC_EXTERN void PetscMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype)
288{
289 PetscInt i,count = *cnt;
290
291 PetscFunctionBegin;
292 if (*datatype == MPIU_REAL) {
293 PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out;
294 for (i=0; i<count; i++) xout[i] = PetscMin(xout[i],xin[i]);

--- 9 unchanged lines hidden (view full) ---

304 else {
305 (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_SCALAR data (i.e. double or complex) types");
306 MPI_Abort(MPI_COMM_WORLD,1);
307 }
308 PetscFunctionReturnVoid();
309}
310#endif
311
363#undef __FUNCT__
364#define __FUNCT__ "Petsc_DelCounter"
365/*
366 Private routine to delete internal tag/name counter storage when a communicator is freed.
367
368 This is called by MPI, not by users. This is called by MPI_Comm_free() when the communicator that has this data as an attribute is freed.
369
370 Note: this is declared extern "C" because it is passed to MPI_Keyval_create()
371
372*/
373PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelCounter(MPI_Comm comm,PetscMPIInt keyval,void *count_val,void *extra_state)
374{
375 PetscErrorCode ierr;
376
377 PetscFunctionBegin;
378 ierr = PetscInfo1(0,"Deleting counter data in an MPI_Comm %ld\n",(long)comm);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
379 ierr = PetscFree(count_val);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
380 PetscFunctionReturn(MPI_SUCCESS);
381}
382
312/*
313 Private routine to delete internal tag/name counter storage when a communicator is freed.
314
315 This is called by MPI, not by users. This is called by MPI_Comm_free() when the communicator that has this data as an attribute is freed.
316
317 Note: this is declared extern "C" because it is passed to MPI_Keyval_create()
318
319*/
320PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelCounter(MPI_Comm comm,PetscMPIInt keyval,void *count_val,void *extra_state)
321{
322 PetscErrorCode ierr;
323
324 PetscFunctionBegin;
325 ierr = PetscInfo1(0,"Deleting counter data in an MPI_Comm %ld\n",(long)comm);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
326 ierr = PetscFree(count_val);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
327 PetscFunctionReturn(MPI_SUCCESS);
328}
329
383#undef __FUNCT__
384#define __FUNCT__ "Petsc_DelComm_Outer"
385/*
386 This is invoked on the outer comm as a result of either PetscCommDestroy() (via MPI_Attr_delete) or when the user
387 calls MPI_Comm_free().
388
389 This is the only entry point for breaking the links between inner and outer comms.
390
391 This is called by MPI, not by users. This is called when MPI_Comm_free() is called on the communicator.
392

--- 13 unchanged lines hidden (view full) ---

406 ierr = MPI_Attr_get(icomm.comm,Petsc_OuterComm_keyval,&ocomm,&flg);CHKERRQ(ierr);
407 if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm does not have expected reference to outer comm");
408 if (ocomm.comm != comm) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm has reference to non-matching outer comm");
409 ierr = MPI_Attr_delete(icomm.comm,Petsc_OuterComm_keyval);CHKERRQ(ierr); /* Calls Petsc_DelComm_Inner */
410 ierr = PetscInfo1(0,"User MPI_Comm %ld is being freed after removing reference from inner PETSc comm to this outer comm\n",(long)comm);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
411 PetscFunctionReturn(MPI_SUCCESS);
412}
413
330/*
331 This is invoked on the outer comm as a result of either PetscCommDestroy() (via MPI_Attr_delete) or when the user
332 calls MPI_Comm_free().
333
334 This is the only entry point for breaking the links between inner and outer comms.
335
336 This is called by MPI, not by users. This is called when MPI_Comm_free() is called on the communicator.
337

--- 13 unchanged lines hidden (view full) ---

351 ierr = MPI_Attr_get(icomm.comm,Petsc_OuterComm_keyval,&ocomm,&flg);CHKERRQ(ierr);
352 if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm does not have expected reference to outer comm");
353 if (ocomm.comm != comm) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm has reference to non-matching outer comm");
354 ierr = MPI_Attr_delete(icomm.comm,Petsc_OuterComm_keyval);CHKERRQ(ierr); /* Calls Petsc_DelComm_Inner */
355 ierr = PetscInfo1(0,"User MPI_Comm %ld is being freed after removing reference from inner PETSc comm to this outer comm\n",(long)comm);if (ierr) PetscFunctionReturn((PetscMPIInt)ierr);
356 PetscFunctionReturn(MPI_SUCCESS);
357}
358
414#undef __FUNCT__
415#define __FUNCT__ "Petsc_DelComm_Inner"
416/*
417 * This is invoked on the inner comm when Petsc_DelComm_Outer calls MPI_Attr_delete. It should not be reached any other way.
418 */
419PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Inner(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state)
420{
421 PetscErrorCode ierr;
422
423 PetscFunctionBegin;

--- 6 unchanged lines hidden (view full) ---

430PETSC_EXTERN PetscMPIInt PetscDataRep_extent_fn(MPI_Datatype,MPI_Aint*,void*);
431PETSC_EXTERN PetscMPIInt PetscDataRep_read_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*);
432PETSC_EXTERN PetscMPIInt PetscDataRep_write_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*);
433#endif
434#endif
435
436int PetscGlobalArgc = 0;
437char **PetscGlobalArgs = 0;
359/*
360 * This is invoked on the inner comm when Petsc_DelComm_Outer calls MPI_Attr_delete. It should not be reached any other way.
361 */
362PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Inner(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state)
363{
364 PetscErrorCode ierr;
365
366 PetscFunctionBegin;

--- 6 unchanged lines hidden (view full) ---

373PETSC_EXTERN PetscMPIInt PetscDataRep_extent_fn(MPI_Datatype,MPI_Aint*,void*);
374PETSC_EXTERN PetscMPIInt PetscDataRep_read_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*);
375PETSC_EXTERN PetscMPIInt PetscDataRep_write_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*);
376#endif
377#endif
378
379int PetscGlobalArgc = 0;
380char **PetscGlobalArgs = 0;
381PetscSegBuffer PetscCitationsList;
438
382
439#undef __FUNCT__
440#define __FUNCT__ "PetscGetArgs"
383PetscErrorCode PetscCitationsInitialize(void)
384{
385 PetscErrorCode ierr;
386
387 PetscFunctionBegin;
388 ierr = PetscSegBufferCreate(1,10000,&PetscCitationsList);CHKERRQ(ierr);
389 ierr = PetscCitationsRegister("@TechReport{petsc-user-ref,\n Author = {Satish Balay and Shrirang Abhyankar and Mark F. Adams and Jed Brown and Peter Brune\n and Kris Buschelman and Lisandro Dalcin and Victor Eijkhout and William D. Gropp\n and Dinesh Kaushik and Matthew G. Knepley\n and Lois Curfman McInnes and Karl Rupp and Barry F. Smith\n and Stefano Zampini and Hong Zhang and Hong Zhang},\n Title = {{PETS}c Users Manual},\n Number = {ANL-95/11 - Revision 3.8},\n Institution = {Argonne National Laboratory},\n Year = {2017}\n}\n",NULL);CHKERRQ(ierr);
390 ierr = PetscCitationsRegister("@InProceedings{petsc-efficient,\n Author = {Satish Balay and William D. Gropp and Lois Curfman McInnes and Barry F. Smith},\n Title = {Efficient Management of Parallelism in Object Oriented Numerical Software Libraries},\n Booktitle = {Modern Software Tools in Scientific Computing},\n Editor = {E. Arge and A. M. Bruaset and H. P. Langtangen},\n Pages = {163--202},\n Publisher = {Birkh{\\\"{a}}user Press},\n Year = {1997}\n}\n",NULL);CHKERRQ(ierr);
391 PetscFunctionReturn(0);
392}
393
441/*@C
442 PetscGetArgs - Allows you to access the raw command line arguments anywhere
443 after PetscInitialize() is called but before PetscFinalize().
444
445 Not Collective
446
447 Output Parameters:
448+ argc - count of number of command line arguments

--- 16 unchanged lines hidden (view full) ---

465{
466 PetscFunctionBegin;
467 if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
468 *argc = PetscGlobalArgc;
469 *args = PetscGlobalArgs;
470 PetscFunctionReturn(0);
471}
472
394/*@C
395 PetscGetArgs - Allows you to access the raw command line arguments anywhere
396 after PetscInitialize() is called but before PetscFinalize().
397
398 Not Collective
399
400 Output Parameters:
401+ argc - count of number of command line arguments

--- 16 unchanged lines hidden (view full) ---

418{
419 PetscFunctionBegin;
420 if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
421 *argc = PetscGlobalArgc;
422 *args = PetscGlobalArgs;
423 PetscFunctionReturn(0);
424}
425
473#undef __FUNCT__
474#define __FUNCT__ "PetscGetArguments"
475/*@C
476 PetscGetArguments - Allows you to access the command line arguments anywhere
477 after PetscInitialize() is called but before PetscFinalize().
478
479 Not Collective
480
481 Output Parameters:
482. args - the command line arguments

--- 11 unchanged lines hidden (view full) ---

494PetscErrorCode PetscGetArguments(char ***args)
495{
496 PetscInt i,argc = PetscGlobalArgc;
497 PetscErrorCode ierr;
498
499 PetscFunctionBegin;
500 if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
501 if (!argc) {*args = 0; PetscFunctionReturn(0);}
426/*@C
427 PetscGetArguments - Allows you to access the command line arguments anywhere
428 after PetscInitialize() is called but before PetscFinalize().
429
430 Not Collective
431
432 Output Parameters:
433. args - the command line arguments

--- 11 unchanged lines hidden (view full) ---

445PetscErrorCode PetscGetArguments(char ***args)
446{
447 PetscInt i,argc = PetscGlobalArgc;
448 PetscErrorCode ierr;
449
450 PetscFunctionBegin;
451 if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()");
452 if (!argc) {*args = 0; PetscFunctionReturn(0);}
502 ierr = PetscMalloc(argc*sizeof(char*),args);CHKERRQ(ierr);
453 ierr = PetscMalloc1(argc,args);CHKERRQ(ierr);
503 for (i=0; i<argc-1; i++) {
504 ierr = PetscStrallocpy(PetscGlobalArgs[i+1],&(*args)[i]);CHKERRQ(ierr);
505 }
506 (*args)[argc-1] = 0;
507 PetscFunctionReturn(0);
508}
509
454 for (i=0; i<argc-1; i++) {
455 ierr = PetscStrallocpy(PetscGlobalArgs[i+1],&(*args)[i]);CHKERRQ(ierr);
456 }
457 (*args)[argc-1] = 0;
458 PetscFunctionReturn(0);
459}
460
510#undef __FUNCT__
511#define __FUNCT__ "PetscFreeArguments"
512/*@C
513 PetscFreeArguments - Frees the memory obtained with PetscGetArguments()
514
515 Not Collective
516
517 Output Parameters:
518. args - the command line arguments
519

--- 14 unchanged lines hidden (view full) ---

534 while (args[i]) {
535 ierr = PetscFree(args[i]);CHKERRQ(ierr);
536 i++;
537 }
538 ierr = PetscFree(args);CHKERRQ(ierr);
539 PetscFunctionReturn(0);
540}
541
461/*@C
462 PetscFreeArguments - Frees the memory obtained with PetscGetArguments()
463
464 Not Collective
465
466 Output Parameters:
467. args - the command line arguments
468

--- 14 unchanged lines hidden (view full) ---

483 while (args[i]) {
484 ierr = PetscFree(args[i]);CHKERRQ(ierr);
485 i++;
486 }
487 ierr = PetscFree(args);CHKERRQ(ierr);
488 PetscFunctionReturn(0);
489}
490
542#undef __FUNCT__
543#define __FUNCT__ "PetscInitialize"
491#if defined(PETSC_HAVE_SAWS)
492#include <petscconfiginfo.h>
493
494PetscErrorCode PetscInitializeSAWs(const char help[])
495{
496 if (!PetscGlobalRank) {
497 char cert[PETSC_MAX_PATH_LEN],root[PETSC_MAX_PATH_LEN],*intro,programname[64],*appline,*options,version[64];
498 int port;
499 PetscBool flg,rootlocal = PETSC_FALSE,flg2,selectport = PETSC_FALSE;
500 size_t applinelen,introlen;
501 PetscErrorCode ierr;
502 char sawsurl[256];
503
504 ierr = PetscOptionsHasName(NULL,NULL,"-saws_log",&flg);CHKERRQ(ierr);
505 if (flg) {
506 char sawslog[PETSC_MAX_PATH_LEN];
507
508 ierr = PetscOptionsGetString(NULL,NULL,"-saws_log",sawslog,PETSC_MAX_PATH_LEN,NULL);CHKERRQ(ierr);
509 if (sawslog[0]) {
510 PetscStackCallSAWs(SAWs_Set_Use_Logfile,(sawslog));
511 } else {
512 PetscStackCallSAWs(SAWs_Set_Use_Logfile,(NULL));
513 }
514 }
515 ierr = PetscOptionsGetString(NULL,NULL,"-saws_https",cert,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
516 if (flg) {
517 PetscStackCallSAWs(SAWs_Set_Use_HTTPS,(cert));
518 }
519 ierr = PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select",&selectport,NULL);CHKERRQ(ierr);
520 if (selectport) {
521 PetscStackCallSAWs(SAWs_Get_Available_Port,(&port));
522 PetscStackCallSAWs(SAWs_Set_Port,(port));
523 } else {
524 ierr = PetscOptionsGetInt(NULL,NULL,"-saws_port",&port,&flg);CHKERRQ(ierr);
525 if (flg) {
526 PetscStackCallSAWs(SAWs_Set_Port,(port));
527 }
528 }
529 ierr = PetscOptionsGetString(NULL,NULL,"-saws_root",root,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
530 if (flg) {
531 PetscStackCallSAWs(SAWs_Set_Document_Root,(root));CHKERRQ(ierr);
532 ierr = PetscStrcmp(root,".",&rootlocal);CHKERRQ(ierr);
533 } else {
534 ierr = PetscOptionsHasName(NULL,NULL,"-saws_options",&flg);CHKERRQ(ierr);
535 if (flg) {
536 ierr = PetscStrreplace(PETSC_COMM_WORLD,"${PETSC_DIR}/share/petsc/saws",root,PETSC_MAX_PATH_LEN);CHKERRQ(ierr);
537 PetscStackCallSAWs(SAWs_Set_Document_Root,(root));CHKERRQ(ierr);
538 }
539 }
540 ierr = PetscOptionsHasName(NULL,NULL,"-saws_local",&flg2);CHKERRQ(ierr);
541 if (flg2) {
542 char jsdir[PETSC_MAX_PATH_LEN];
543 if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"-saws_local option requires -saws_root option");
544 ierr = PetscSNPrintf(jsdir,PETSC_MAX_PATH_LEN,"%s/js",root);CHKERRQ(ierr);
545 ierr = PetscTestDirectory(jsdir,'r',&flg);CHKERRQ(ierr);
546 if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_READ,"-saws_local option requires js directory in root directory");
547 PetscStackCallSAWs(SAWs_Push_Local_Header,());CHKERRQ(ierr);
548 }
549 ierr = PetscGetProgramName(programname,64);CHKERRQ(ierr);
550 ierr = PetscStrlen(help,&applinelen);CHKERRQ(ierr);
551 introlen = 4096 + applinelen;
552 applinelen += 1024;
553 ierr = PetscMalloc(applinelen,&appline);CHKERRQ(ierr);
554 ierr = PetscMalloc(introlen,&intro);CHKERRQ(ierr);
555
556 if (rootlocal) {
557 ierr = PetscSNPrintf(appline,applinelen,"%s.c.html",programname);CHKERRQ(ierr);
558 ierr = PetscTestFile(appline,'r',&rootlocal);CHKERRQ(ierr);
559 }
560 ierr = PetscOptionsGetAll(NULL,&options);CHKERRQ(ierr);
561 if (rootlocal && help) {
562 ierr = PetscSNPrintf(appline,applinelen,"<center> Running <a href=\"%s.c.html\">%s</a> %s</center><br><center><pre>%s</pre></center><br>\n",programname,programname,options,help);
563 } else if (help) {
564 ierr = PetscSNPrintf(appline,applinelen,"<center>Running %s %s</center><br><center><pre>%s</pre></center><br>",programname,options,help);
565 } else {
566 ierr = PetscSNPrintf(appline,applinelen,"<center> Running %s %s</center><br>\n",programname,options);
567 }
568 ierr = PetscFree(options);CHKERRQ(ierr);
569 ierr = PetscGetVersion(version,sizeof(version));CHKERRQ(ierr);
570 ierr = PetscSNPrintf(intro,introlen,"<body>\n"
571 "<center><h2> <a href=\"http://www.mcs.anl.gov/petsc\">PETSc</a> Application Web server powered by <a href=\"https://bitbucket.org/saws/saws\">SAWs</a> </h2></center>\n"
572 "<center>This is the default PETSc application dashboard, from it you can access any published PETSc objects or logging data</center><br><center>%s configured with %s</center><br>\n"
573 "%s",version,petscconfigureoptions,appline);
574 PetscStackCallSAWs(SAWs_Push_Body,("index.html",0,intro));
575 ierr = PetscFree(intro);CHKERRQ(ierr);
576 ierr = PetscFree(appline);CHKERRQ(ierr);
577 if (selectport) {
578 PetscBool silent;
579
580 ierr = SAWs_Initialize();
581 /* another process may have grabbed the port so keep trying */
582 while (ierr) {
583 PetscStackCallSAWs(SAWs_Get_Available_Port,(&port));
584 PetscStackCallSAWs(SAWs_Set_Port,(port));
585 ierr = SAWs_Initialize();
586 }
587
588 ierr = PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select_silent",&silent,NULL);CHKERRQ(ierr);
589 if (!silent) {
590 PetscStackCallSAWs(SAWs_Get_FullURL,(sizeof(sawsurl),sawsurl));
591 ierr = PetscPrintf(PETSC_COMM_WORLD,"Point your browser to %s for SAWs\n",sawsurl);CHKERRQ(ierr);
592 }
593 } else {
594 PetscStackCallSAWs(SAWs_Initialize,());
595 }
596 ierr = PetscCitationsRegister("@TechReport{ saws,\n"
597 " Author = {Matt Otten and Jed Brown and Barry Smith},\n"
598 " Title = {Scientific Application Web Server (SAWs) Users Manual},\n"
599 " Institution = {Argonne National Laboratory},\n"
600 " Year = 2013\n}\n",NULL);CHKERRQ(ierr);
601 }
602 PetscFunctionReturn(0);
603}
604#endif
605
544/*@C
545 PetscInitialize - Initializes the PETSc database and MPI.
546 PetscInitialize() calls MPI_Init() if that has yet to be called,
547 so this routine should always be called near the beginning of
548 your program -- usually the very first line!
549
550 Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
551

--- 6 unchanged lines hidden (view full) ---

558
559 If you wish PETSc code to run ONLY on a subcommunicator of MPI_COMM_WORLD, create that
560 communicator first and assign it to PETSC_COMM_WORLD BEFORE calling PetscInitialize(). Thus if you are running a
561 four process job and two processes will run PETSc and have PetscInitialize() and PetscFinalize() and two process will not,
562 then do this. If ALL processes in the job are using PetscInitialize() and PetscFinalize() then you don't need to do this, even
563 if different subcommunicators of the job are doing different things with PETSc.
564
565 Options Database Keys:
606/*@C
607 PetscInitialize - Initializes the PETSc database and MPI.
608 PetscInitialize() calls MPI_Init() if that has yet to be called,
609 so this routine should always be called near the beginning of
610 your program -- usually the very first line!
611
612 Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set
613

--- 6 unchanged lines hidden (view full) ---

620
621 If you wish PETSc code to run ONLY on a subcommunicator of MPI_COMM_WORLD, create that
622 communicator first and assign it to PETSC_COMM_WORLD BEFORE calling PetscInitialize(). Thus if you are running a
623 four process job and two processes will run PETSc and have PetscInitialize() and PetscFinalize() and two process will not,
624 then do this. If ALL processes in the job are using PetscInitialize() and PetscFinalize() then you don't need to do this, even
625 if different subcommunicators of the job are doing different things with PETSc.
626
627 Options Database Keys:
566+ -start_in_debugger [noxterm,dbx,xdb,gdb,...] - Starts program in debugger
628+ -help [intro] - prints help method for each option; if intro is given the program stops after printing the introductory help message
629. -start_in_debugger [noxterm,dbx,xdb,gdb,...] - Starts program in debugger
567. -on_error_attach_debugger [noxterm,dbx,xdb,gdb,...] - Starts debugger when error detected
568. -on_error_emacs <machinename> causes emacsclient to jump to error file
569. -on_error_abort calls abort() when error detected (no traceback)
570. -on_error_mpiabort calls MPI_abort() when error detected
571. -error_output_stderr prints error messages to stderr instead of the default stdout
572. -error_output_none does not print the error messages (but handles errors in the same way as if this was not called)
573. -debugger_nodes [node1,node2,...] - Indicates nodes to start in debugger
574. -debugger_pause [sleeptime] (in seconds) - Pauses debugger
575. -stop_for_debugger - Print message on how to attach debugger manually to
576 process and wait (-debugger_pause) seconds for attachment
577. -malloc - Indicates use of PETSc error-checking malloc (on by default for debug version of libraries)
578. -malloc no - Indicates not to use error-checking malloc
579. -malloc_debug - check for memory corruption at EVERY malloc or free
630. -on_error_attach_debugger [noxterm,dbx,xdb,gdb,...] - Starts debugger when error detected
631. -on_error_emacs <machinename> causes emacsclient to jump to error file
632. -on_error_abort calls abort() when error detected (no traceback)
633. -on_error_mpiabort calls MPI_abort() when error detected
634. -error_output_stderr prints error messages to stderr instead of the default stdout
635. -error_output_none does not print the error messages (but handles errors in the same way as if this was not called)
636. -debugger_nodes [node1,node2,...] - Indicates nodes to start in debugger
637. -debugger_pause [sleeptime] (in seconds) - Pauses debugger
638. -stop_for_debugger - Print message on how to attach debugger manually to
639 process and wait (-debugger_pause) seconds for attachment
640. -malloc - Indicates use of PETSc error-checking malloc (on by default for debug version of libraries)
641. -malloc no - Indicates not to use error-checking malloc
642. -malloc_debug - check for memory corruption at EVERY malloc or free
643. -malloc_dump - prints a list of all unfreed memory at the end of the run
580. -malloc_test - like -malloc_dump -malloc_debug, but only active for debugging builds
581. -fp_trap - Stops on floating point exceptions (Note that on the
582 IBM RS6000 this slows code by at least a factor of 10.)
583. -no_signal_handler - Indicates not to trap error signals
584. -shared_tmp - indicates /tmp directory is shared by all processors
585. -not_shared_tmp - each processor has own /tmp
586. -tmp - alternative name of /tmp directory
587. -get_total_flops - returns total flops done by all processors
644. -malloc_test - like -malloc_dump -malloc_debug, but only active for debugging builds
645. -fp_trap - Stops on floating point exceptions (Note that on the
646 IBM RS6000 this slows code by at least a factor of 10.)
647. -no_signal_handler - Indicates not to trap error signals
648. -shared_tmp - indicates /tmp directory is shared by all processors
649. -not_shared_tmp - each processor has own /tmp
650. -tmp - alternative name of /tmp directory
651. -get_total_flops - returns total flops done by all processors
588. -memory_info - Print memory usage at end of run
589- -server <port> - start PETSc webserver (default port is 8080)
652- -memory_view - Print memory usage at end of run
590
591 Options Database Keys for Profiling:
653
654 Options Database Keys for Profiling:
592 See the <a href="../../docs/manual.pdf#nameddest=ch_profiling">profiling chapter of the users manual</a> for details.
655 See Users-Manual: ch_profiling for details.
593+ -info <optional filename> - Prints verbose information to the screen
594. -info_exclude <null,vec,mat,pc,ksp,snes,ts> - Excludes some of the verbose messages
595. -log_sync - Log the synchronization in scatters, inner products and norms
596. -log_trace [filename] - Print traces of all PETSc calls to the screen (useful to determine where a program
597 hangs without running in the debugger). See PetscLogTraceBegin().
656+ -info <optional filename> - Prints verbose information to the screen
657. -info_exclude <null,vec,mat,pc,ksp,snes,ts> - Excludes some of the verbose messages
658. -log_sync - Log the synchronization in scatters, inner products and norms
659. -log_trace [filename] - Print traces of all PETSc calls to the screen (useful to determine where a program
660 hangs without running in the debugger). See PetscLogTraceBegin().
598. -log_summary [filename] - Prints summary of flop and timing information to screen. If the filename is specified the
661. -log_view [:filename:format] - Prints summary of flop and timing information to screen or file, see PetscLogView().
662. -log_summary [filename] - (Deprecated, use -log_view) Prints summary of flop and timing information to screen. If the filename is specified the
599 summary is written to the file. See PetscLogView().
663 summary is written to the file. See PetscLogView().
600. -log_summary_python [filename] - Prints data on of flop and timing usage to a file or screen. See PetscLogPrintSViewPython().
664. -log_exclude: <vec,mat,pc.ksp,snes> - excludes subset of object classes from logging
601. -log_all [filename] - Logs extensive profiling information See PetscLogDump().
602. -log [filename] - Logs basic profiline information See PetscLogDump().
603- -log_mpe [filename] - Creates a logfile viewable by the utility Jumpshot (in MPICH distribution)
604
665. -log_all [filename] - Logs extensive profiling information See PetscLogDump().
666. -log [filename] - Logs basic profiline information See PetscLogDump().
667- -log_mpe [filename] - Creates a logfile viewable by the utility Jumpshot (in MPICH distribution)
668
605 Only one of -log_trace, -log_summary, -log_all, -log, or -log_mpe may be used at a time
669 Only one of -log_trace, -log_view, -log_view, -log_all, -log, or -log_mpe may be used at a time
606
670
671 Options Database Keys for SAWs:
672+ -saws_port <portnumber> - port number to publish SAWs data, default is 8080
673. -saws_port_auto_select - have SAWs select a new unique port number where it publishes the data, the URL is printed to the screen
674 this is useful when you are running many jobs that utilize SAWs at the same time
675. -saws_log <filename> - save a log of all SAWs communication
676. -saws_https <certificate file> - have SAWs use HTTPS instead of HTTP
677- -saws_root <directory> - allow SAWs to have access to the given directory to search for requested resources and files
678
607 Environmental Variables:
608+ PETSC_TMP - alternative tmp directory
609. PETSC_SHARED_TMP - tmp is shared by all processes
610. PETSC_NOT_SHARED_TMP - each process has its own private tmp
611. PETSC_VIEWER_SOCKET_PORT - socket number to use for socket viewer
612- PETSC_VIEWER_SOCKET_MACHINE - machine to use for socket viewer to connect to
613
614
615 Level: beginner
616
617 Notes:
618 If for some reason you must call MPI_Init() separately, call
619 it before PetscInitialize().
620
621 Fortran Version:
622 In Fortran this routine has the format
623$ call PetscInitialize(file,ierr)
624
625+ ierr - error return code
679 Environmental Variables:
680+ PETSC_TMP - alternative tmp directory
681. PETSC_SHARED_TMP - tmp is shared by all processes
682. PETSC_NOT_SHARED_TMP - each process has its own private tmp
683. PETSC_VIEWER_SOCKET_PORT - socket number to use for socket viewer
684- PETSC_VIEWER_SOCKET_MACHINE - machine to use for socket viewer to connect to
685
686
687 Level: beginner
688
689 Notes:
690 If for some reason you must call MPI_Init() separately, call
691 it before PetscInitialize().
692
693 Fortran Version:
694 In Fortran this routine has the format
695$ call PetscInitialize(file,ierr)
696
697+ ierr - error return code
626- file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use NULL_CHARACTER to not check for
698- file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use PETSC_NULL_CHARACTER to not check for
627 code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files
628
629 Important Fortran Note:
699 code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files
700
701 Important Fortran Note:
630 In Fortran, you MUST use NULL_CHARACTER to indicate a
702 In Fortran, you MUST use PETSC_NULL_CHARACTER to indicate a
631 null character string; you CANNOT just use NULL as
703 null character string; you CANNOT just use NULL as
632 in the C version. See the <a href="../../docs/manual.pdf">users manual</a> for details.
704 in the C version. See Users-Manual: ch_fortran for details.
633
634 If your main program is C but you call Fortran code that also uses PETSc you need to call PetscInitializeFortran() soon after
635 calling PetscInitialize().
636
637 Concepts: initializing PETSc
638
639.seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscInitializeNoArguments()
640
641@*/
642PetscErrorCode PetscInitialize(int *argc,char ***args,const char file[],const char help[])
643{
644 PetscErrorCode ierr;
645 PetscMPIInt flag, size;
705
706 If your main program is C but you call Fortran code that also uses PETSc you need to call PetscInitializeFortran() soon after
707 calling PetscInitialize().
708
709 Concepts: initializing PETSc
710
711.seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscInitializeNoArguments()
712
713@*/
714PetscErrorCode PetscInitialize(int *argc,char ***args,const char file[],const char help[])
715{
716 PetscErrorCode ierr;
717 PetscMPIInt flag, size;
646 PetscInt nodesize;
647 PetscBool flg;
718 PetscBool flg = PETSC_TRUE;
648 char hostname[256];
719 char hostname[256];
720#if defined(PETSC_HAVE_CUDA)
721 cublasStatus_t cberr;
722#endif
723#if defined(PETSC_HAVE_HWLOC)
724 PetscViewer viewer;
725#endif
649
650 PetscFunctionBegin;
651 if (PetscInitializeCalled) PetscFunctionReturn(0);
726
727 PetscFunctionBegin;
728 if (PetscInitializeCalled) PetscFunctionReturn(0);
729 /*
730 The checking over compatible runtime libraries is complicated by the MPI ABI initiative
731 https://wiki.mpich.org/mpich/index.php/ABI_Compatibility_Initiative which started with
732 MPICH v3.1 (Released Feburary 2014)
733 IBM MPI v2.1 (December 2014)
734 Intel® MPI Library v5.0 (2014)
735 Cray MPT v7.0.0 (June 2014)
736 As of July 31, 2017 the ABI number still appears to be 12, that is all of the versions
737 listed above and since that time are compatible.
652
738
739 Unfortunately the MPI ABI initiative has not defined a way to determine the ABI number
740 at compile time or runtime. Thus we will need to systematically track the allowed versions
741 and how they are represented in the mpi.h and MPI_Get_library_version() output in order
742 to perform the checking.
743
744 Currently we only check for pre MPI ABI versions (and packages that do not follow the MPI ABI).
745
746 Questions:
747
748 Should the checks for ABI incompatibility be only on the major version number below?
749 Presumably the output to stderr will be removed before a release.
750 */
751
752#if defined(PETSC_HAVE_MPI_GET_LIBRARY_VERSION)
753 {
754 char mpilibraryversion[MPI_MAX_LIBRARY_VERSION_STRING];
755 PetscMPIInt mpilibraryversionlength;
756 ierr = MPI_Get_library_version(mpilibraryversion,&mpilibraryversionlength);if (ierr) return ierr;
757 /* check for MPICH versions before MPI ABI initiative */
758#if defined(MPICH_VERSION)
759#if MPICH_NUMVERSION < 30100000
760 {
761 char *ver,*lf;
762 flg = PETSC_FALSE;
763 ierr = PetscStrstr(mpilibraryversion,"MPICH Version:",&ver);if (ierr) return ierr;
764 if (ver) {
765 ierr = PetscStrchr(ver,'\n',&lf);if (ierr) return ierr;
766 if (lf) {
767 *lf = 0;
768 ierr = PetscStrendswith(ver,MPICH_VERSION,&flg);if (ierr) return ierr;
769 }
770 }
771 if (!flg) {
772 fprintf(stderr,"PETSc Error --- MPICH library version \n%s does not match what PETSc was compiled with %s, aborting\n",mpilibraryversion,MPICH_VERSION);
773 return PETSC_ERR_MPI_LIB_INCOMP;
774 }
775 }
776#endif
777 /* check for OpenMPI version, it is not part of the MPI ABI initiative (is it part of another initiative that needs to be handled?) */
778#elif defined(OMPI_MAJOR_VERSION)
779 {
780 char *ver,bs[32],*bsf;
781 flg = PETSC_FALSE;
782 ierr = PetscStrstr(mpilibraryversion,"Open MPI",&ver);if (ierr) return ierr;
783 if (ver) {
784 sprintf(bs,"v%d.%d",OMPI_MAJOR_VERSION,OMPI_MINOR_VERSION);
785 ierr = PetscStrstr(ver,bs,&bsf);if (ierr) return ierr;
786 if (bsf) flg = PETSC_TRUE;
787 }
788 if (!flg) {
789 fprintf(stderr,"PETSc Error --- Open MPI library version \n%s does not match what PETSc was compiled with %d.%d, aborting\n",mpilibraryversion,OMPI_MAJOR_VERSION,OMPI_MINOR_VERSION);
790 return PETSC_ERR_MPI_LIB_INCOMP;
791 }
792 }
793#endif
794 }
795#endif
796
797
653 /* these must be initialized in a routine, not as a constant declaration*/
654 PETSC_STDOUT = stdout;
655 PETSC_STDERR = stderr;
656
798 /* these must be initialized in a routine, not as a constant declaration*/
799 PETSC_STDOUT = stdout;
800 PETSC_STDERR = stderr;
801
657 ierr = PetscOptionsCreate();CHKERRQ(ierr);
802 /* on Windows - set printf to default to printing 2 digit exponents */
803#if defined(PETSC_HAVE__SET_OUTPUT_FORMAT)
804 _set_output_format(_TWO_DIGIT_EXPONENT);
805#endif
658
806
807 ierr = PetscOptionsCreateDefault();CHKERRQ(ierr);
808
659 /*
660 We initialize the program name here (before MPI_Init()) because MPICH has a bug in
661 it that it sets args[0] on all processors to be args[0] on the first processor.
662 */
663 if (argc && *argc) {
664 ierr = PetscSetProgramName(**args);CHKERRQ(ierr);
665 } else {
666 ierr = PetscSetProgramName("Unknown Name");CHKERRQ(ierr);

--- 12 unchanged lines hidden (view full) ---

679#endif
680 PetscBeganMPI = PETSC_TRUE;
681 }
682 if (argc && args) {
683 PetscGlobalArgc = *argc;
684 PetscGlobalArgs = *args;
685 }
686 PetscFinalizeCalled = PETSC_FALSE;
809 /*
810 We initialize the program name here (before MPI_Init()) because MPICH has a bug in
811 it that it sets args[0] on all processors to be args[0] on the first processor.
812 */
813 if (argc && *argc) {
814 ierr = PetscSetProgramName(**args);CHKERRQ(ierr);
815 } else {
816 ierr = PetscSetProgramName("Unknown Name");CHKERRQ(ierr);

--- 12 unchanged lines hidden (view full) ---

829#endif
830 PetscBeganMPI = PETSC_TRUE;
831 }
832 if (argc && args) {
833 PetscGlobalArgc = *argc;
834 PetscGlobalArgs = *args;
835 }
836 PetscFinalizeCalled = PETSC_FALSE;
837 ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockOpen);CHKERRQ(ierr);
838 ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockStdout);CHKERRQ(ierr);
839 ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockStderr);CHKERRQ(ierr);
840 ierr = PetscSpinlockCreate(&PetscCommSpinLock);CHKERRQ(ierr);
687
688 if (PETSC_COMM_WORLD == MPI_COMM_NULL) PETSC_COMM_WORLD = MPI_COMM_WORLD;
689 ierr = MPI_Comm_set_errhandler(PETSC_COMM_WORLD,MPI_ERRORS_RETURN);CHKERRQ(ierr);
690
691 /* Done after init due to a bug in MPICH-GM? */
692 ierr = PetscErrorPrintfInitialize();CHKERRQ(ierr);
693
694 ierr = MPI_Comm_rank(MPI_COMM_WORLD,&PetscGlobalRank);CHKERRQ(ierr);

--- 4 unchanged lines hidden (view full) ---

699
700 /*
701 Initialized the global complex variable; this is because with
702 shared libraries the constructors for global variables
703 are not called; at least on IRIX.
704 */
705#if defined(PETSC_HAVE_COMPLEX)
706 {
841
842 if (PETSC_COMM_WORLD == MPI_COMM_NULL) PETSC_COMM_WORLD = MPI_COMM_WORLD;
843 ierr = MPI_Comm_set_errhandler(PETSC_COMM_WORLD,MPI_ERRORS_RETURN);CHKERRQ(ierr);
844
845 /* Done after init due to a bug in MPICH-GM? */
846 ierr = PetscErrorPrintfInitialize();CHKERRQ(ierr);
847
848 ierr = MPI_Comm_rank(MPI_COMM_WORLD,&PetscGlobalRank);CHKERRQ(ierr);

--- 4 unchanged lines hidden (view full) ---

853
854 /*
855 Initialized the global complex variable; this is because with
856 shared libraries the constructors for global variables
857 are not called; at least on IRIX.
858 */
859#if defined(PETSC_HAVE_COMPLEX)
860 {
707#if defined(PETSC_CLANGUAGE_CXX)
861#if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_REAL___FLOAT128)
708 PetscComplex ic(0.0,1.0);
709 PETSC_i = ic;
862 PetscComplex ic(0.0,1.0);
863 PETSC_i = ic;
710#elif defined(PETSC_CLANGUAGE_C)
864#else
711 PETSC_i = _Complex_I;
712#endif
713 }
714
715#if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
716 ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr);
717 ierr = MPI_Type_commit(&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr);
718 ierr = MPI_Type_contiguous(2,MPI_FLOAT,&MPIU_C_COMPLEX);CHKERRQ(ierr);
719 ierr = MPI_Type_commit(&MPIU_C_COMPLEX);CHKERRQ(ierr);
720#endif
721#endif /* PETSC_HAVE_COMPLEX */
722
723 /*
724 Create the PETSc MPI reduction operator that sums of the first
725 half of the entries and maxes the second half.
726 */
865 PETSC_i = _Complex_I;
866#endif
867 }
868
869#if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
870 ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr);
871 ierr = MPI_Type_commit(&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr);
872 ierr = MPI_Type_contiguous(2,MPI_FLOAT,&MPIU_C_COMPLEX);CHKERRQ(ierr);
873 ierr = MPI_Type_commit(&MPIU_C_COMPLEX);CHKERRQ(ierr);
874#endif
875#endif /* PETSC_HAVE_COMPLEX */
876
877 /*
878 Create the PETSc MPI reduction operator that sums of the first
879 half of the entries and maxes the second half.
880 */
727 ierr = MPI_Op_create(PetscMaxSum_Local,1,&PetscMaxSum_Op);CHKERRQ(ierr);
881 ierr = MPI_Op_create(MPIU_MaxSum_Local,1,&MPIU_MAXSUM_OP);CHKERRQ(ierr);
728
729#if defined(PETSC_USE_REAL___FLOAT128)
730 ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU___FLOAT128);CHKERRQ(ierr);
731 ierr = MPI_Type_commit(&MPIU___FLOAT128);CHKERRQ(ierr);
732#if defined(PETSC_HAVE_COMPLEX)
733 ierr = MPI_Type_contiguous(4,MPI_DOUBLE,&MPIU___COMPLEX128);CHKERRQ(ierr);
734 ierr = MPI_Type_commit(&MPIU___COMPLEX128);CHKERRQ(ierr);
735#endif
736 ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX);CHKERRQ(ierr);
737 ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN);CHKERRQ(ierr);
882
883#if defined(PETSC_USE_REAL___FLOAT128)
884 ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU___FLOAT128);CHKERRQ(ierr);
885 ierr = MPI_Type_commit(&MPIU___FLOAT128);CHKERRQ(ierr);
886#if defined(PETSC_HAVE_COMPLEX)
887 ierr = MPI_Type_contiguous(4,MPI_DOUBLE,&MPIU___COMPLEX128);CHKERRQ(ierr);
888 ierr = MPI_Type_commit(&MPIU___COMPLEX128);CHKERRQ(ierr);
889#endif
890 ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX);CHKERRQ(ierr);
891 ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN);CHKERRQ(ierr);
892#elif defined(PETSC_USE_REAL___FP16)
893 ierr = MPI_Type_contiguous(2,MPI_CHAR,&MPIU___FP16);CHKERRQ(ierr);
894 ierr = MPI_Type_commit(&MPIU___FP16);CHKERRQ(ierr);
895 ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX);CHKERRQ(ierr);
896 ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN);CHKERRQ(ierr);
738#endif
739
897#endif
898
740#if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128)
899#if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
741 ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM);CHKERRQ(ierr);
742#endif
743
744 ierr = MPI_Type_contiguous(2,MPIU_SCALAR,&MPIU_2SCALAR);CHKERRQ(ierr);
745 ierr = MPI_Type_commit(&MPIU_2SCALAR);CHKERRQ(ierr);
900 ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM);CHKERRQ(ierr);
901#endif
902
903 ierr = MPI_Type_contiguous(2,MPIU_SCALAR,&MPIU_2SCALAR);CHKERRQ(ierr);
904 ierr = MPI_Type_commit(&MPIU_2SCALAR);CHKERRQ(ierr);
746 ierr = MPI_Op_create(PetscADMax_Local,1,&PetscADMax_Op);CHKERRQ(ierr);
747 ierr = MPI_Op_create(PetscADMin_Local,1,&PetscADMin_Op);CHKERRQ(ierr);
748
749#if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT)
750 ierr = MPI_Type_contiguous(2,MPIU_INT,&MPIU_2INT);CHKERRQ(ierr);
751 ierr = MPI_Type_commit(&MPIU_2INT);CHKERRQ(ierr);
752#endif
753
905
906#if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT)
907 ierr = MPI_Type_contiguous(2,MPIU_INT,&MPIU_2INT);CHKERRQ(ierr);
908 ierr = MPI_Type_commit(&MPIU_2INT);CHKERRQ(ierr);
909#endif
910
911
754 /*
755 Attributes to be set on PETSc communicators
756 */
757 ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelCounter,&Petsc_Counter_keyval,(void*)0);CHKERRQ(ierr);
758 ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelComm_Outer,&Petsc_InnerComm_keyval,(void*)0);CHKERRQ(ierr);
759 ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelComm_Inner,&Petsc_OuterComm_keyval,(void*)0);CHKERRQ(ierr);
760
761 /*
762 Build the options database
763 */
912 /*
913 Attributes to be set on PETSc communicators
914 */
915 ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelCounter,&Petsc_Counter_keyval,(void*)0);CHKERRQ(ierr);
916 ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelComm_Outer,&Petsc_InnerComm_keyval,(void*)0);CHKERRQ(ierr);
917 ierr = MPI_Keyval_create(MPI_NULL_COPY_FN,Petsc_DelComm_Inner,&Petsc_OuterComm_keyval,(void*)0);CHKERRQ(ierr);
918
919 /*
920 Build the options database
921 */
764 ierr = PetscOptionsInsert(argc,args,file);CHKERRQ(ierr);
922 ierr = PetscOptionsInsert(NULL,argc,args,file);CHKERRQ(ierr);
765
766
767 /*
768 Print main application help message
769 */
923
924
925 /*
926 Print main application help message
927 */
770 ierr = PetscOptionsHasName(NULL,"-help",&flg);CHKERRQ(ierr);
928 ierr = PetscOptionsHasName(NULL,NULL,"-help",&flg);CHKERRQ(ierr);
771 if (help && flg) {
772 ierr = PetscPrintf(PETSC_COMM_WORLD,help);CHKERRQ(ierr);
773 }
774 ierr = PetscOptionsCheckInitial_Private();CHKERRQ(ierr);
775
929 if (help && flg) {
930 ierr = PetscPrintf(PETSC_COMM_WORLD,help);CHKERRQ(ierr);
931 }
932 ierr = PetscOptionsCheckInitial_Private();CHKERRQ(ierr);
933
776 /* SHOULD PUT IN GUARDS: Make sure logging is initialized, even if we do not print it out */
934 ierr = PetscCitationsInitialize();CHKERRQ(ierr);
935
936#if defined(PETSC_HAVE_SAWS)
937 ierr = PetscInitializeSAWs(help);CHKERRQ(ierr);
938#endif
939
940 /* Creates the logging data structures; this is enabled even if logging is not turned on */
777#if defined(PETSC_USE_LOG)
941#if defined(PETSC_USE_LOG)
778 ierr = PetscLogBegin_Private();CHKERRQ(ierr);
942 ierr = PetscLogInitialize();CHKERRQ(ierr);
779#endif
780
781 /*
782 Load the dynamic libraries (on machines that support them), this registers all
783 the solvers etc. (On non-dynamic machines this initializes the PetscDraw and PetscViewer classes)
784 */
785 ierr = PetscInitialize_DynamicLibraries();CHKERRQ(ierr);
786
787 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
788 ierr = PetscInfo1(0,"PETSc successfully started: number of processors = %d\n",size);CHKERRQ(ierr);
789 ierr = PetscGetHostName(hostname,256);CHKERRQ(ierr);
790 ierr = PetscInfo1(0,"Running on machine: %s\n",hostname);CHKERRQ(ierr);
791
792 ierr = PetscOptionsCheckInitial_Components();CHKERRQ(ierr);
793 /* Check the options database for options related to the options database itself */
943#endif
944
945 /*
946 Load the dynamic libraries (on machines that support them), this registers all
947 the solvers etc. (On non-dynamic machines this initializes the PetscDraw and PetscViewer classes)
948 */
949 ierr = PetscInitialize_DynamicLibraries();CHKERRQ(ierr);
950
951 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
952 ierr = PetscInfo1(0,"PETSc successfully started: number of processors = %d\n",size);CHKERRQ(ierr);
953 ierr = PetscGetHostName(hostname,256);CHKERRQ(ierr);
954 ierr = PetscInfo1(0,"Running on machine: %s\n",hostname);CHKERRQ(ierr);
955
956 ierr = PetscOptionsCheckInitial_Components();CHKERRQ(ierr);
957 /* Check the options database for options related to the options database itself */
794 ierr = PetscOptionsSetFromOptions();CHKERRQ(ierr);
958 ierr = PetscOptionsSetFromOptions(NULL);CHKERRQ(ierr);
795
796#if defined(PETSC_USE_PETSC_MPI_EXTERNAL32)
797 /*
798 Tell MPI about our own data representation converter, this would/should be used if extern32 is not supported by the MPI
799
800 Currently not used because it is not supported by MPICH.
801 */
802#if !defined(PETSC_WORDS_BIGENDIAN)
803 ierr = MPI_Register_datarep((char*)"petsc",PetscDataRep_read_conv_fn,PetscDataRep_write_conv_fn,PetscDataRep_extent_fn,NULL);CHKERRQ(ierr);
804#endif
805#endif
806
959
960#if defined(PETSC_USE_PETSC_MPI_EXTERNAL32)
961 /*
962 Tell MPI about our own data representation converter, this would/should be used if extern32 is not supported by the MPI
963
964 Currently not used because it is not supported by MPICH.
965 */
966#if !defined(PETSC_WORDS_BIGENDIAN)
967 ierr = MPI_Register_datarep((char*)"petsc",PetscDataRep_read_conv_fn,PetscDataRep_write_conv_fn,PetscDataRep_extent_fn,NULL);CHKERRQ(ierr);
968#endif
969#endif
970
807 ierr = PetscOptionsGetInt(NULL,"-hmpi_spawn_size",&nodesize,&flg);CHKERRQ(ierr);
808 if (flg) {
809#if defined(PETSC_HAVE_MPI_COMM_SPAWN)
810 ierr = PetscHMPISpawn((PetscMPIInt) nodesize);CHKERRQ(ierr); /* worker nodes never return from here; they go directly to PetscEnd() */
811#else
812 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"PETSc built without MPI 2 (MPI_Comm_spawn) support, use -hmpi_merge_size instead");
813#endif
814 } else {
815 ierr = PetscOptionsGetInt(NULL,"-hmpi_merge_size",&nodesize,&flg);CHKERRQ(ierr);
816 if (flg) {
817 ierr = PetscHMPIMerge((PetscMPIInt) nodesize,NULL,NULL);CHKERRQ(ierr);
818 if (PetscHMPIWorker) { /* if worker then never enter user code */
819 PetscInitializeCalled = PETSC_TRUE;
820 PetscEnd();
821 }
822 }
823 }
824
825#if defined(PETSC_HAVE_CUDA)
971#if defined(PETSC_HAVE_CUDA)
826 {
972 flg = PETSC_TRUE;
973 ierr = PetscOptionsGetBool(NULL,NULL,"-cublas",&flg,NULL);CHKERRQ(ierr);
974 if (flg) {
827 PetscMPIInt p;
828 for (p = 0; p < PetscGlobalSize; ++p) {
975 PetscMPIInt p;
976 for (p = 0; p < PetscGlobalSize; ++p) {
829 if (p == PetscGlobalRank) cublasInit();
977 if (p == PetscGlobalRank) {
978 cberr = cublasCreate(&cublasv2handle);CHKERRCUBLAS(cberr);
979 }
830 ierr = MPI_Barrier(PETSC_COMM_WORLD);CHKERRQ(ierr);
831 }
832 }
833#endif
834
980 ierr = MPI_Barrier(PETSC_COMM_WORLD);CHKERRQ(ierr);
981 }
982 }
983#endif
984
835 ierr = PetscOptionsHasName(NULL,"-python",&flg);CHKERRQ(ierr);
985 ierr = PetscOptionsHasName(NULL,NULL,"-python",&flg);CHKERRQ(ierr);
836 if (flg) {
837 PetscInitializeCalled = PETSC_TRUE;
838 ierr = PetscPythonInitialize(NULL,NULL);CHKERRQ(ierr);
839 }
840
986 if (flg) {
987 PetscInitializeCalled = PETSC_TRUE;
988 ierr = PetscPythonInitialize(NULL,NULL);CHKERRQ(ierr);
989 }
990
841 ierr = PetscThreadCommInitializePackage();CHKERRQ(ierr);
842
843 /*
844 Setup building of stack frames for all function calls
845 */
991 /*
992 Setup building of stack frames for all function calls
993 */
846 PetscThreadLocalRegister((PetscThreadKey*)&petscstack); /* Creates pthread_key */
847#if defined(PETSC_USE_DEBUG)
994#if defined(PETSC_USE_DEBUG) && !defined(PETSC_HAVE_THREADSAFETY)
848 ierr = PetscStackCreate();CHKERRQ(ierr);
849#endif
850
851#if defined(PETSC_SERIALIZE_FUNCTIONS)
852 ierr = PetscFPTCreate(10000);CHKERRQ(ierr);
853#endif
854
995 ierr = PetscStackCreate();CHKERRQ(ierr);
996#endif
997
998#if defined(PETSC_SERIALIZE_FUNCTIONS)
999 ierr = PetscFPTCreate(10000);CHKERRQ(ierr);
1000#endif
1001
1002#if defined(PETSC_HAVE_HWLOC)
1003 ierr = PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,"-process_view",&viewer,NULL,&flg);CHKERRQ(ierr);
1004 if (flg) {
1005 ierr = PetscProcessPlacementView(viewer);CHKERRQ(ierr);
1006 }
1007#endif
1008
855 /*
856 Once we are completedly initialized then we can set this variables
857 */
858 PetscInitializeCalled = PETSC_TRUE;
859 PetscFunctionReturn(0);
860}
861
1009 /*
1010 Once we are completedly initialized then we can set this variables
1011 */
1012 PetscInitializeCalled = PETSC_TRUE;
1013 PetscFunctionReturn(0);
1014}
1015
1016#if defined(PETSC_USE_LOG)
862extern PetscObject *PetscObjects;
863extern PetscInt PetscObjectsCounts, PetscObjectsMaxCounts;
1017extern PetscObject *PetscObjects;
1018extern PetscInt PetscObjectsCounts, PetscObjectsMaxCounts;
1019extern PetscBool PetscObjectsLog;
1020#endif
864
1021
865#undef __FUNCT__
866#define __FUNCT__ "PetscFinalize"
1022/*
1023 Frees all the MPI types and operations that PETSc may have created
1024*/
1025PetscErrorCode PetscFreeMPIResources(void)
1026{
1027 PetscErrorCode ierr;
1028
1029 PetscFunctionBegin;
1030#if defined(PETSC_USE_REAL___FLOAT128)
1031 ierr = MPI_Type_free(&MPIU___FLOAT128);CHKERRQ(ierr);
1032#if defined(PETSC_HAVE_COMPLEX)
1033 ierr = MPI_Type_free(&MPIU___COMPLEX128);CHKERRQ(ierr);
1034#endif
1035 ierr = MPI_Op_free(&MPIU_MAX);CHKERRQ(ierr);
1036 ierr = MPI_Op_free(&MPIU_MIN);CHKERRQ(ierr);
1037#elif defined(PETSC_USE_REAL___FP16)
1038 ierr = MPI_Type_free(&MPIU___FP16);CHKERRQ(ierr);
1039 ierr = MPI_Op_free(&MPIU_MAX);CHKERRQ(ierr);
1040 ierr = MPI_Op_free(&MPIU_MIN);CHKERRQ(ierr);
1041#endif
1042
1043#if defined(PETSC_HAVE_COMPLEX)
1044#if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
1045 ierr = MPI_Type_free(&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr);
1046 ierr = MPI_Type_free(&MPIU_C_COMPLEX);CHKERRQ(ierr);
1047#endif
1048#endif
1049
1050#if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1051 ierr = MPI_Op_free(&MPIU_SUM);CHKERRQ(ierr);
1052#endif
1053
1054 ierr = MPI_Type_free(&MPIU_2SCALAR);CHKERRQ(ierr);
1055#if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT)
1056 ierr = MPI_Type_free(&MPIU_2INT);CHKERRQ(ierr);
1057#endif
1058 ierr = MPI_Op_free(&MPIU_MAXSUM_OP);CHKERRQ(ierr);
1059 PetscFunctionReturn(0);
1060}
1061
867/*@C
868 PetscFinalize - Checks for options to be called at the conclusion
869 of the program. MPI_Finalize() is called only if the user had not
870 called MPI_Init() before calling PetscInitialize().
871
872 Collective on PETSC_COMM_WORLD
873
874 Options Database Keys:

--- 13 unchanged lines hidden (view full) ---

888.seealso: PetscInitialize(), PetscOptionsView(), PetscMallocDump(), PetscMPIDump(), PetscEnd()
889@*/
890PetscErrorCode PetscFinalize(void)
891{
892 PetscErrorCode ierr;
893 PetscMPIInt rank;
894 PetscInt nopt;
895 PetscBool flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE;
1062/*@C
1063 PetscFinalize - Checks for options to be called at the conclusion
1064 of the program. MPI_Finalize() is called only if the user had not
1065 called MPI_Init() before calling PetscInitialize().
1066
1067 Collective on PETSC_COMM_WORLD
1068
1069 Options Database Keys:

--- 13 unchanged lines hidden (view full) ---

1083.seealso: PetscInitialize(), PetscOptionsView(), PetscMallocDump(), PetscMPIDump(), PetscEnd()
1084@*/
1085PetscErrorCode PetscFinalize(void)
1086{
1087 PetscErrorCode ierr;
1088 PetscMPIInt rank;
1089 PetscInt nopt;
1090 PetscBool flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE;
896#if defined(PETSC_HAVE_AMS)
897 PetscBool flg = PETSC_FALSE;
898#endif
1091 PetscBool flg;
899#if defined(PETSC_USE_LOG)
900 char mname[PETSC_MAX_PATH_LEN];
901#endif
1092#if defined(PETSC_USE_LOG)
1093 char mname[PETSC_MAX_PATH_LEN];
1094#endif
1095#if defined(PETSC_HAVE_CUDA)
1096 cublasStatus_t cberr;
1097#endif
902
903 PetscFunctionBegin;
904 if (!PetscInitializeCalled) {
905 printf("PetscInitialize() must be called before PetscFinalize()\n");
906 PetscFunctionReturn(PETSC_ERR_ARG_WRONGSTATE);
907 }
908 ierr = PetscInfo(NULL,"PetscFinalize() called\n");CHKERRQ(ierr);
909
1098
1099 PetscFunctionBegin;
1100 if (!PetscInitializeCalled) {
1101 printf("PetscInitialize() must be called before PetscFinalize()\n");
1102 PetscFunctionReturn(PETSC_ERR_ARG_WRONGSTATE);
1103 }
1104 ierr = PetscInfo(NULL,"PetscFinalize() called\n");CHKERRQ(ierr);
1105
1106 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
1107
1108 ierr = PetscOptionsHasName(NULL,NULL,"-citations",&flg);CHKERRQ(ierr);
1109 if (flg) {
1110 char *cits, filename[PETSC_MAX_PATH_LEN];
1111 FILE *fd = PETSC_STDOUT;
1112
1113 ierr = PetscOptionsGetString(NULL,NULL,"-citations",filename,PETSC_MAX_PATH_LEN,NULL);CHKERRQ(ierr);
1114 if (filename[0]) {
1115 ierr = PetscFOpen(PETSC_COMM_WORLD,filename,"w",&fd);CHKERRQ(ierr);
1116 }
1117 ierr = PetscSegBufferGet(PetscCitationsList,1,&cits);CHKERRQ(ierr);
1118 cits[0] = 0;
1119 ierr = PetscSegBufferExtractAlloc(PetscCitationsList,&cits);CHKERRQ(ierr);
1120 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"If you publish results based on this computation please cite the following:\n");CHKERRQ(ierr);
1121 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"===========================================================================\n");CHKERRQ(ierr);
1122 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"%s",cits);CHKERRQ(ierr);
1123 ierr = PetscFPrintf(PETSC_COMM_WORLD,fd,"===========================================================================\n");CHKERRQ(ierr);
1124 ierr = PetscFClose(PETSC_COMM_WORLD,fd);CHKERRQ(ierr);
1125 ierr = PetscFree(cits);CHKERRQ(ierr);
1126 }
1127 ierr = PetscSegBufferDestroy(&PetscCitationsList);CHKERRQ(ierr);
1128
1129#if defined(PETSC_HAVE_SSL) && defined(PETSC_USE_SOCKET_VIEWER)
1130 /* TextBelt is run for testing purposes only, please do not use this feature often */
1131 {
1132 PetscInt nmax = 2;
1133 char **buffs;
1134 ierr = PetscMalloc1(2,&buffs);CHKERRQ(ierr);
1135 ierr = PetscOptionsGetStringArray(NULL,NULL,"-textbelt",buffs,&nmax,&flg1);CHKERRQ(ierr);
1136 if (flg1) {
1137 if (!nmax) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"-textbelt requires either the phone number or number,\"message\"");
1138 if (nmax == 1) {
1139 ierr = PetscMalloc1(128,&buffs[1]);CHKERRQ(ierr);
1140 ierr = PetscGetProgramName(buffs[1],32);CHKERRQ(ierr);
1141 ierr = PetscStrcat(buffs[1]," has completed");CHKERRQ(ierr);
1142 }
1143 ierr = PetscTextBelt(PETSC_COMM_WORLD,buffs[0],buffs[1],NULL);CHKERRQ(ierr);
1144 ierr = PetscFree(buffs[0]);CHKERRQ(ierr);
1145 ierr = PetscFree(buffs[1]);CHKERRQ(ierr);
1146 }
1147 ierr = PetscFree(buffs);CHKERRQ(ierr);
1148 }
1149 {
1150 PetscInt nmax = 2;
1151 char **buffs;
1152 ierr = PetscMalloc1(2,&buffs);CHKERRQ(ierr);
1153 ierr = PetscOptionsGetStringArray(NULL,NULL,"-tellmycell",buffs,&nmax,&flg1);CHKERRQ(ierr);
1154 if (flg1) {
1155 if (!nmax) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"-tellmycell requires either the phone number or number,\"message\"");
1156 if (nmax == 1) {
1157 ierr = PetscMalloc1(128,&buffs[1]);CHKERRQ(ierr);
1158 ierr = PetscGetProgramName(buffs[1],32);CHKERRQ(ierr);
1159 ierr = PetscStrcat(buffs[1]," has completed");CHKERRQ(ierr);
1160 }
1161 ierr = PetscTellMyCell(PETSC_COMM_WORLD,buffs[0],buffs[1],NULL);CHKERRQ(ierr);
1162 ierr = PetscFree(buffs[0]);CHKERRQ(ierr);
1163 ierr = PetscFree(buffs[1]);CHKERRQ(ierr);
1164 }
1165 ierr = PetscFree(buffs);CHKERRQ(ierr);
1166 }
1167#endif
1168 /*
1169 It should be safe to cancel the options monitors, since we don't expect to be setting options
1170 here (at least that are worth monitoring). Monitors ought to be released so that they release
1171 whatever memory was allocated there before -malloc_dump reports unfreed memory.
1172 */
1173 ierr = PetscOptionsMonitorCancel();CHKERRQ(ierr);
1174
910#if defined(PETSC_SERIALIZE_FUNCTIONS)
911 ierr = PetscFPTDestroy();CHKERRQ(ierr);
912#endif
913
914
1175#if defined(PETSC_SERIALIZE_FUNCTIONS)
1176 ierr = PetscFPTDestroy();CHKERRQ(ierr);
1177#endif
1178
1179
915#if defined(PETSC_HAVE_AMS)
916 ierr = PetscOptionsGetBool(NULL,"-options_gui",&flg,NULL);CHKERRQ(ierr);
1180#if defined(PETSC_HAVE_SAWS)
1181 flg = PETSC_FALSE;
1182 ierr = PetscOptionsGetBool(NULL,NULL,"-saw_options",&flg,NULL);CHKERRQ(ierr);
917 if (flg) {
1183 if (flg) {
918 ierr = PetscOptionsAMSDestroy();CHKERRQ(ierr);
1184 ierr = PetscOptionsSAWsDestroy();CHKERRQ(ierr);
919 }
920#endif
921
1185 }
1186#endif
1187
922#if defined(PETSC_HAVE_SERVER)
1188#if defined(PETSC_HAVE_X)
923 flg1 = PETSC_FALSE;
1189 flg1 = PETSC_FALSE;
924 ierr = PetscOptionsGetBool(NULL,"-server",&flg1,NULL);CHKERRQ(ierr);
1190 ierr = PetscOptionsGetBool(NULL,NULL,"-x_virtual",&flg1,NULL);CHKERRQ(ierr);
925 if (flg1) {
926 /* this is a crude hack, but better than nothing */
1191 if (flg1) {
1192 /* this is a crude hack, but better than nothing */
927 ierr = PetscPOpen(PETSC_COMM_WORLD,NULL,"pkill -9 petscwebserver","r",NULL);CHKERRQ(ierr);
1193 ierr = PetscPOpen(PETSC_COMM_WORLD,NULL,"pkill -9 Xvfb","r",NULL);CHKERRQ(ierr);
928 }
929#endif
930
1194 }
1195#endif
1196
931 ierr = PetscHMPIFinalize();CHKERRQ(ierr);
932
933 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
934 ierr = PetscOptionsGetBool(NULL,"-malloc_info",&flg2,NULL);CHKERRQ(ierr);
1197#if !defined(PETSC_HAVE_THREADSAFETY)
1198 ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_info",&flg2,NULL);CHKERRQ(ierr);
935 if (!flg2) {
936 flg2 = PETSC_FALSE;
1199 if (!flg2) {
1200 flg2 = PETSC_FALSE;
937 ierr = PetscOptionsGetBool(NULL,"-memory_info",&flg2,NULL);CHKERRQ(ierr);
1201 ierr = PetscOptionsGetBool(NULL,NULL,"-memory_view",&flg2,NULL);CHKERRQ(ierr);
938 }
939 if (flg2) {
1202 }
1203 if (flg2) {
940 ierr = PetscMemoryShowUsage(PETSC_VIEWER_STDOUT_WORLD,"Summary of Memory Usage in PETSc\n");CHKERRQ(ierr);
1204 ierr = PetscMemoryView(PETSC_VIEWER_STDOUT_WORLD,"Summary of Memory Usage in PETSc\n");CHKERRQ(ierr);
941 }
1205 }
1206#endif
942
943#if defined(PETSC_USE_LOG)
944 flg1 = PETSC_FALSE;
1207
1208#if defined(PETSC_USE_LOG)
1209 flg1 = PETSC_FALSE;
945 ierr = PetscOptionsGetBool(NULL,"-get_total_flops",&flg1,NULL);CHKERRQ(ierr);
1210 ierr = PetscOptionsGetBool(NULL,NULL,"-get_total_flops",&flg1,NULL);CHKERRQ(ierr);
946 if (flg1) {
947 PetscLogDouble flops = 0;
948 ierr = MPI_Reduce(&petsc_TotalFlops,&flops,1,MPI_DOUBLE,MPI_SUM,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
949 ierr = PetscPrintf(PETSC_COMM_WORLD,"Total flops over all processors %g\n",flops);CHKERRQ(ierr);
950 }
951#endif
952
953
954#if defined(PETSC_USE_LOG)
955#if defined(PETSC_HAVE_MPE)
956 mname[0] = 0;
1211 if (flg1) {
1212 PetscLogDouble flops = 0;
1213 ierr = MPI_Reduce(&petsc_TotalFlops,&flops,1,MPI_DOUBLE,MPI_SUM,0,PETSC_COMM_WORLD);CHKERRQ(ierr);
1214 ierr = PetscPrintf(PETSC_COMM_WORLD,"Total flops over all processors %g\n",flops);CHKERRQ(ierr);
1215 }
1216#endif
1217
1218
1219#if defined(PETSC_USE_LOG)
1220#if defined(PETSC_HAVE_MPE)
1221 mname[0] = 0;
957
958 ierr = PetscOptionsGetString(NULL,"-log_mpe",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
1222 ierr = PetscOptionsGetString(NULL,NULL,"-log_mpe",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
959 if (flg1) {
960 if (mname[0]) {ierr = PetscLogMPEDump(mname);CHKERRQ(ierr);}
961 else {ierr = PetscLogMPEDump(0);CHKERRQ(ierr);}
962 }
963#endif
1223 if (flg1) {
1224 if (mname[0]) {ierr = PetscLogMPEDump(mname);CHKERRQ(ierr);}
1225 else {ierr = PetscLogMPEDump(0);CHKERRQ(ierr);}
1226 }
1227#endif
964 mname[0] = 0;
1228#endif
965
1229
966 ierr = PetscOptionsGetString(NULL,"-log_summary",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
1230 /*
1231 Free all objects registered with PetscObjectRegisterDestroy() such as PETSC_VIEWER_XXX_().
1232 */
1233 ierr = PetscObjectRegisterDestroyAll();CHKERRQ(ierr);
1234
1235#if defined(PETSC_USE_LOG)
1236 ierr = PetscLogViewFromOptions();CHKERRQ(ierr);
1237 mname[0] = 0;
1238 ierr = PetscOptionsGetString(NULL,NULL,"-log_summary",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
967 if (flg1) {
968 PetscViewer viewer;
1239 if (flg1) {
1240 PetscViewer viewer;
1241 ierr = (*PetscHelpPrintf)(PETSC_COMM_WORLD,"\n\n WARNING: -log_summary is being deprecated; switch to -log_view\n\n\n");CHKERRQ(ierr);
969 if (mname[0]) {
970 ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,mname,&viewer);CHKERRQ(ierr);
971 ierr = PetscLogView(viewer);CHKERRQ(ierr);
972 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
973 } else {
974 viewer = PETSC_VIEWER_STDOUT_WORLD;
1242 if (mname[0]) {
1243 ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,mname,&viewer);CHKERRQ(ierr);
1244 ierr = PetscLogView(viewer);CHKERRQ(ierr);
1245 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1246 } else {
1247 viewer = PETSC_VIEWER_STDOUT_WORLD;
1248 ierr = PetscViewerPushFormat(viewer,PETSC_VIEWER_DEFAULT);CHKERRQ(ierr);
975 ierr = PetscLogView(viewer);CHKERRQ(ierr);
1249 ierr = PetscLogView(viewer);CHKERRQ(ierr);
1250 ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
976 }
977 }
978
1251 }
1252 }
1253
979 mname[0] = 0;
1254 /*
1255 Free any objects created by the last block of code.
1256 */
1257 ierr = PetscObjectRegisterDestroyAll();CHKERRQ(ierr);
980
1258
981 ierr = PetscOptionsGetString(NULL,"-log_summary_python",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
982 if (flg1) {
983 PetscViewer viewer;
984 if (mname[0]) {
985 ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD,mname,&viewer);CHKERRQ(ierr);
986 ierr = PetscLogViewPython(viewer);CHKERRQ(ierr);
987 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
988 } else {
989 viewer = PETSC_VIEWER_STDOUT_WORLD;
990 ierr = PetscLogViewPython(viewer);CHKERRQ(ierr);
991 }
992 }
993
994 ierr = PetscOptionsGetString(NULL,"-log_detailed",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
995 if (flg1) {
996 if (mname[0]) {ierr = PetscLogPrintDetailed(PETSC_COMM_WORLD,mname);CHKERRQ(ierr);}
997 else {ierr = PetscLogPrintDetailed(PETSC_COMM_WORLD,0);CHKERRQ(ierr);}
998 }
999
1000 mname[0] = 0;
1259 mname[0] = 0;
1001
1002 ierr = PetscOptionsGetString(NULL,"-log_all",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
1003 ierr = PetscOptionsGetString(NULL,"-log",mname,PETSC_MAX_PATH_LEN,&flg2);CHKERRQ(ierr);
1260 ierr = PetscOptionsGetString(NULL,NULL,"-log_all",mname,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
1261 ierr = PetscOptionsGetString(NULL,NULL,"-log",mname,PETSC_MAX_PATH_LEN,&flg2);CHKERRQ(ierr);
1004 if (flg1 || flg2) {
1005 if (mname[0]) PetscLogDump(mname);
1006 else PetscLogDump(0);
1007 }
1008#endif
1009
1262 if (flg1 || flg2) {
1263 if (mname[0]) PetscLogDump(mname);
1264 else PetscLogDump(0);
1265 }
1266#endif
1267
1010 /*
1011 Free all objects registered with PetscObjectRegisterDestroy() such as PETSC_VIEWER_XXX_().
1012 */
1013 ierr = PetscObjectRegisterDestroyAll();CHKERRQ(ierr);
1014
1015 ierr = PetscStackDestroy();CHKERRQ(ierr);
1268 ierr = PetscStackDestroy();CHKERRQ(ierr);
1016 PetscThreadLocalDestroy((PetscThreadKey)petscstack); /* Deletes pthread_key */
1017
1018 flg1 = PETSC_FALSE;
1269
1270 flg1 = PETSC_FALSE;
1019 ierr = PetscOptionsGetBool(NULL,"-no_signal_handler",&flg1,NULL);CHKERRQ(ierr);
1271 ierr = PetscOptionsGetBool(NULL,NULL,"-no_signal_handler",&flg1,NULL);CHKERRQ(ierr);
1020 if (!flg1) { ierr = PetscPopSignalHandler();CHKERRQ(ierr);}
1021 flg1 = PETSC_FALSE;
1272 if (!flg1) { ierr = PetscPopSignalHandler();CHKERRQ(ierr);}
1273 flg1 = PETSC_FALSE;
1022 ierr = PetscOptionsGetBool(NULL,"-mpidump",&flg1,NULL);CHKERRQ(ierr);
1274 ierr = PetscOptionsGetBool(NULL,NULL,"-mpidump",&flg1,NULL);CHKERRQ(ierr);
1023 if (flg1) {
1024 ierr = PetscMPIDump(stdout);CHKERRQ(ierr);
1025 }
1026 flg1 = PETSC_FALSE;
1027 flg2 = PETSC_FALSE;
1028 /* preemptive call to avoid listing this option in options table as unused */
1275 if (flg1) {
1276 ierr = PetscMPIDump(stdout);CHKERRQ(ierr);
1277 }
1278 flg1 = PETSC_FALSE;
1279 flg2 = PETSC_FALSE;
1280 /* preemptive call to avoid listing this option in options table as unused */
1029 ierr = PetscOptionsHasName(NULL,"-malloc_dump",&flg1);CHKERRQ(ierr);
1030 ierr = PetscOptionsHasName(NULL,"-objects_dump",&flg1);CHKERRQ(ierr);
1031 ierr = PetscOptionsGetBool(NULL,"-options_table",&flg2,NULL);CHKERRQ(ierr);
1281 ierr = PetscOptionsHasName(NULL,NULL,"-malloc_dump",&flg1);CHKERRQ(ierr);
1282 ierr = PetscOptionsHasName(NULL,NULL,"-objects_dump",&flg1);CHKERRQ(ierr);
1283 ierr = PetscOptionsGetBool(NULL,NULL,"-options_view",&flg2,NULL);CHKERRQ(ierr);
1032
1033 if (flg2) {
1034 PetscViewer viewer;
1284
1285 if (flg2) {
1286 PetscViewer viewer;
1035 ierr = PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer);CHKERRQ(ierr);
1036 ierr = PetscOptionsView(viewer);CHKERRQ(ierr);
1287 ierr = PetscViewerCreate(PETSC_COMM_WORLD,&viewer);CHKERRQ(ierr);
1288 ierr = PetscViewerSetType(viewer,PETSCVIEWERASCII);CHKERRQ(ierr);
1289 ierr = PetscOptionsView(NULL,viewer);CHKERRQ(ierr);
1037 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1038 }
1039
1040 /* to prevent PETSc -options_left from warning */
1290 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1291 }
1292
1293 /* to prevent PETSc -options_left from warning */
1041 ierr = PetscOptionsHasName(NULL,"-nox",&flg1);CHKERRQ(ierr);
1042 ierr = PetscOptionsHasName(NULL,"-nox_warning",&flg1);CHKERRQ(ierr);
1294 ierr = PetscOptionsHasName(NULL,NULL,"-nox",&flg1);CHKERRQ(ierr);
1295 ierr = PetscOptionsHasName(NULL,NULL,"-nox_warning",&flg1);CHKERRQ(ierr);
1043
1296
1044 if (!PetscHMPIWorker) { /* worker processes skip this because they do not usually process options */
1045 flg3 = PETSC_FALSE; /* default value is required */
1046 ierr = PetscOptionsGetBool(NULL,"-options_left",&flg3,&flg1);CHKERRQ(ierr);
1047 ierr = PetscOptionsAllUsed(&nopt);CHKERRQ(ierr);
1048 if (flg3) {
1049 if (!flg2) { /* have not yet printed the options */
1050 PetscViewer viewer;
1051 ierr = PetscViewerASCIIGetStdout(PETSC_COMM_WORLD,&viewer);CHKERRQ(ierr);
1052 ierr = PetscOptionsView(viewer);CHKERRQ(ierr);
1053 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1054 }
1055 if (!nopt) {
1056 ierr = PetscPrintf(PETSC_COMM_WORLD,"There are no unused options.\n");CHKERRQ(ierr);
1057 } else if (nopt == 1) {
1058 ierr = PetscPrintf(PETSC_COMM_WORLD,"There is one unused database option. It is:\n");CHKERRQ(ierr);
1059 } else {
1060 ierr = PetscPrintf(PETSC_COMM_WORLD,"There are %D unused database options. They are:\n",nopt);CHKERRQ(ierr);
1061 }
1297 flg3 = PETSC_FALSE; /* default value is required */
1298 ierr = PetscOptionsGetBool(NULL,NULL,"-options_left",&flg3,&flg1);CHKERRQ(ierr);
1299 ierr = PetscOptionsAllUsed(NULL,&nopt);CHKERRQ(ierr);
1300 if (flg3) {
1301 if (!flg2) { /* have not yet printed the options */
1302 PetscViewer viewer;
1303 ierr = PetscViewerCreate(PETSC_COMM_WORLD,&viewer);CHKERRQ(ierr);
1304 ierr = PetscViewerSetType(viewer,PETSCVIEWERASCII);CHKERRQ(ierr);
1305 ierr = PetscOptionsView(NULL,viewer);CHKERRQ(ierr);
1306 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1062 }
1307 }
1308 if (!nopt) {
1309 ierr = PetscPrintf(PETSC_COMM_WORLD,"There are no unused options.\n");CHKERRQ(ierr);
1310 } else if (nopt == 1) {
1311 ierr = PetscPrintf(PETSC_COMM_WORLD,"There is one unused database option. It is:\n");CHKERRQ(ierr);
1312 } else {
1313 ierr = PetscPrintf(PETSC_COMM_WORLD,"There are %D unused database options. They are:\n",nopt);CHKERRQ(ierr);
1314 }
1315 }
1063#if defined(PETSC_USE_DEBUG)
1316#if defined(PETSC_USE_DEBUG)
1064 if (nopt && !flg3 && !flg1) {
1065 ierr = PetscPrintf(PETSC_COMM_WORLD,"WARNING! There are options you set that were not used!\n");CHKERRQ(ierr);
1066 ierr = PetscPrintf(PETSC_COMM_WORLD,"WARNING! could be spelling mistake, etc!\n");CHKERRQ(ierr);
1067 ierr = PetscOptionsLeft();CHKERRQ(ierr);
1068 } else if (nopt && flg3) {
1317 if (nopt && !flg3 && !flg1) {
1318 ierr = PetscPrintf(PETSC_COMM_WORLD,"WARNING! There are options you set that were not used!\n");CHKERRQ(ierr);
1319 ierr = PetscPrintf(PETSC_COMM_WORLD,"WARNING! could be spelling mistake, etc!\n");CHKERRQ(ierr);
1320 ierr = PetscOptionsLeft(NULL);CHKERRQ(ierr);
1321 } else if (nopt && flg3) {
1069#else
1322#else
1070 if (nopt && flg3) {
1323 if (nopt && flg3) {
1071#endif
1324#endif
1072 ierr = PetscOptionsLeft();CHKERRQ(ierr);
1073 }
1325 ierr = PetscOptionsLeft(NULL);CHKERRQ(ierr);
1074 }
1075
1326 }
1327
1076 {
1077 PetscThreadComm tcomm_world;
1078 ierr = PetscGetThreadCommWorld(&tcomm_world);CHKERRQ(ierr);
1079 /* Free global thread communicator */
1080 ierr = PetscThreadCommDestroy(&tcomm_world);CHKERRQ(ierr);
1328#if defined(PETSC_HAVE_SAWS)
1329 if (!PetscGlobalRank) {
1330 ierr = PetscStackSAWsViewOff();CHKERRQ(ierr);
1331 PetscStackCallSAWs(SAWs_Finalize,());
1081 }
1332 }
1333#endif
1082
1334
1335#if defined(PETSC_USE_LOG)
1083 /*
1084 List all objects the user may have forgot to free
1085 */
1336 /*
1337 List all objects the user may have forgot to free
1338 */
1086 ierr = PetscOptionsHasName(NULL,"-objects_dump",&flg1);CHKERRQ(ierr);
1087 if (flg1) {
1088 MPI_Comm local_comm;
1089 char string[64];
1339 if (PetscObjectsLog) {
1340 ierr = PetscOptionsHasName(NULL,NULL,"-objects_dump",&flg1);CHKERRQ(ierr);
1341 if (flg1) {
1342 MPI_Comm local_comm;
1343 char string[64];
1090
1344
1091 ierr = PetscOptionsGetString(NULL,"-objects_dump",string,64,NULL);CHKERRQ(ierr);
1092 ierr = MPI_Comm_dup(MPI_COMM_WORLD,&local_comm);CHKERRQ(ierr);
1093 ierr = PetscSequentialPhaseBegin_Private(local_comm,1);CHKERRQ(ierr);
1094 ierr = PetscObjectsDump(stdout,(string[0] == 'a') ? PETSC_TRUE : PETSC_FALSE);CHKERRQ(ierr);
1095 ierr = PetscSequentialPhaseEnd_Private(local_comm,1);CHKERRQ(ierr);
1096 ierr = MPI_Comm_free(&local_comm);CHKERRQ(ierr);
1345 ierr = PetscOptionsGetString(NULL,NULL,"-objects_dump",string,64,NULL);CHKERRQ(ierr);
1346 ierr = MPI_Comm_dup(MPI_COMM_WORLD,&local_comm);CHKERRQ(ierr);
1347 ierr = PetscSequentialPhaseBegin_Private(local_comm,1);CHKERRQ(ierr);
1348 ierr = PetscObjectsDump(stdout,(string[0] == 'a') ? PETSC_TRUE : PETSC_FALSE);CHKERRQ(ierr);
1349 ierr = PetscSequentialPhaseEnd_Private(local_comm,1);CHKERRQ(ierr);
1350 ierr = MPI_Comm_free(&local_comm);CHKERRQ(ierr);
1351 }
1097 }
1352 }
1353#endif
1354
1355#if defined(PETSC_USE_LOG)
1098 PetscObjectsCounts = 0;
1099 PetscObjectsMaxCounts = 0;
1356 PetscObjectsCounts = 0;
1357 PetscObjectsMaxCounts = 0;
1100
1101 ierr = PetscFree(PetscObjects);CHKERRQ(ierr);
1358 ierr = PetscFree(PetscObjects);CHKERRQ(ierr);
1102
1103#if defined(PETSC_USE_LOG)
1104 ierr = PetscLogDestroy();CHKERRQ(ierr);
1105#endif
1106
1107 /*
1108 Destroy any packages that registered a finalize
1109 */
1110 ierr = PetscRegisterFinalizeAll();CHKERRQ(ierr);
1111
1359#endif
1360
1361 /*
1362 Destroy any packages that registered a finalize
1363 */
1364 ierr = PetscRegisterFinalizeAll();CHKERRQ(ierr);
1365
1112 /*
1113 Destroy all the function registration lists created
1114 */
1115 ierr = PetscFinalize_DynamicLibraries();CHKERRQ(ierr);
1366#if defined(PETSC_USE_LOG)
1367 ierr = PetscLogDestroy();CHKERRQ(ierr);
1368#endif
1116
1117 /*
1118 Print PetscFunctionLists that have not been properly freed
1119
1120 ierr = PetscFunctionListPrintAll();CHKERRQ(ierr);
1121 */
1122
1123 if (petsc_history) {
1124 ierr = PetscCloseHistoryFile(&petsc_history);CHKERRQ(ierr);
1125 petsc_history = 0;
1126 }
1369
1370 /*
1371 Print PetscFunctionLists that have not been properly freed
1372
1373 ierr = PetscFunctionListPrintAll();CHKERRQ(ierr);
1374 */
1375
1376 if (petsc_history) {
1377 ierr = PetscCloseHistoryFile(&petsc_history);CHKERRQ(ierr);
1378 petsc_history = 0;
1379 }
1380 ierr = PetscOptionsHelpPrintedDestroy(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr);
1127
1128 ierr = PetscInfoAllow(PETSC_FALSE,NULL);CHKERRQ(ierr);
1129
1381
1382 ierr = PetscInfoAllow(PETSC_FALSE,NULL);CHKERRQ(ierr);
1383
1384#if !defined(PETSC_HAVE_THREADSAFETY)
1130 {
1131 char fname[PETSC_MAX_PATH_LEN];
1132 FILE *fd;
1133 int err;
1134
1135 fname[0] = 0;
1136
1385 {
1386 char fname[PETSC_MAX_PATH_LEN];
1387 FILE *fd;
1388 int err;
1389
1390 fname[0] = 0;
1391
1137 ierr = PetscOptionsGetString(NULL,"-malloc_dump",fname,250,&flg1);CHKERRQ(ierr);
1392 ierr = PetscOptionsGetString(NULL,NULL,"-malloc_dump",fname,250,&flg1);CHKERRQ(ierr);
1138 flg2 = PETSC_FALSE;
1393 flg2 = PETSC_FALSE;
1139 ierr = PetscOptionsGetBool(NULL,"-malloc_test",&flg2,NULL);CHKERRQ(ierr);
1394 ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_test",&flg2,NULL);CHKERRQ(ierr);
1140#if defined(PETSC_USE_DEBUG)
1141 if (PETSC_RUNNING_ON_VALGRIND) flg2 = PETSC_FALSE;
1142#else
1143 flg2 = PETSC_FALSE; /* Skip reporting for optimized builds regardless of -malloc_test */
1144#endif
1145 if (flg1 && fname[0]) {
1146 char sname[PETSC_MAX_PATH_LEN];
1147

--- 14 unchanged lines hidden (view full) ---

1162 }
1163
1164 {
1165 char fname[PETSC_MAX_PATH_LEN];
1166 FILE *fd = NULL;
1167
1168 fname[0] = 0;
1169
1395#if defined(PETSC_USE_DEBUG)
1396 if (PETSC_RUNNING_ON_VALGRIND) flg2 = PETSC_FALSE;
1397#else
1398 flg2 = PETSC_FALSE; /* Skip reporting for optimized builds regardless of -malloc_test */
1399#endif
1400 if (flg1 && fname[0]) {
1401 char sname[PETSC_MAX_PATH_LEN];
1402

--- 14 unchanged lines hidden (view full) ---

1417 }
1418
1419 {
1420 char fname[PETSC_MAX_PATH_LEN];
1421 FILE *fd = NULL;
1422
1423 fname[0] = 0;
1424
1170 ierr = PetscOptionsGetString(NULL,"-malloc_log",fname,250,&flg1);CHKERRQ(ierr);
1171 ierr = PetscOptionsHasName(NULL,"-malloc_log_threshold",&flg2);CHKERRQ(ierr);
1425 ierr = PetscOptionsGetString(NULL,NULL,"-malloc_log",fname,250,&flg1);CHKERRQ(ierr);
1426 ierr = PetscOptionsHasName(NULL,NULL,"-malloc_log_threshold",&flg2);CHKERRQ(ierr);
1172 if (flg1 && fname[0]) {
1173 int err;
1174
1175 if (!rank) {
1176 fd = fopen(fname,"w");
1177 if (!fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot open log file: %s",fname);
1178 }
1179 ierr = PetscMallocDumpLog(fd);CHKERRQ(ierr);
1180 if (fd) {
1181 err = fclose(fd);
1182 if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file");
1183 }
1184 } else if (flg1 || flg2) {
1185 ierr = PetscMallocDumpLog(stdout);CHKERRQ(ierr);
1186 }
1187 }
1427 if (flg1 && fname[0]) {
1428 int err;
1429
1430 if (!rank) {
1431 fd = fopen(fname,"w");
1432 if (!fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot open log file: %s",fname);
1433 }
1434 ierr = PetscMallocDumpLog(fd);CHKERRQ(ierr);
1435 if (fd) {
1436 err = fclose(fd);
1437 if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file");
1438 }
1439 } else if (flg1 || flg2) {
1440 ierr = PetscMallocDumpLog(stdout);CHKERRQ(ierr);
1441 }
1442 }
1188 /* Can be destroyed only after all the options are used */
1189 ierr = PetscOptionsDestroy();CHKERRQ(ierr);
1443#endif
1190
1444
1191 PetscGlobalArgc = 0;
1192 PetscGlobalArgs = 0;
1445 /*
1446 Close any open dynamic libraries
1447 */
1448 ierr = PetscFinalize_DynamicLibraries();CHKERRQ(ierr);
1193
1449
1194#if defined(PETSC_USE_REAL___FLOAT128)
1195 ierr = MPI_Type_free(&MPIU___FLOAT128);CHKERRQ(ierr);
1196#if defined(PETSC_HAVE_COMPLEX)
1197 ierr = MPI_Type_free(&MPIU___COMPLEX128);CHKERRQ(ierr);
1450#if defined(PETSC_HAVE_CUDA)
1451 flg = PETSC_TRUE;
1452 ierr = PetscOptionsGetBool(NULL,NULL,"-cublas",&flg,NULL);CHKERRQ(ierr);
1453 if (flg) {
1454 PetscInt p;
1455 for (p = 0; p < PetscGlobalSize; ++p) {
1456 if (p == PetscGlobalRank) {
1457 if (cublasv2handle) {
1458 cberr = cublasDestroy(cublasv2handle);CHKERRCUBLAS(cberr);
1459 }
1460 }
1461 ierr = MPI_Barrier(PETSC_COMM_WORLD);CHKERRQ(ierr);
1462 }
1463 }
1198#endif
1464#endif
1199 ierr = MPI_Op_free(&MPIU_MAX);CHKERRQ(ierr);
1200 ierr = MPI_Op_free(&MPIU_MIN);CHKERRQ(ierr);
1201#endif
1202
1465
1203#if defined(PETSC_HAVE_COMPLEX)
1204#if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
1205 ierr = MPI_Type_free(&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr);
1206 ierr = MPI_Type_free(&MPIU_C_COMPLEX);CHKERRQ(ierr);
1207#endif
1208#endif
1466 /* Can be destroyed only after all the options are used */
1467 ierr = PetscOptionsDestroyDefault();CHKERRQ(ierr);
1209
1468
1210#if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128)
1211 ierr = MPI_Op_free(&MPIU_SUM);CHKERRQ(ierr);
1212#endif
1469 PetscGlobalArgc = 0;
1470 PetscGlobalArgs = 0;
1213
1471
1214 ierr = MPI_Type_free(&MPIU_2SCALAR);CHKERRQ(ierr);
1215#if defined(PETSC_USE_64BIT_INDICES) || !defined(MPI_2INT)
1216 ierr = MPI_Type_free(&MPIU_2INT);CHKERRQ(ierr);
1217#endif
1218 ierr = MPI_Op_free(&PetscMaxSum_Op);CHKERRQ(ierr);
1219 ierr = MPI_Op_free(&PetscADMax_Op);CHKERRQ(ierr);
1220 ierr = MPI_Op_free(&PetscADMin_Op);CHKERRQ(ierr);
1472 ierr = PetscFreeMPIResources();CHKERRQ(ierr);
1221
1222 /*
1223 Destroy any known inner MPI_Comm's and attributes pointing to them
1224 Note this will not destroy any new communicators the user has created.
1225
1226 If all PETSc objects were not destroyed those left over objects will have hanging references to
1227 the MPI_Comms that were freed; but that is ok because those PETSc objects will never be used again
1228 */

--- 23 unchanged lines hidden (view full) ---

1252 ierr = MPI_Comm_free(&icomm);CHKERRQ(ierr);
1253 }
1254 }
1255
1256 ierr = MPI_Keyval_free(&Petsc_Counter_keyval);CHKERRQ(ierr);
1257 ierr = MPI_Keyval_free(&Petsc_InnerComm_keyval);CHKERRQ(ierr);
1258 ierr = MPI_Keyval_free(&Petsc_OuterComm_keyval);CHKERRQ(ierr);
1259
1473
1474 /*
1475 Destroy any known inner MPI_Comm's and attributes pointing to them
1476 Note this will not destroy any new communicators the user has created.
1477
1478 If all PETSc objects were not destroyed those left over objects will have hanging references to
1479 the MPI_Comms that were freed; but that is ok because those PETSc objects will never be used again
1480 */

--- 23 unchanged lines hidden (view full) ---

1504 ierr = MPI_Comm_free(&icomm);CHKERRQ(ierr);
1505 }
1506 }
1507
1508 ierr = MPI_Keyval_free(&Petsc_Counter_keyval);CHKERRQ(ierr);
1509 ierr = MPI_Keyval_free(&Petsc_InnerComm_keyval);CHKERRQ(ierr);
1510 ierr = MPI_Keyval_free(&Petsc_OuterComm_keyval);CHKERRQ(ierr);
1511
1260#if defined(PETSC_HAVE_CUDA)
1261 {
1262 PetscInt p;
1263 for (p = 0; p < PetscGlobalSize; ++p) {
1264 if (p == PetscGlobalRank) cublasShutdown();
1265 ierr = MPI_Barrier(PETSC_COMM_WORLD);CHKERRQ(ierr);
1266 }
1267 }
1268#endif
1512 ierr = PetscSpinlockDestroy(&PetscViewerASCIISpinLockOpen);CHKERRQ(ierr);
1513 ierr = PetscSpinlockDestroy(&PetscViewerASCIISpinLockStdout);CHKERRQ(ierr);
1514 ierr = PetscSpinlockDestroy(&PetscViewerASCIISpinLockStderr);CHKERRQ(ierr);
1515 ierr = PetscSpinlockDestroy(&PetscCommSpinLock);CHKERRQ(ierr);
1269
1270 if (PetscBeganMPI) {
1271#if defined(PETSC_HAVE_MPI_FINALIZED)
1272 PetscMPIInt flag;
1273 ierr = MPI_Finalized(&flag);CHKERRQ(ierr);
1274 if (flag) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI_Finalize() has already been called, even though MPI_Init() was called by PetscInitialize()");
1275#endif
1276 ierr = MPI_Finalize();CHKERRQ(ierr);

--- 8 unchanged lines hidden (view full) ---

1285 [ 1] 8 bytes PetscCommDuplicate() line 645 in src/sys/mpiu.c indicating the
1286 memory was not freed.
1287
1288*/
1289 ierr = PetscMallocClear();CHKERRQ(ierr);
1290
1291 PetscInitializeCalled = PETSC_FALSE;
1292 PetscFinalizeCalled = PETSC_TRUE;
1516
1517 if (PetscBeganMPI) {
1518#if defined(PETSC_HAVE_MPI_FINALIZED)
1519 PetscMPIInt flag;
1520 ierr = MPI_Finalized(&flag);CHKERRQ(ierr);
1521 if (flag) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI_Finalize() has already been called, even though MPI_Init() was called by PetscInitialize()");
1522#endif
1523 ierr = MPI_Finalize();CHKERRQ(ierr);

--- 8 unchanged lines hidden (view full) ---

1532 [ 1] 8 bytes PetscCommDuplicate() line 645 in src/sys/mpiu.c indicating the
1533 memory was not freed.
1534
1535*/
1536 ierr = PetscMallocClear();CHKERRQ(ierr);
1537
1538 PetscInitializeCalled = PETSC_FALSE;
1539 PetscFinalizeCalled = PETSC_TRUE;
1293 PetscFunctionReturn(ierr);
1540 PetscFunctionReturn(0);
1294}
1295
1296#if defined(PETSC_MISSING_LAPACK_lsame_)
1297PETSC_EXTERN int lsame_(char *a,char *b)
1298{
1299 if (*a == *b) return 1;
1300 if (*a + 32 == *b) return 1;
1301 if (*a - 32 == *b) return 1;

--- 13 unchanged lines hidden ---
1541}
1542
1543#if defined(PETSC_MISSING_LAPACK_lsame_)
1544PETSC_EXTERN int lsame_(char *a,char *b)
1545{
1546 if (*a == *b) return 1;
1547 if (*a + 32 == *b) return 1;
1548 if (*a - 32 == *b) return 1;

--- 13 unchanged lines hidden ---