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