Actual source code: init.c
1: /*
3: This file defines part of the initialization of PETSc
5: This file uses regular malloc and free because it cannot be known
6: what malloc is being used until it has already processed the input.
7: */
8: #include <petsc/private/petscimpl.h>
10: #if defined(PETSC_HAVE_UNISTD_H)
11: #include <unistd.h>
12: #endif
14: /* ------------------------Nasty global variables -------------------------------*/
15: /*
16: Indicates if PETSc started up MPI, or it was
17: already started before PETSc was initialized.
18: */
19: PetscBool PetscBeganMPI = PETSC_FALSE;
20: PetscBool PetscErrorHandlingInitialized = PETSC_FALSE;
21: PetscBool PetscInitializeCalled = PETSC_FALSE;
22: PetscBool PetscFinalizeCalled = PETSC_FALSE;
24: PetscMPIInt PetscGlobalRank = -1;
25: PetscMPIInt PetscGlobalSize = -1;
27: #if defined(PETSC_HAVE_KOKKOS)
28: PetscBool PetscBeganKokkos = PETSC_FALSE;
29: #endif
31: #if defined(PETSC_HAVE_NVSHMEM)
32: PetscBool PetscBeganNvshmem = PETSC_FALSE;
33: PetscBool PetscNvshmemInitialized = PETSC_FALSE;
34: #endif
36: PetscBool use_gpu_aware_mpi = PetscDefined(HAVE_MPIUNI) ? PETSC_FALSE : PETSC_TRUE;
38: PetscBool PetscPrintFunctionList = PETSC_FALSE;
40: #if defined(PETSC_HAVE_COMPLEX)
41: #if defined(PETSC_COMPLEX_INSTANTIATE)
42: template <>
43: class std::complex<double>; /* instantiate complex template class */
44: #endif
46: /*MC
47: PETSC_i - the imaginary number i
49: Synopsis:
50: #include <petscsys.h>
51: PetscComplex PETSC_i;
53: Level: beginner
55: Note:
56: Complex numbers are automatically available if PETSc located a working complex implementation
58: .seealso: `PetscRealPart()`, `PetscImaginaryPart()`, `PetscRealPartComplex()`, `PetscImaginaryPartComplex()`
59: M*/
60: PetscComplex PETSC_i;
61: MPI_Datatype MPIU___COMPLEX128 = 0;
62: #endif /* PETSC_HAVE_COMPLEX */
63: #if defined(PETSC_HAVE_REAL___FLOAT128)
64: MPI_Datatype MPIU___FLOAT128 = 0;
65: #endif
66: #if defined(PETSC_HAVE_REAL___FP16)
67: MPI_Datatype MPIU___FP16 = 0;
68: #endif
69: MPI_Datatype MPIU_2SCALAR = 0;
70: MPI_Datatype MPIU_REAL_INT = 0;
71: MPI_Datatype MPIU_SCALAR_INT = 0;
72: #if defined(PETSC_USE_64BIT_INDICES)
73: MPI_Datatype MPIU_2INT = 0;
74: #endif
75: MPI_Datatype MPI_4INT = 0;
76: MPI_Datatype MPIU_4INT = 0;
77: MPI_Datatype MPIU_BOOL;
78: MPI_Datatype MPIU_ENUM;
79: MPI_Datatype MPIU_FORTRANADDR;
80: MPI_Datatype MPIU_SIZE_T;
82: /*
83: Function that is called to display all error messages
84: */
85: PetscErrorCode (*PetscErrorPrintf)(const char[], ...) = PetscErrorPrintfDefault;
86: PetscErrorCode (*PetscHelpPrintf)(MPI_Comm, const char[], ...) = PetscHelpPrintfDefault;
87: PetscErrorCode (*PetscVFPrintf)(FILE *, const char[], va_list) = PetscVFPrintfDefault;
89: /*
90: Optional file where all PETSc output from various prints is saved
91: */
92: PETSC_INTERN FILE *petsc_history;
93: FILE *petsc_history = NULL;
95: PetscErrorCode PetscOpenHistoryFile(const char filename[], FILE **fd)
96: {
97: PetscMPIInt rank, size;
98: char pfile[PETSC_MAX_PATH_LEN], pname[PETSC_MAX_PATH_LEN], fname[PETSC_MAX_PATH_LEN], date[64];
99: char version[256];
101: PetscFunctionBegin;
102: PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
103: if (rank == 0) {
104: char arch[10];
106: PetscCall(PetscGetArchType(arch, 10));
107: PetscCall(PetscGetDate(date, 64));
108: PetscCall(PetscGetVersion(version, 256));
109: PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
110: if (filename) {
111: PetscCall(PetscFixFilename(filename, fname));
112: } else {
113: PetscCall(PetscGetHomeDirectory(pfile, sizeof(pfile)));
114: PetscCall(PetscStrlcat(pfile, "/.petschistory", sizeof(pfile)));
115: PetscCall(PetscFixFilename(pfile, fname));
116: }
118: *fd = fopen(fname, "a");
119: PetscCheck(fd, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Cannot open file: %s", fname);
121: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "----------------------------------------\n"));
122: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "%s %s\n", version, date));
123: PetscCall(PetscGetProgramName(pname, sizeof(pname)));
124: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "%s on a %s, %d proc. with options:\n", pname, arch, size));
125: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "----------------------------------------\n"));
127: PetscCall(PetscFFlush(*fd));
128: }
129: PetscFunctionReturn(PETSC_SUCCESS);
130: }
132: PETSC_INTERN PetscErrorCode PetscCloseHistoryFile(FILE **fd)
133: {
134: PetscMPIInt rank;
136: PetscFunctionBegin;
137: PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
138: if (rank == 0) {
139: char date[64];
140: int err;
142: PetscCall(PetscGetDate(date, sizeof(date)));
143: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "----------------------------------------\n"));
144: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "Finished at %s\n", date));
145: PetscCall(PetscFPrintf(PETSC_COMM_SELF, *fd, "----------------------------------------\n"));
146: PetscCall(PetscFFlush(*fd));
147: err = fclose(*fd);
148: PetscCheck(!err, PETSC_COMM_SELF, PETSC_ERR_SYS, "fclose() failed on file");
149: }
150: PetscFunctionReturn(PETSC_SUCCESS);
151: }
153: /*
154: This is ugly and probably belongs somewhere else, but I want to
155: be able to put a true MPI abort error handler with command line args.
157: This is so MPI errors in the debugger will leave all the stack
158: frames. The default MP_Abort() cleans up and exits thus providing no useful information
159: in the debugger hence we call abort() instead of MPI_Abort().
160: */
162: void Petsc_MPI_AbortOnError(PETSC_UNUSED MPI_Comm *comm, PetscMPIInt *flag, ...)
163: {
164: PetscFunctionBegin;
165: PetscCallContinue((*PetscErrorPrintf)("MPI error %d\n", *flag));
166: abort();
167: }
169: void Petsc_MPI_DebuggerOnError(MPI_Comm *comm, PetscMPIInt *flag, ...)
170: {
171: PetscFunctionBegin;
172: PetscCallContinue((*PetscErrorPrintf)("MPI error %d\n", *flag));
173: if (PetscAttachDebugger()) PETSCABORT(*comm, (PetscErrorCode)*flag); /* hopeless so get out */
174: }
176: /*@C
177: PetscEnd - Calls `PetscFinalize()` and then ends the program. This is useful if one
178: wishes a clean exit somewhere deep in the program.
180: Collective on `PETSC_COMM_WORLD`
182: Options Database Keys are the same as for `PetscFinalize()`
184: Level: advanced
186: Note:
187: See `PetscInitialize()` for more general runtime options.
189: .seealso: `PetscInitialize()`, `PetscOptionsView()`, `PetscMallocDump()`, `PetscMPIDump()`, `PetscFinalize()`
190: @*/
191: PetscErrorCode PetscEnd(void)
192: {
193: PetscFunctionBegin;
194: PetscCall(PetscFinalize());
195: exit(0);
196: return PETSC_SUCCESS;
197: }
199: PetscBool PetscOptionsPublish = PETSC_FALSE;
200: PETSC_INTERN PetscErrorCode PetscSetUseHBWMalloc_Private(void);
201: PETSC_INTERN PetscBool petscsetmallocvisited;
202: static char emacsmachinename[256];
204: PetscErrorCode (*PetscExternalVersionFunction)(MPI_Comm) = NULL;
205: PetscErrorCode (*PetscExternalHelpFunction)(MPI_Comm) = NULL;
207: #if PetscDefined(USE_LOG)
208: #include <petscviewer.h>
209: #endif
211: /*@C
212: PetscSetHelpVersionFunctions - Sets functions that print help and version information
213: before the PETSc help and version information is printed. Must call BEFORE `PetscInitialize()`.
214: This routine enables a "higher-level" package that uses PETSc to print its messages first and control
215: how the PETSc help messages are printed.
217: Input Parameters:
218: + help - the help function (may be `NULL`)
219: - version - the version function (may be `NULL`)
221: Level: developer
223: .seealso: `PetscInitialize()`
224: @*/
225: PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*help)(MPI_Comm), PetscErrorCode (*version)(MPI_Comm))
226: {
227: PetscFunctionBegin;
228: PetscExternalHelpFunction = help;
229: PetscExternalVersionFunction = version;
230: PetscFunctionReturn(PETSC_SUCCESS);
231: }
233: #if defined(PETSC_USE_LOG)
234: PETSC_INTERN PetscBool PetscObjectsLog;
235: #endif
237: PETSC_INTERN PetscErrorCode PetscOptionsCheckInitial_Private(const char help[])
238: {
239: char string[64];
240: MPI_Comm comm = PETSC_COMM_WORLD;
241: PetscBool flg1 = PETSC_FALSE, flg2 = PETSC_FALSE, flag, hasHelp;
242: PetscBool checkstack = PETSC_FALSE;
243: PetscReal si;
244: PetscInt intensity;
245: int i;
246: PetscMPIInt rank;
247: char version[256];
248: #if defined(PETSC_USE_LOG)
249: char mname[PETSC_MAX_PATH_LEN];
250: PetscViewerFormat format;
251: PetscBool flg4 = PETSC_FALSE;
252: #endif
254: PetscFunctionBegin;
255: PetscCallMPI(MPI_Comm_rank(comm, &rank));
257: if (PetscDefined(USE_DEBUG) && !PetscDefined(HAVE_THREADSAFETY)) checkstack = PETSC_TRUE;
258: PetscCall(PetscOptionsGetBool(NULL, NULL, "-checkstack", &checkstack, NULL));
259: PetscCall(PetscStackSetCheck(checkstack));
261: PetscCall(PetscOptionsGetBool(NULL, NULL, "-checkfunctionlist", &PetscPrintFunctionList, NULL));
263: #if !defined(PETSC_HAVE_THREADSAFETY)
264: if (!(PETSC_RUNNING_ON_VALGRIND)) {
265: /*
266: Setup the memory management; support for tracing malloc() usage
267: */
268: PetscBool mdebug = PETSC_FALSE, eachcall = PETSC_FALSE, initializenan = PETSC_FALSE, mlog = PETSC_FALSE;
269: PetscBool flg3 = PETSC_FALSE;
271: if (PetscDefined(USE_DEBUG)) {
272: mdebug = PETSC_TRUE;
273: initializenan = PETSC_TRUE;
274: PetscCall(PetscOptionsHasName(NULL, NULL, "-malloc_test", &flg1));
275: } else {
276: /* don't warn about unused option */
277: PetscCall(PetscOptionsHasName(NULL, NULL, "-malloc_test", &flg1));
278: flg1 = PETSC_FALSE;
279: }
280: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc_debug", &flg2, &flg3));
281: if (flg1 || flg2) {
282: mdebug = PETSC_TRUE;
283: eachcall = PETSC_TRUE;
284: initializenan = PETSC_TRUE;
285: } else if (flg3 && !flg2) {
286: mdebug = PETSC_FALSE;
287: eachcall = PETSC_FALSE;
288: initializenan = PETSC_FALSE;
289: }
291: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc_requested_size", &flg1, &flg2));
292: if (flg2) PetscCall(PetscMallocLogRequestedSizeSet(flg1));
294: PetscCall(PetscOptionsHasName(NULL, NULL, "-malloc_view", &mlog));
295: if (mlog) mdebug = PETSC_TRUE;
296: /* the next line is deprecated */
297: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc", &mdebug, NULL));
298: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc_dump", &mdebug, NULL));
299: PetscCall(PetscOptionsGetBool(NULL, NULL, "-log_view_memory", &mdebug, NULL));
300: if (mdebug) PetscCall(PetscMallocSetDebug(eachcall, initializenan));
301: if (mlog) {
302: PetscReal logthreshold = 0;
303: PetscCall(PetscOptionsGetReal(NULL, NULL, "-malloc_view_threshold", &logthreshold, NULL));
304: PetscCall(PetscMallocViewSet(logthreshold));
305: }
306: #if defined(PETSC_USE_LOG)
307: PetscCall(PetscOptionsGetBool(NULL, NULL, "-log_view_memory", &PetscLogMemory, NULL));
308: #endif
309: }
311: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc_coalesce", &flg1, &flg2));
312: if (flg2) PetscCall(PetscMallocSetCoalesce(flg1));
313: flg1 = PETSC_FALSE;
314: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc_hbw", &flg1, NULL));
315: /* ignore this option if malloc is already set */
316: if (flg1 && !petscsetmallocvisited) PetscCall(PetscSetUseHBWMalloc_Private());
318: flg1 = PETSC_FALSE;
319: PetscCall(PetscOptionsGetBool(NULL, NULL, "-malloc_info", &flg1, NULL));
320: if (!flg1) {
321: flg1 = PETSC_FALSE;
322: PetscCall(PetscOptionsGetBool(NULL, NULL, "-memory_view", &flg1, NULL));
323: }
324: if (flg1) PetscCall(PetscMemorySetGetMaximumUsage());
325: #endif
327: #if defined(PETSC_USE_LOG)
328: PetscCall(PetscOptionsHasName(NULL, NULL, "-objects_dump", &PetscObjectsLog));
329: #endif
331: /*
332: Set the display variable for graphics
333: */
334: PetscCall(PetscSetDisplay());
336: /*
337: Print main application help message
338: */
339: PetscCall(PetscOptionsHasHelp(NULL, &hasHelp));
340: if (help && hasHelp) {
341: PetscCall(PetscPrintf(comm, "%s", help));
342: PetscCall(PetscPrintf(comm, "----------------------------------------\n"));
343: }
345: /*
346: Print the PETSc version information
347: */
348: PetscCall(PetscOptionsHasName(NULL, NULL, "-version", &flg1));
349: if (flg1 || hasHelp) {
350: /*
351: Print "higher-level" package version message
352: */
353: if (PetscExternalVersionFunction) PetscCall((*PetscExternalVersionFunction)(comm));
355: PetscCall(PetscGetVersion(version, 256));
356: PetscCall((*PetscHelpPrintf)(comm, "%s\n", version));
357: PetscCall((*PetscHelpPrintf)(comm, "%s", PETSC_AUTHOR_INFO));
358: PetscCall((*PetscHelpPrintf)(comm, "See https://petsc.org/release/changes for recent updates.\n"));
359: PetscCall((*PetscHelpPrintf)(comm, "See https://petsc.org/release/faq for problems.\n"));
360: PetscCall((*PetscHelpPrintf)(comm, "See https://petsc.org/release/manualpages for help. \n"));
361: PetscCall((*PetscHelpPrintf)(comm, "Libraries linked from %s\n", PETSC_LIB_DIR));
362: PetscCall((*PetscHelpPrintf)(comm, "----------------------------------------\n"));
363: }
365: /*
366: Print "higher-level" package help message
367: */
368: if (hasHelp) {
369: PetscBool hasHelpIntro;
371: if (PetscExternalHelpFunction) PetscCall((*PetscExternalHelpFunction)(comm));
372: PetscCall(PetscOptionsHasHelpIntro_Internal(NULL, &hasHelpIntro));
373: if (hasHelpIntro) {
374: PetscCall(PetscOptionsDestroyDefault());
375: PetscCall(PetscFreeMPIResources());
376: PetscCallMPI(MPI_Finalize());
377: exit(0);
378: }
379: }
381: /*
382: Setup the error handling
383: */
384: flg1 = PETSC_FALSE;
385: PetscCall(PetscOptionsGetBool(NULL, NULL, "-on_error_abort", &flg1, NULL));
386: if (flg1) {
387: PetscCallMPI(MPI_Comm_set_errhandler(comm, MPI_ERRORS_ARE_FATAL));
388: PetscCall(PetscPushErrorHandler(PetscAbortErrorHandler, NULL));
389: }
390: flg1 = PETSC_FALSE;
391: PetscCall(PetscOptionsGetBool(NULL, NULL, "-on_error_mpiabort", &flg1, NULL));
392: if (flg1) PetscCall(PetscPushErrorHandler(PetscMPIAbortErrorHandler, NULL));
393: flg1 = PETSC_FALSE;
394: PetscCall(PetscOptionsGetBool(NULL, NULL, "-mpi_return_on_error", &flg1, NULL));
395: if (flg1) PetscCallMPI(MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN));
396: flg1 = PETSC_FALSE;
397: PetscCall(PetscOptionsGetBool(NULL, NULL, "-no_signal_handler", &flg1, NULL));
398: if (!flg1) PetscCall(PetscPushSignalHandler(PetscSignalHandlerDefault, (void *)0));
400: /*
401: Setup debugger information
402: */
403: PetscCall(PetscSetDefaultDebugger());
404: PetscCall(PetscOptionsGetString(NULL, NULL, "-on_error_attach_debugger", string, sizeof(string), &flg1));
405: if (flg1) {
406: MPI_Errhandler err_handler;
408: PetscCall(PetscSetDebuggerFromString(string));
409: PetscCallMPI(MPI_Comm_create_errhandler(Petsc_MPI_DebuggerOnError, &err_handler));
410: PetscCallMPI(MPI_Comm_set_errhandler(comm, err_handler));
411: PetscCall(PetscPushErrorHandler(PetscAttachDebuggerErrorHandler, NULL));
412: }
413: PetscCall(PetscOptionsGetString(NULL, NULL, "-debug_terminal", string, sizeof(string), &flg1));
414: if (flg1) PetscCall(PetscSetDebugTerminal(string));
415: PetscCall(PetscOptionsGetString(NULL, NULL, "-start_in_debugger", string, sizeof(string), &flg1));
416: PetscCall(PetscOptionsGetString(NULL, NULL, "-stop_for_debugger", string, sizeof(string), &flg2));
417: if (flg1 || flg2) {
418: PetscMPIInt size;
419: PetscInt lsize, *ranks;
420: MPI_Errhandler err_handler;
421: /*
422: we have to make sure that all processors have opened
423: connections to all other processors, otherwise once the
424: debugger has stated it is likely to receive a SIGUSR1
425: and kill the program.
426: */
427: PetscCallMPI(MPI_Comm_size(comm, &size));
428: if (size > 2) {
429: PetscMPIInt dummy = 0;
430: MPI_Status status;
431: for (i = 0; i < size; i++) {
432: if (rank != i) PetscCallMPI(MPI_Send(&dummy, 1, MPI_INT, i, 109, comm));
433: }
434: for (i = 0; i < size; i++) {
435: if (rank != i) PetscCallMPI(MPI_Recv(&dummy, 1, MPI_INT, i, 109, comm, &status));
436: }
437: }
438: /* check if this processor node should be in debugger */
439: PetscCall(PetscMalloc1(size, &ranks));
440: lsize = size;
441: /* Deprecated in 3.14 */
442: PetscCall(PetscOptionsGetIntArray(NULL, NULL, "-debugger_nodes", ranks, &lsize, &flag));
443: if (flag) {
444: const char *const quietopt = "-options_suppress_deprecated_warnings";
445: char msg[4096];
446: PetscBool quiet = PETSC_FALSE;
448: PetscCall(PetscOptionsGetBool(NULL, NULL, quietopt, &quiet, NULL));
449: if (!quiet) {
450: PetscCall(PetscStrncpy(msg, "** PETSc DEPRECATION WARNING ** : the option ", sizeof(msg)));
451: PetscCall(PetscStrlcat(msg, "-debugger_nodes", sizeof(msg)));
452: PetscCall(PetscStrlcat(msg, " is deprecated as of version ", sizeof(msg)));
453: PetscCall(PetscStrlcat(msg, "3.14", sizeof(msg)));
454: PetscCall(PetscStrlcat(msg, " and will be removed in a future release.", sizeof(msg)));
455: PetscCall(PetscStrlcat(msg, " Please use the option ", sizeof(msg)));
456: PetscCall(PetscStrlcat(msg, "-debugger_ranks", sizeof(msg)));
457: PetscCall(PetscStrlcat(msg, " instead.", sizeof(msg)));
458: PetscCall(PetscStrlcat(msg, " (Silence this warning with ", sizeof(msg)));
459: PetscCall(PetscStrlcat(msg, quietopt, sizeof(msg)));
460: PetscCall(PetscStrlcat(msg, ")\n", sizeof(msg)));
461: PetscCall(PetscPrintf(comm, "%s", msg));
462: }
463: } else {
464: lsize = size;
465: PetscCall(PetscOptionsGetIntArray(NULL, NULL, "-debugger_ranks", ranks, &lsize, &flag));
466: }
467: if (flag) {
468: for (i = 0; i < lsize; i++) {
469: if (ranks[i] == rank) {
470: flag = PETSC_FALSE;
471: break;
472: }
473: }
474: }
475: if (!flag) {
476: PetscCall(PetscSetDebuggerFromString(string));
477: PetscCall(PetscPushErrorHandler(PetscAbortErrorHandler, NULL));
478: if (flg1) {
479: PetscCall(PetscAttachDebugger());
480: } else {
481: PetscCall(PetscStopForDebugger());
482: }
483: PetscCallMPI(MPI_Comm_create_errhandler(Petsc_MPI_AbortOnError, &err_handler));
484: PetscCallMPI(MPI_Comm_set_errhandler(comm, err_handler));
485: } else {
486: PetscCall(PetscWaitOnError());
487: }
488: PetscCall(PetscFree(ranks));
489: }
491: PetscCall(PetscOptionsGetString(NULL, NULL, "-on_error_emacs", emacsmachinename, sizeof(emacsmachinename), &flg1));
492: if (flg1 && rank == 0) PetscCall(PetscPushErrorHandler(PetscEmacsClientErrorHandler, emacsmachinename));
494: /*
495: Setup profiling and logging
496: */
497: #if defined(PETSC_USE_INFO)
498: {
499: PetscCall(PetscInfoSetFromOptions(NULL));
500: }
501: #endif
502: PetscCall(PetscDetermineInitialFPTrap());
503: flg1 = PETSC_FALSE;
504: PetscCall(PetscOptionsGetBool(NULL, NULL, "-fp_trap", &flg1, &flag));
505: if (flag) PetscCall(PetscSetFPTrap(flg1 ? PETSC_FP_TRAP_ON : PETSC_FP_TRAP_OFF));
506: PetscCall(PetscOptionsGetInt(NULL, NULL, "-check_pointer_intensity", &intensity, &flag));
507: if (flag) PetscCall(PetscCheckPointerSetIntensity(intensity));
508: #if defined(PETSC_USE_LOG)
509: mname[0] = 0;
510: PetscCall(PetscOptionsGetString(NULL, NULL, "-history", mname, sizeof(mname), &flg1));
511: if (flg1) {
512: if (mname[0]) {
513: PetscCall(PetscOpenHistoryFile(mname, &petsc_history));
514: } else {
515: PetscCall(PetscOpenHistoryFile(NULL, &petsc_history));
516: }
517: }
519: PetscCall(PetscOptionsGetBool(NULL, NULL, "-log_sync", &PetscLogSyncOn, NULL));
521: PetscBool flg3 = PETSC_FALSE;
522: #if defined(PETSC_HAVE_MPE)
523: flg1 = PETSC_FALSE;
524: PetscCall(PetscOptionsHasName(NULL, NULL, "-log_mpe", &flg1));
525: if (flg1) PetscCall(PetscLogMPEBegin());
526: #endif
527: flg1 = PETSC_FALSE;
528: PetscCall(PetscOptionsGetBool(NULL, NULL, "-log_all", &flg1, NULL));
529: PetscCall(PetscOptionsHasName(NULL, NULL, "-log_summary", &flg3));
530: if (flg1) PetscCall(PetscLogAllBegin());
531: else if (flg3) PetscCall(PetscLogDefaultBegin());
533: PetscCall(PetscOptionsGetString(NULL, NULL, "-log_trace", mname, sizeof(mname), &flg1));
534: if (flg1) {
535: char name[PETSC_MAX_PATH_LEN], fname[PETSC_MAX_PATH_LEN];
536: FILE *file;
537: if (mname[0]) {
538: PetscCall(PetscSNPrintf(name, PETSC_MAX_PATH_LEN, "%s.%d", mname, rank));
539: PetscCall(PetscFixFilename(name, fname));
540: file = fopen(fname, "w");
541: PetscCheck(file, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "Unable to open trace file: %s", fname);
542: } else file = PETSC_STDOUT;
543: PetscCall(PetscLogTraceBegin(file));
544: }
546: PetscCall(PetscOptionsGetViewer(comm, NULL, NULL, "-log_view", NULL, &format, &flg4));
547: if (flg4) {
548: if (format == PETSC_VIEWER_ASCII_XML || format == PETSC_VIEWER_ASCII_FLAMEGRAPH) {
549: PetscCall(PetscLogNestedBegin());
550: } else {
551: PetscCall(PetscLogDefaultBegin());
552: }
553: }
554: if (flg4 && (format == PETSC_VIEWER_ASCII_XML || format == PETSC_VIEWER_ASCII_FLAMEGRAPH)) {
555: PetscReal threshold = PetscRealConstant(0.01);
556: PetscCall(PetscOptionsGetReal(NULL, NULL, "-log_threshold", &threshold, &flg1));
557: if (flg1) PetscCall(PetscLogSetThreshold((PetscLogDouble)threshold, NULL));
558: }
559: #endif
561: PetscCall(PetscOptionsGetBool(NULL, NULL, "-saws_options", &PetscOptionsPublish, NULL));
562: PetscCall(PetscOptionsGetBool(NULL, NULL, "-use_gpu_aware_mpi", &use_gpu_aware_mpi, &flg1));
563: if (!flg1) PetscCall(PetscOptionsGetBool(NULL, NULL, "-sf_use_gpu_aware_mpi", &use_gpu_aware_mpi, &flg1)); // an alias option
565: /*
566: Print basic help message
567: */
568: if (hasHelp) {
569: PetscCall((*PetscHelpPrintf)(comm, "Options for all PETSc programs:\n"));
570: PetscCall((*PetscHelpPrintf)(comm, " -version: prints PETSc version\n"));
571: PetscCall((*PetscHelpPrintf)(comm, " -help intro: prints example description and PETSc version, and exits\n"));
572: PetscCall((*PetscHelpPrintf)(comm, " -help: prints example description, PETSc version, and available options for used routines\n"));
573: PetscCall((*PetscHelpPrintf)(comm, " -on_error_abort: cause an abort when an error is detected. Useful \n "));
574: PetscCall((*PetscHelpPrintf)(comm, " only when run in the debugger\n"));
575: PetscCall((*PetscHelpPrintf)(comm, " -on_error_attach_debugger [gdb,dbx,xxgdb,ups,noxterm]\n"));
576: PetscCall((*PetscHelpPrintf)(comm, " start the debugger in new xterm\n"));
577: PetscCall((*PetscHelpPrintf)(comm, " unless noxterm is given\n"));
578: PetscCall((*PetscHelpPrintf)(comm, " -start_in_debugger [gdb,dbx,xxgdb,ups,noxterm]\n"));
579: PetscCall((*PetscHelpPrintf)(comm, " start all processes in the debugger\n"));
580: PetscCall((*PetscHelpPrintf)(comm, " -on_error_emacs <machinename>\n"));
581: PetscCall((*PetscHelpPrintf)(comm, " emacs jumps to error file\n"));
582: PetscCall((*PetscHelpPrintf)(comm, " -debugger_ranks [n1,n2,..] Ranks to start in debugger\n"));
583: PetscCall((*PetscHelpPrintf)(comm, " -debugger_pause [m] : delay (in seconds) to attach debugger\n"));
584: PetscCall((*PetscHelpPrintf)(comm, " -stop_for_debugger : prints message on how to attach debugger manually\n"));
585: PetscCall((*PetscHelpPrintf)(comm, " waits the delay for you to attach\n"));
586: PetscCall((*PetscHelpPrintf)(comm, " -display display: Location where X window graphics and debuggers are displayed\n"));
587: PetscCall((*PetscHelpPrintf)(comm, " -no_signal_handler: do not trap error signals\n"));
588: PetscCall((*PetscHelpPrintf)(comm, " -mpi_return_on_error: MPI returns error code, rather than abort on internal error\n"));
589: PetscCall((*PetscHelpPrintf)(comm, " -fp_trap: stop on floating point exceptions\n"));
590: PetscCall((*PetscHelpPrintf)(comm, " note on IBM RS6000 this slows run greatly\n"));
591: PetscCall((*PetscHelpPrintf)(comm, " -malloc_dump <optional filename>: dump list of unfreed memory at conclusion\n"));
592: PetscCall((*PetscHelpPrintf)(comm, " -malloc: use PETSc error checking malloc (deprecated, use -malloc_debug)\n"));
593: PetscCall((*PetscHelpPrintf)(comm, " -malloc no: don't use PETSc error checking malloc (deprecated, use -malloc_debug no)\n"));
594: PetscCall((*PetscHelpPrintf)(comm, " -malloc_info: prints total memory usage\n"));
595: PetscCall((*PetscHelpPrintf)(comm, " -malloc_view <optional filename>: keeps log of all memory allocations, displays in PetscFinalize()\n"));
596: PetscCall((*PetscHelpPrintf)(comm, " -malloc_debug <true or false>: enables or disables extended checking for memory corruption\n"));
597: PetscCall((*PetscHelpPrintf)(comm, " -options_view: dump list of options inputted\n"));
598: PetscCall((*PetscHelpPrintf)(comm, " -options_left: dump list of unused options\n"));
599: PetscCall((*PetscHelpPrintf)(comm, " -options_left no: don't dump list of unused options\n"));
600: PetscCall((*PetscHelpPrintf)(comm, " -tmp tmpdir: alternative /tmp directory\n"));
601: PetscCall((*PetscHelpPrintf)(comm, " -shared_tmp: tmp directory is shared by all processors\n"));
602: PetscCall((*PetscHelpPrintf)(comm, " -not_shared_tmp: each processor has separate tmp directory\n"));
603: PetscCall((*PetscHelpPrintf)(comm, " -memory_view: print memory usage at end of run\n"));
604: #if defined(PETSC_USE_LOG)
605: PetscCall((*PetscHelpPrintf)(comm, " -get_total_flops: total flops over all processors\n"));
606: PetscCall((*PetscHelpPrintf)(comm, " -log_view [:filename:[format]]: logging objects and events\n"));
607: PetscCall((*PetscHelpPrintf)(comm, " -log_trace [filename]: prints trace of all PETSc calls\n"));
608: PetscCall((*PetscHelpPrintf)(comm, " -log_exclude <list,of,classnames>: exclude given classes from logging\n"));
609: #if defined(PETSC_HAVE_DEVICE)
610: PetscCall((*PetscHelpPrintf)(comm, " -log_view_gpu_time: log the GPU time for each and event\n"));
611: #endif
612: #if defined(PETSC_HAVE_MPE)
613: PetscCall((*PetscHelpPrintf)(comm, " -log_mpe: Also create logfile viewable through Jumpshot\n"));
614: #endif
615: #endif
616: #if defined(PETSC_USE_INFO)
617: PetscCall((*PetscHelpPrintf)(comm, " -info [filename][:[~]<list,of,classnames>[:[~]self]]: print verbose information\n"));
618: #endif
619: PetscCall((*PetscHelpPrintf)(comm, " -options_file <file>: reads options from file\n"));
620: PetscCall((*PetscHelpPrintf)(comm, " -options_monitor: monitor options to standard output, including that set previously e.g. in option files\n"));
621: PetscCall((*PetscHelpPrintf)(comm, " -options_monitor_cancel: cancels all hardwired option monitors\n"));
622: PetscCall((*PetscHelpPrintf)(comm, " -petsc_sleep n: sleeps n seconds before running program\n"));
623: }
625: #if defined(PETSC_HAVE_POPEN)
626: {
627: char machine[128];
628: PetscCall(PetscOptionsGetString(NULL, NULL, "-popen_machine", machine, sizeof(machine), &flg1));
629: if (flg1) PetscCall(PetscPOpenSetMachine(machine));
630: }
631: #endif
633: PetscCall(PetscOptionsGetReal(NULL, NULL, "-petsc_sleep", &si, &flg1));
634: if (flg1) PetscCall(PetscSleep(si));
635: PetscFunctionReturn(PETSC_SUCCESS);
636: }