1e5c89e4eSSatish Balay /* 2e5c89e4eSSatish Balay 3e5c89e4eSSatish Balay This file defines part of the initialization of PETSc 4e5c89e4eSSatish Balay 5540e20f2SPierre Jolivet This file uses regular malloc and free because it cannot be known 6e5c89e4eSSatish Balay what malloc is being used until it has already processed the input. 7e5c89e4eSSatish Balay */ 8ef386f4bSSatish Balay 9ef386f4bSSatish Balay #include <petscsys.h> /*I "petscsys.h" I*/ 10f67a399dSBarry Smith #include <petsc/private/petscimpl.h> 11022afb99SBarry Smith #include <petscvalgrind.h> 12665c2dedSJed Brown #include <petscviewer.h> 13fdc842d1SBarry Smith #if defined(PETSC_USE_LOG) 14fdc842d1SBarry Smith PETSC_INTERN PetscErrorCode PetscLogInitialize(void); 15fdc842d1SBarry Smith #endif 16ef386f4bSSatish Balay 17ba61063dSBarry Smith #if defined(PETSC_HAVE_SYS_SYSINFO_H) 1851d315f7SKerry Stevens #include <sys/sysinfo.h> 19ba61063dSBarry Smith #endif 20121deb67SSatish Balay #if defined(PETSC_HAVE_UNISTD_H) 2151d315f7SKerry Stevens #include <unistd.h> 22121deb67SSatish Balay #endif 23*05035670SJunchao Zhang 24d9b72601SDominic Meiser #if defined(PETSC_HAVE_CUDA) 25d9b72601SDominic Meiser #include <cuda_runtime.h> 267fd2f626SJose E. Roman #include <petsccublas.h> 27*05035670SJunchao Zhang #endif 28*05035670SJunchao Zhang 29*05035670SJunchao Zhang #if defined(PETSC_HAVE_HIP) 30*05035670SJunchao Zhang #include <hip/hip_runtime.h> 31*05035670SJunchao Zhang #endif 32*05035670SJunchao Zhang 33*05035670SJunchao Zhang #if defined(PETSC_HAVE_DEVICE) 34c2a741eeSJunchao Zhang #if defined(PETSC_HAVE_OMPI_MAJOR_VERSION) 35c2a741eeSJunchao Zhang #include "mpi-ext.h" /* Needed for OpenMPI CUDA-aware check */ 36c2a741eeSJunchao Zhang #endif 37d9b72601SDominic Meiser #endif 38555d055bSBarry Smith 39f0a7718cSKarl Rupp #if defined(PETSC_HAVE_VIENNACL) 40f0a7718cSKarl Rupp PETSC_EXTERN PetscErrorCode PetscViennaCLInit(); 41f0a7718cSKarl Rupp #endif 42f0a7718cSKarl Rupp 43*05035670SJunchao Zhang 44e5c89e4eSSatish Balay /* ------------------------Nasty global variables -------------------------------*/ 45e5c89e4eSSatish Balay /* 46e5c89e4eSSatish Balay Indicates if PETSc started up MPI, or it was 47e5c89e4eSSatish Balay already started before PETSc was initialized. 48e5c89e4eSSatish Balay */ 490cbf60d0SJose E. Roman PetscBool PetscBeganMPI = PETSC_FALSE; 508ad20175SVaclav Hapla PetscBool PetscErrorHandlingInitialized = PETSC_FALSE; 510cbf60d0SJose E. Roman PetscBool PetscInitializeCalled = PETSC_FALSE; 520cbf60d0SJose E. Roman PetscBool PetscFinalizeCalled = PETSC_FALSE; 53d6f2c3cbSBarry Smith 547087cfbeSBarry Smith PetscMPIInt PetscGlobalRank = -1; 557087cfbeSBarry Smith PetscMPIInt PetscGlobalSize = -1; 56ba61063dSBarry Smith 57c2a741eeSJunchao Zhang PetscBool use_gpu_aware_mpi = PETSC_TRUE; 58c2a741eeSJunchao Zhang 5950f81f78SJed Brown #if defined(PETSC_HAVE_COMPLEX) 60e5c89e4eSSatish Balay #if defined(PETSC_COMPLEX_INSTANTIATE) 61e5c89e4eSSatish Balay template <> class std::complex<double>; /* instantiate complex template class */ 62e5c89e4eSSatish Balay #endif 632c876bd9SBarry Smith #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) 64500d8756SSatish Balay MPI_Datatype MPIU_C_DOUBLE_COMPLEX; 65500d8756SSatish Balay MPI_Datatype MPIU_C_COMPLEX; 662c876bd9SBarry Smith #endif 678619c96cSJed Brown 688619c96cSJed Brown /*MC 698619c96cSJed Brown PETSC_i - the imaginary number i 708619c96cSJed Brown 718619c96cSJed Brown Synopsis: 728619c96cSJed Brown #include <petscsys.h> 738619c96cSJed Brown PetscComplex PETSC_i; 748619c96cSJed Brown 758619c96cSJed Brown Level: beginner 768619c96cSJed Brown 778619c96cSJed Brown Note: 788cd53115SBarry Smith Complex numbers are automatically available if PETSc located a working complex implementation 798619c96cSJed Brown 808619c96cSJed Brown .seealso: PetscRealPart(), PetscImaginaryPart(), PetscRealPartComplex(), PetscImaginaryPartComplex() 818619c96cSJed Brown M*/ 8250f81f78SJed Brown PetscComplex PETSC_i; 83e5c89e4eSSatish Balay #endif 84ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) 85c90a1750SBarry Smith MPI_Datatype MPIU___FLOAT128 = 0; 867c2de775SJed Brown #if defined(PETSC_HAVE_COMPLEX) 878c764dc5SJose Roman MPI_Datatype MPIU___COMPLEX128 = 0; 888c764dc5SJose Roman #endif 89570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16) 90570b7f6dSBarry Smith MPI_Datatype MPIU___FP16 = 0; 91c90a1750SBarry Smith #endif 927087cfbeSBarry Smith MPI_Datatype MPIU_2SCALAR = 0; 930354ff80SSatish Balay #if defined(PETSC_USE_64BIT_INDICES) 947087cfbeSBarry Smith MPI_Datatype MPIU_2INT = 0; 9544041f26SJed Brown #endif 968ad47952SJed Brown MPI_Datatype MPIU_BOOL; 978ad47952SJed Brown MPI_Datatype MPIU_ENUM; 987cdaf61dSJed Brown MPI_Datatype MPIU_FORTRANADDR; 99e316c87fSJed Brown MPI_Datatype MPIU_SIZE_T; 10075567043SBarry Smith 101e5c89e4eSSatish Balay /* 102e5c89e4eSSatish Balay Function that is called to display all error messages 103e5c89e4eSSatish Balay */ 1047087cfbeSBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char [],...) = PetscErrorPrintfDefault; 1057087cfbeSBarry Smith PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char [],...) = PetscHelpPrintfDefault; 1067087cfbeSBarry Smith PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list) = PetscVFPrintfDefault; 107bab1f7e6SVictor Minden /* 1084cf1874eSKarl Rupp This is needed to turn on/off GPU synchronization 1098b5db460SBarry Smith */ 1104cf1874eSKarl Rupp PetscBool PetscViennaCLSynchronize = PETSC_FALSE; 111bab1f7e6SVictor Minden 112e5c89e4eSSatish Balay /* ------------------------------------------------------------------------------*/ 113e5c89e4eSSatish Balay /* 114e5c89e4eSSatish Balay Optional file where all PETSc output from various prints is saved 115e5c89e4eSSatish Balay */ 11695c0884eSLisandro Dalcin PETSC_INTERN FILE *petsc_history; 1170298fd71SBarry Smith FILE *petsc_history = NULL; 118e5c89e4eSSatish Balay 1197087cfbeSBarry Smith PetscErrorCode PetscOpenHistoryFile(const char filename[],FILE **fd) 120e5c89e4eSSatish Balay { 121e5c89e4eSSatish Balay PetscErrorCode ierr; 122e5c89e4eSSatish Balay PetscMPIInt rank,size; 123e5c89e4eSSatish Balay char pfile[PETSC_MAX_PATH_LEN],pname[PETSC_MAX_PATH_LEN],fname[PETSC_MAX_PATH_LEN],date[64]; 124e5c89e4eSSatish Balay char version[256]; 125e5c89e4eSSatish Balay 126e5c89e4eSSatish Balay PetscFunctionBegin; 127e5c89e4eSSatish Balay ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); 128e5c89e4eSSatish Balay if (!rank) { 129e5c89e4eSSatish Balay char arch[10]; 130f56c2debSBarry Smith int err; 131f56c2debSBarry Smith 132e5c89e4eSSatish Balay ierr = PetscGetArchType(arch,10);CHKERRQ(ierr); 133e5c89e4eSSatish Balay ierr = PetscGetDate(date,64);CHKERRQ(ierr); 134a523d312SBarry Smith ierr = PetscGetVersion(version,256);CHKERRQ(ierr); 135e5c89e4eSSatish Balay ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); 136e5c89e4eSSatish Balay if (filename) { 137e5c89e4eSSatish Balay ierr = PetscFixFilename(filename,fname);CHKERRQ(ierr); 138e5c89e4eSSatish Balay } else { 139589a23caSBarry Smith ierr = PetscGetHomeDirectory(pfile,sizeof(pfile));CHKERRQ(ierr); 140589a23caSBarry Smith ierr = PetscStrlcat(pfile,"/.petschistory",sizeof(pfile));CHKERRQ(ierr); 141e5c89e4eSSatish Balay ierr = PetscFixFilename(pfile,fname);CHKERRQ(ierr); 142e5c89e4eSSatish Balay } 143e5c89e4eSSatish Balay 144a297a907SKarl Rupp *fd = fopen(fname,"a"); 145a297a907SKarl Rupp if (!fd) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Cannot open file: %s",fname); 146a297a907SKarl Rupp 147c0bb3764SVaclav Hapla ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"----------------------------------------\n");CHKERRQ(ierr); 148e5c89e4eSSatish Balay ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"%s %s\n",version,date);CHKERRQ(ierr); 149589a23caSBarry Smith ierr = PetscGetProgramName(pname,sizeof(pname));CHKERRQ(ierr); 150e5c89e4eSSatish Balay ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"%s on a %s, %d proc. with options:\n",pname,arch,size);CHKERRQ(ierr); 151c0bb3764SVaclav Hapla ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"----------------------------------------\n");CHKERRQ(ierr); 152a297a907SKarl Rupp 153f56c2debSBarry Smith err = fflush(*fd); 154e32f2f54SBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 155e5c89e4eSSatish Balay } 156e5c89e4eSSatish Balay PetscFunctionReturn(0); 157e5c89e4eSSatish Balay } 158e5c89e4eSSatish Balay 15995c0884eSLisandro Dalcin PETSC_INTERN PetscErrorCode PetscCloseHistoryFile(FILE **fd) 160e5c89e4eSSatish Balay { 161e5c89e4eSSatish Balay PetscErrorCode ierr; 162e5c89e4eSSatish Balay PetscMPIInt rank; 163e5c89e4eSSatish Balay char date[64]; 164f56c2debSBarry Smith int err; 165e5c89e4eSSatish Balay 166e5c89e4eSSatish Balay PetscFunctionBegin; 167e5c89e4eSSatish Balay ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); 168e5c89e4eSSatish Balay if (!rank) { 169e5c89e4eSSatish Balay ierr = PetscGetDate(date,64);CHKERRQ(ierr); 170c0bb3764SVaclav Hapla ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"----------------------------------------\n");CHKERRQ(ierr); 171e5c89e4eSSatish Balay ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"Finished at %s\n",date);CHKERRQ(ierr); 172c0bb3764SVaclav Hapla ierr = PetscFPrintf(PETSC_COMM_SELF,*fd,"----------------------------------------\n");CHKERRQ(ierr); 173f56c2debSBarry Smith err = fflush(*fd); 174e32f2f54SBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fflush() failed on file"); 175f56c2debSBarry Smith err = fclose(*fd); 176e32f2f54SBarry Smith if (err) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"fclose() failed on file"); 177e5c89e4eSSatish Balay } 178e5c89e4eSSatish Balay PetscFunctionReturn(0); 179e5c89e4eSSatish Balay } 180e5c89e4eSSatish Balay 181e5c89e4eSSatish Balay /* ------------------------------------------------------------------------------*/ 182e5c89e4eSSatish Balay 183e5c89e4eSSatish Balay /* 184e5c89e4eSSatish Balay This is ugly and probably belongs somewhere else, but I want to 185e5c89e4eSSatish Balay be able to put a true MPI abort error handler with command line args. 186e5c89e4eSSatish Balay 187e5c89e4eSSatish Balay This is so MPI errors in the debugger will leave all the stack 1883c311c98SBarry Smith frames. The default MP_Abort() cleans up and exits thus providing no useful information 1893c311c98SBarry Smith in the debugger hence we call abort() instead of MPI_Abort(). 190e5c89e4eSSatish Balay */ 191e5c89e4eSSatish Balay 19233c7d699SBarry Smith void Petsc_MPI_AbortOnError(MPI_Comm *comm,PetscMPIInt *flag,...) 193e5c89e4eSSatish Balay { 194e5c89e4eSSatish Balay PetscFunctionBegin; 1953c311c98SBarry Smith (*PetscErrorPrintf)("MPI error %d\n",*flag); 196e5c89e4eSSatish Balay abort(); 197e5c89e4eSSatish Balay } 198e5c89e4eSSatish Balay 19933c7d699SBarry Smith void Petsc_MPI_DebuggerOnError(MPI_Comm *comm,PetscMPIInt *flag,...) 200e5c89e4eSSatish Balay { 201e5c89e4eSSatish Balay PetscErrorCode ierr; 202e5c89e4eSSatish Balay 203e5c89e4eSSatish Balay PetscFunctionBegin; 2043c311c98SBarry Smith (*PetscErrorPrintf)("MPI error %d\n",*flag); 205e5c89e4eSSatish Balay ierr = PetscAttachDebugger(); 20641e02c4dSJunchao Zhang if (ierr) PETSCABORT(*comm,*flag); /* hopeless so get out */ 207e5c89e4eSSatish Balay } 208e5c89e4eSSatish Balay 209e5c89e4eSSatish Balay /*@C 210e5c89e4eSSatish Balay PetscEnd - Calls PetscFinalize() and then ends the program. This is useful if one 211e5c89e4eSSatish Balay wishes a clean exit somewhere deep in the program. 212e5c89e4eSSatish Balay 213e5c89e4eSSatish Balay Collective on PETSC_COMM_WORLD 214e5c89e4eSSatish Balay 215e5c89e4eSSatish Balay Options Database Keys are the same as for PetscFinalize() 216e5c89e4eSSatish Balay 217e5c89e4eSSatish Balay Level: advanced 218e5c89e4eSSatish Balay 219e5c89e4eSSatish Balay Note: 220e5c89e4eSSatish Balay See PetscInitialize() for more general runtime options. 221e5c89e4eSSatish Balay 22288c29154SBarry Smith .seealso: PetscInitialize(), PetscOptionsView(), PetscMallocDump(), PetscMPIDump(), PetscFinalize() 223e5c89e4eSSatish Balay @*/ 2247087cfbeSBarry Smith PetscErrorCode PetscEnd(void) 225e5c89e4eSSatish Balay { 226e5c89e4eSSatish Balay PetscFunctionBegin; 227e5c89e4eSSatish Balay PetscFinalize(); 228e5c89e4eSSatish Balay exit(0); 229e5c89e4eSSatish Balay return 0; 230e5c89e4eSSatish Balay } 231e5c89e4eSSatish Balay 232ace3abfcSBarry Smith PetscBool PetscOptionsPublish = PETSC_FALSE; 23395c0884eSLisandro Dalcin PETSC_INTERN PetscErrorCode PetscSetUseHBWMalloc_Private(void); 23495c0884eSLisandro Dalcin PETSC_INTERN PetscBool petscsetmallocvisited; 235e5c89e4eSSatish Balay static char emacsmachinename[256]; 236e5c89e4eSSatish Balay 23702c9f0b5SLisandro Dalcin PetscErrorCode (*PetscExternalVersionFunction)(MPI_Comm) = NULL; 23802c9f0b5SLisandro Dalcin PetscErrorCode (*PetscExternalHelpFunction)(MPI_Comm) = NULL; 239e5c89e4eSSatish Balay 240e5c89e4eSSatish Balay /*@C 241e5c89e4eSSatish Balay PetscSetHelpVersionFunctions - Sets functions that print help and version information 242e5c89e4eSSatish Balay before the PETSc help and version information is printed. Must call BEFORE PetscInitialize(). 243e5c89e4eSSatish Balay This routine enables a "higher-level" package that uses PETSc to print its messages first. 244e5c89e4eSSatish Balay 245e5c89e4eSSatish Balay Input Parameter: 2460298fd71SBarry Smith + help - the help function (may be NULL) 2470298fd71SBarry Smith - version - the version function (may be NULL) 248e5c89e4eSSatish Balay 249e5c89e4eSSatish Balay Level: developer 250e5c89e4eSSatish Balay 251e5c89e4eSSatish Balay @*/ 2527087cfbeSBarry Smith PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*help)(MPI_Comm),PetscErrorCode (*version)(MPI_Comm)) 253e5c89e4eSSatish Balay { 254e5c89e4eSSatish Balay PetscFunctionBegin; 255e5c89e4eSSatish Balay PetscExternalHelpFunction = help; 256e5c89e4eSSatish Balay PetscExternalVersionFunction = version; 257e5c89e4eSSatish Balay PetscFunctionReturn(0); 258e5c89e4eSSatish Balay } 259e5c89e4eSSatish Balay 26005df10baSBarry Smith #if defined(PETSC_USE_LOG) 26195c0884eSLisandro Dalcin PETSC_INTERN PetscBool PetscObjectsLog; 26205df10baSBarry Smith #endif 26305df10baSBarry Smith 264e781f417SStefano Zampini void PetscMPI_Comm_eh(MPI_Comm *comm, PetscMPIInt *err, ...) 265e781f417SStefano Zampini { 266e781f417SStefano Zampini if (PetscUnlikely(*err)) { 267e781f417SStefano Zampini PetscMPIInt len; 268e781f417SStefano Zampini char errstring[MPI_MAX_ERROR_STRING]; 269e781f417SStefano Zampini 270e781f417SStefano Zampini MPI_Error_string(*err,errstring,&len); 271e781f417SStefano Zampini PetscError(MPI_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,PETSC_MPI_ERROR_CODE,PETSC_ERROR_INITIAL,"Internal error in MPI: %s",errstring); 272e781f417SStefano Zampini } 273e781f417SStefano Zampini return; 274e781f417SStefano Zampini } 275e781f417SStefano Zampini 276*05035670SJunchao Zhang /* CUPM stands for 'CUDA Programming Model', which is implemented in either CUDA or HIP. 277*05035670SJunchao Zhang Use the following macros to define CUDA/HIP initialization related vars/routines. 278*05035670SJunchao Zhang */ 279*05035670SJunchao Zhang #if defined(PETSC_HAVE_CUDA) 280*05035670SJunchao Zhang typedef cudaError_t cupmError_t; 281*05035670SJunchao Zhang typedef struct cudaDeviceProp cupmDeviceProp; 282*05035670SJunchao Zhang #define cupmGetDeviceCount(x) cudaGetDeviceCount(x) 283*05035670SJunchao Zhang #define cupmGetDevice(x) cudaGetDevice(x) 284*05035670SJunchao Zhang #define cupmSetDevice(x) cudaSetDevice(x) 285*05035670SJunchao Zhang #define cupmSetDeviceFlags(x) cudaSetDeviceFlags(x) 286*05035670SJunchao Zhang #define cupmGetDeviceProperties(x,y) cudaGetDeviceProperties(x,y) 287*05035670SJunchao Zhang #define cupmGetLastError() cudaGetLastError() 288*05035670SJunchao Zhang #define cupmDeviceMapHost cudaDeviceMapHost 289*05035670SJunchao Zhang #define cupmSuccess cudaSuccess 290*05035670SJunchao Zhang #define cupmErrorSetOnActiveProcess cudaErrorSetOnActiveProcess 291*05035670SJunchao Zhang #define CHKERRCUPM(x) CHKERRCUDA(x) 292*05035670SJunchao Zhang #define PetscCUPMBLASInitializeHandle() PetscCUBLASInitializeHandle() 293*05035670SJunchao Zhang #define PetscCUPMSOLVERDnInitializeHandle() PetscCUSOLVERDnInitializeHandle() 294*05035670SJunchao Zhang #define PetscCUPMInitialize PetscCUDAInitialize 295*05035670SJunchao Zhang #define PetscCUPMInitialized PetscCUDAInitialized 296*05035670SJunchao Zhang #define PetscCUPMInitializeCheck PetscCUDAInitializeCheck 297*05035670SJunchao Zhang #define PetscCUPMInitializeAndView PetscCUDAInitializeAndView 298*05035670SJunchao Zhang #define PetscCUPMSynchronize PetscCUDASynchronize 299*05035670SJunchao Zhang #define PetscNotUseCUPM PetscNotUseCUDA 300*05035670SJunchao Zhang #define cupmOptionsStr "CUDA options" 301*05035670SJunchao Zhang #define cupmSetDeviceStr "-cuda_set_device" 302*05035670SJunchao Zhang #define cupmViewStr "-cuda_view" 303*05035670SJunchao Zhang #define cupmSynchronizeStr "-cuda_synchronize" 304*05035670SJunchao Zhang #define PetscCUPMInitializeStr "PetscCUDAInitialize" 305*05035670SJunchao Zhang #define PetscOptionsCheckCUPM PetscOptionsCheckCUDA 306*05035670SJunchao Zhang #define PetscMPICUPMAwarenessCheck PetscMPICUDAAwarenessCheck 307*05035670SJunchao Zhang #include "cupminit.inc" 308*05035670SJunchao Zhang #endif 309*05035670SJunchao Zhang 310*05035670SJunchao Zhang #if defined(PETSC_HAVE_HIP) 311*05035670SJunchao Zhang typedef hipError_t cupmError_t; 312*05035670SJunchao Zhang typedef hipDeviceProp_t cupmDeviceProp; 313*05035670SJunchao Zhang #define cupmGetDeviceCount(x) hipGetDeviceCount(x) 314*05035670SJunchao Zhang #define cupmGetDevice(x) hipGetDevice(x) 315*05035670SJunchao Zhang #define cupmSetDevice(x) hipSetDevice(x) 316*05035670SJunchao Zhang #define cupmSetDeviceFlags(x) hipSetDeviceFlags(x) 317*05035670SJunchao Zhang #define cupmGetDeviceProperties(x,y) hipGetDeviceProperties(x,y) 318*05035670SJunchao Zhang #define cupmGetLastError() hipGetLastError() 319*05035670SJunchao Zhang #define cupmDeviceMapHost hipDeviceMapHost 320*05035670SJunchao Zhang #define cupmSuccess hipSuccess 321*05035670SJunchao Zhang #define cupmErrorSetOnActiveProcess hipErrorSetOnActiveProcess 322*05035670SJunchao Zhang #define CHKERRCUPM(x) CHKERRQ((x)==hipSuccess? 0:PETSC_ERR_LIB) 323*05035670SJunchao Zhang #define PetscCUPMBLASInitializeHandle() 0 324*05035670SJunchao Zhang #define PetscCUPMSOLVERDnInitializeHandle() 0 325*05035670SJunchao Zhang #define PetscCUPMInitialize PetscHIPInitialize 326*05035670SJunchao Zhang #define PetscCUPMInitialized PetscHIPInitialized 327*05035670SJunchao Zhang #define PetscCUPMInitializeCheck PetscHIPInitializeCheck 328*05035670SJunchao Zhang #define PetscCUPMInitializeAndView PetscHIPInitializeAndView 329*05035670SJunchao Zhang #define PetscCUPMSynchronize PetscHIPSynchronize 330*05035670SJunchao Zhang #define PetscNotUseCUPM PetscNotUseHIP 331*05035670SJunchao Zhang #define cupmOptionsStr "HIP options" 332*05035670SJunchao Zhang #define cupmSetDeviceStr "-hip_set_device" 333*05035670SJunchao Zhang #define cupmViewStr "-hip_view" 334*05035670SJunchao Zhang #define cupmSynchronizeStr "-hip_synchronize" 335*05035670SJunchao Zhang #define PetscCUPMInitializeStr "PetscHIPInitialize" 336*05035670SJunchao Zhang #define PetscOptionsCheckCUPM PetscOptionsCheckHIP 337*05035670SJunchao Zhang #define PetscMPICUPMAwarenessCheck PetscMPIHIPAwarenessCheck 338*05035670SJunchao Zhang #include "cupminit.inc" 339*05035670SJunchao Zhang #endif 340*05035670SJunchao Zhang 34157171095SVaclav Hapla PETSC_INTERN PetscErrorCode PetscOptionsCheckInitial_Private(const char help[]) 342e5c89e4eSSatish Balay { 343e5ed2c37SJose E. Roman char string[64]; 344e5c89e4eSSatish Balay MPI_Comm comm = PETSC_COMM_WORLD; 345*05035670SJunchao Zhang PetscBool flg1 = PETSC_FALSE,flg2 = PETSC_FALSE,flg3 = PETSC_FALSE,flag,hasHelp,logView; 346e5c89e4eSSatish Balay PetscErrorCode ierr; 34767584ceeSBarry Smith PetscReal si; 34828559dc8SJed Brown PetscInt intensity; 349e5c89e4eSSatish Balay int i; 350e5c89e4eSSatish Balay PetscMPIInt rank; 351d314f959SVaclav Hapla char version[256]; 3522479a3a6SBarry Smith #if defined(PETSC_USE_LOG) 353e5ed2c37SJose E. Roman char mname[PETSC_MAX_PATH_LEN]; 3542479a3a6SBarry Smith PetscViewerFormat format; 35567584ceeSBarry Smith PetscBool flg4 = PETSC_FALSE; 35667584ceeSBarry Smith #endif 3577381773fSBarry Smith 358e5c89e4eSSatish Balay PetscFunctionBegin; 35942218b76SBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 360e5c89e4eSSatish Balay 36167584ceeSBarry Smith #if !defined(PETSC_HAVE_THREADSAFETY) 36292f119d6SBarry Smith if (!(PETSC_RUNNING_ON_VALGRIND)) { 363e5c89e4eSSatish Balay /* 364e5c89e4eSSatish Balay Setup the memory management; support for tracing malloc() usage 365e5c89e4eSSatish Balay */ 366244bdbccSBarry Smith PetscBool mdebug = PETSC_FALSE, eachcall = PETSC_FALSE, initializenan = PETSC_FALSE, mlog = PETSC_FALSE; 36792f119d6SBarry Smith 36876bd3646SJed Brown if (PetscDefined(USE_DEBUG)) { 36992f119d6SBarry Smith mdebug = PETSC_TRUE; 37092f119d6SBarry Smith initializenan = PETSC_TRUE; 37192f119d6SBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-malloc_test",&flg1);CHKERRQ(ierr); 37276bd3646SJed Brown } else { 37392f119d6SBarry Smith /* don't warn about unused option */ 37492f119d6SBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-malloc_test",&flg1);CHKERRQ(ierr); 37592f119d6SBarry Smith flg1 = PETSC_FALSE; 37676bd3646SJed Brown } 37779dccf82SBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_debug",&flg2,&flg3);CHKERRQ(ierr); 37892f119d6SBarry Smith if (flg1 || flg2) { 37992f119d6SBarry Smith mdebug = PETSC_TRUE; 38092f119d6SBarry Smith eachcall = PETSC_TRUE; 38192f119d6SBarry Smith initializenan = PETSC_TRUE; 38279dccf82SBarry Smith } else if (flg3 && !flg2) { 38379dccf82SBarry Smith mdebug = PETSC_FALSE; 38479dccf82SBarry Smith eachcall = PETSC_FALSE; 38579dccf82SBarry Smith initializenan = PETSC_FALSE; 386e5c89e4eSSatish Balay } 38792f119d6SBarry Smith 38892f119d6SBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-malloc_view",&mlog);CHKERRQ(ierr); 38992f119d6SBarry Smith if (mlog) { 39092f119d6SBarry Smith mdebug = PETSC_TRUE; 39192f119d6SBarry Smith } 39279dccf82SBarry Smith /* the next line is deprecated */ 39392f119d6SBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-malloc",&mdebug,NULL);CHKERRQ(ierr); 39492f119d6SBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_dump",&mdebug,NULL);CHKERRQ(ierr); 39592f119d6SBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-log_view_memory",&mdebug,NULL);CHKERRQ(ierr); 39692f119d6SBarry Smith if (mdebug) { 39792f119d6SBarry Smith ierr = PetscMallocSetDebug(eachcall,initializenan);CHKERRQ(ierr); 39892f119d6SBarry Smith } 39992f119d6SBarry Smith if (mlog) { 40092f119d6SBarry Smith PetscReal logthreshold = 0; 40192f119d6SBarry Smith ierr = PetscOptionsGetReal(NULL,NULL,"-malloc_view_threshold",&logthreshold,NULL);CHKERRQ(ierr); 40292f119d6SBarry Smith ierr = PetscMallocViewSet(logthreshold);CHKERRQ(ierr); 40392f119d6SBarry Smith } 4048b254c29SBarry Smith #if defined(PETSC_USE_LOG) 4058b254c29SBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-log_view_memory",&PetscLogMemory,NULL);CHKERRQ(ierr); 4068b254c29SBarry Smith #endif 40792f119d6SBarry Smith } 40892f119d6SBarry Smith 409ba282f50SJed Brown ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_coalesce",&flg1,&flg2);CHKERRQ(ierr); 410ba282f50SJed Brown if (flg2) {ierr = PetscMallocSetCoalesce(flg1);CHKERRQ(ierr);} 41190d69ab7SBarry Smith flg1 = PETSC_FALSE; 4122f21b5c6SHong Zhang ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_hbw",&flg1,NULL);CHKERRQ(ierr); 413cf6f3811SHong Zhang /* ignore this option if malloc is already set */ 414cf6f3811SHong Zhang if (flg1 && !petscsetmallocvisited) {ierr = PetscSetUseHBWMalloc_Private();CHKERRQ(ierr);} 415e5c89e4eSSatish Balay 41690d69ab7SBarry Smith flg1 = PETSC_FALSE; 417c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-malloc_info",&flg1,NULL);CHKERRQ(ierr); 4187783f70dSSatish Balay if (!flg1) { 41990d69ab7SBarry Smith flg1 = PETSC_FALSE; 420c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-memory_view",&flg1,NULL);CHKERRQ(ierr); 4217783f70dSSatish Balay } 422e5c89e4eSSatish Balay if (flg1) { 423e5c89e4eSSatish Balay ierr = PetscMemorySetGetMaximumUsage();CHKERRQ(ierr); 424e5c89e4eSSatish Balay } 42567584ceeSBarry Smith #endif 426e5c89e4eSSatish Balay 427b4427426SBarry Smith #if defined(PETSC_USE_LOG) 428c5929fdfSBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-objects_dump",&PetscObjectsLog);CHKERRQ(ierr); 429b4427426SBarry Smith #endif 43005df10baSBarry Smith 431e5c89e4eSSatish Balay /* 432e5c89e4eSSatish Balay Set the display variable for graphics 433e5c89e4eSSatish Balay */ 434e5c89e4eSSatish Balay ierr = PetscSetDisplay();CHKERRQ(ierr); 435e5c89e4eSSatish Balay 43651dcc849SKerry Stevens /* 43757171095SVaclav Hapla Print main application help message 43857171095SVaclav Hapla */ 43957171095SVaclav Hapla ierr = PetscOptionsHasHelp(NULL,&hasHelp);CHKERRQ(ierr); 44057171095SVaclav Hapla if (help && hasHelp) { 44157171095SVaclav Hapla ierr = PetscPrintf(comm,help);CHKERRQ(ierr); 44257171095SVaclav Hapla ierr = PetscPrintf(comm,"----------------------------------------\n");CHKERRQ(ierr); 44357171095SVaclav Hapla } 44457171095SVaclav Hapla 44557171095SVaclav Hapla /* 446e5c89e4eSSatish Balay Print the PETSc version information 447e5c89e4eSSatish Balay */ 448d314f959SVaclav Hapla ierr = PetscOptionsHasName(NULL,NULL,"-version",&flg1);CHKERRQ(ierr); 449d314f959SVaclav Hapla if (flg1 || hasHelp) { 450e5c89e4eSSatish Balay /* 451e5c89e4eSSatish Balay Print "higher-level" package version message 452e5c89e4eSSatish Balay */ 453e5c89e4eSSatish Balay if (PetscExternalVersionFunction) { 454e5c89e4eSSatish Balay ierr = (*PetscExternalVersionFunction)(comm);CHKERRQ(ierr); 455e5c89e4eSSatish Balay } 456e5c89e4eSSatish Balay 457a523d312SBarry Smith ierr = PetscGetVersion(version,256);CHKERRQ(ierr); 458e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm,"%s\n",version);CHKERRQ(ierr); 459e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm,"%s",PETSC_AUTHOR_INFO);CHKERRQ(ierr); 460e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm,"See docs/changes/index.html for recent updates.\n");CHKERRQ(ierr); 46184e42920SBarry Smith ierr = (*PetscHelpPrintf)(comm,"See docs/faq.html for problems.\n");CHKERRQ(ierr); 462e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm,"See docs/manualpages/index.html for help. \n");CHKERRQ(ierr); 463e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm,"Libraries linked from %s\n",PETSC_LIB_DIR);CHKERRQ(ierr); 464c0bb3764SVaclav Hapla ierr = (*PetscHelpPrintf)(comm,"----------------------------------------\n");CHKERRQ(ierr); 4657ca660e7SBarry Smith } 4667ca660e7SBarry Smith 46794941ca7SBarry Smith /* 46894941ca7SBarry Smith Print "higher-level" package help message 46994941ca7SBarry Smith */ 47057171095SVaclav Hapla if (hasHelp) { 471d314f959SVaclav Hapla PetscBool hasHelpIntro; 472d314f959SVaclav Hapla 47394941ca7SBarry Smith if (PetscExternalHelpFunction) { 47494941ca7SBarry Smith ierr = (*PetscExternalHelpFunction)(comm);CHKERRQ(ierr); 47594941ca7SBarry Smith } 476d314f959SVaclav Hapla ierr = PetscOptionsHasHelpIntro_Internal(NULL,&hasHelpIntro);CHKERRQ(ierr); 477d314f959SVaclav Hapla if (hasHelpIntro) { 478bdb346e9SBarry Smith ierr = PetscOptionsDestroyDefault();CHKERRQ(ierr); 479008a6e76SBarry Smith ierr = PetscFreeMPIResources();CHKERRQ(ierr); 4807ca660e7SBarry Smith ierr = MPI_Finalize();CHKERRQ(ierr); 4817ca660e7SBarry Smith exit(0); 4827ca660e7SBarry Smith } 483e5c89e4eSSatish Balay } 484e5c89e4eSSatish Balay 485e5c89e4eSSatish Balay /* 486e5c89e4eSSatish Balay Setup the error handling 487e5c89e4eSSatish Balay */ 48890d69ab7SBarry Smith flg1 = PETSC_FALSE; 489c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-on_error_abort",&flg1,NULL);CHKERRQ(ierr); 490b59baad1SJed Brown if (flg1) { 49142218b76SBarry Smith ierr = MPI_Comm_set_errhandler(comm,MPI_ERRORS_ARE_FATAL);CHKERRQ(ierr); 49202c9f0b5SLisandro Dalcin ierr = PetscPushErrorHandler(PetscAbortErrorHandler,NULL);CHKERRQ(ierr); 493b59baad1SJed Brown } 49490d69ab7SBarry Smith flg1 = PETSC_FALSE; 495c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-on_error_mpiabort",&flg1,NULL);CHKERRQ(ierr); 49602c9f0b5SLisandro Dalcin if (flg1) { ierr = PetscPushErrorHandler(PetscMPIAbortErrorHandler,NULL);CHKERRQ(ierr);} 49790d69ab7SBarry Smith flg1 = PETSC_FALSE; 498c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-mpi_return_on_error",&flg1,NULL);CHKERRQ(ierr); 499e5c89e4eSSatish Balay if (flg1) { 500d54338ecSKarl Rupp ierr = MPI_Comm_set_errhandler(comm,MPI_ERRORS_RETURN);CHKERRQ(ierr); 501e5c89e4eSSatish Balay } 502e781f417SStefano Zampini /* experimental */ 503e781f417SStefano Zampini flg1 = PETSC_FALSE; 504e781f417SStefano Zampini ierr = PetscOptionsGetBool(NULL,NULL,"-mpi_return_error_string",&flg1,NULL);CHKERRQ(ierr); 505e781f417SStefano Zampini if (flg1) { 506e781f417SStefano Zampini MPI_Errhandler eh; 507e781f417SStefano Zampini 508e781f417SStefano Zampini ierr = MPI_Comm_create_errhandler(PetscMPI_Comm_eh,&eh);CHKERRQ(ierr); 509e781f417SStefano Zampini ierr = MPI_Comm_set_errhandler(comm,eh);CHKERRQ(ierr); 510e781f417SStefano Zampini ierr = MPI_Errhandler_free(&eh);CHKERRQ(ierr); 511e781f417SStefano Zampini } 51290d69ab7SBarry Smith flg1 = PETSC_FALSE; 513c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-no_signal_handler",&flg1,NULL);CHKERRQ(ierr); 5148d359177SBarry Smith if (!flg1) {ierr = PetscPushSignalHandler(PetscSignalHandlerDefault,(void*)0);CHKERRQ(ierr);} 515e5c89e4eSSatish Balay 516e5c89e4eSSatish Balay /* 517e5c89e4eSSatish Balay Setup debugger information 518e5c89e4eSSatish Balay */ 519e5c89e4eSSatish Balay ierr = PetscSetDefaultDebugger();CHKERRQ(ierr); 520589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-on_error_attach_debugger",string,sizeof(string),&flg1);CHKERRQ(ierr); 521e5c89e4eSSatish Balay if (flg1) { 522e5c89e4eSSatish Balay MPI_Errhandler err_handler; 523e5c89e4eSSatish Balay 524e5c89e4eSSatish Balay ierr = PetscSetDebuggerFromString(string);CHKERRQ(ierr); 52533c7d699SBarry Smith ierr = MPI_Comm_create_errhandler(Petsc_MPI_DebuggerOnError,&err_handler);CHKERRQ(ierr); 526d54338ecSKarl Rupp ierr = MPI_Comm_set_errhandler(comm,err_handler);CHKERRQ(ierr); 52702c9f0b5SLisandro Dalcin ierr = PetscPushErrorHandler(PetscAttachDebuggerErrorHandler,NULL);CHKERRQ(ierr); 528e5c89e4eSSatish Balay } 529589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-debug_terminal",string,sizeof(string),&flg1);CHKERRQ(ierr); 5305e96ac45SJed Brown if (flg1) { ierr = PetscSetDebugTerminal(string);CHKERRQ(ierr); } 531589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-start_in_debugger",string,sizeof(string),&flg1);CHKERRQ(ierr); 532589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-stop_for_debugger",string,sizeof(string),&flg2);CHKERRQ(ierr); 533e5c89e4eSSatish Balay if (flg1 || flg2) { 534e5c89e4eSSatish Balay PetscMPIInt size; 535e5c89e4eSSatish Balay PetscInt lsize,*nodes; 536e5c89e4eSSatish Balay MPI_Errhandler err_handler; 537e5c89e4eSSatish Balay /* 538e5c89e4eSSatish Balay we have to make sure that all processors have opened 539e5c89e4eSSatish Balay connections to all other processors, otherwise once the 540e5c89e4eSSatish Balay debugger has stated it is likely to receive a SIGUSR1 541e5c89e4eSSatish Balay and kill the program. 542e5c89e4eSSatish Balay */ 54342218b76SBarry Smith ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 544e5c89e4eSSatish Balay if (size > 2) { 545533163c2SBarry Smith PetscMPIInt dummy = 0; 546e5c89e4eSSatish Balay MPI_Status status; 547e5c89e4eSSatish Balay for (i=0; i<size; i++) { 548e5c89e4eSSatish Balay if (rank != i) { 54942218b76SBarry Smith ierr = MPI_Send(&dummy,1,MPI_INT,i,109,comm);CHKERRQ(ierr); 550e5c89e4eSSatish Balay } 551e5c89e4eSSatish Balay } 552e5c89e4eSSatish Balay for (i=0; i<size; i++) { 553e5c89e4eSSatish Balay if (rank != i) { 55442218b76SBarry Smith ierr = MPI_Recv(&dummy,1,MPI_INT,i,109,comm,&status);CHKERRQ(ierr); 555e5c89e4eSSatish Balay } 556e5c89e4eSSatish Balay } 557e5c89e4eSSatish Balay } 558e5c89e4eSSatish Balay /* check if this processor node should be in debugger */ 559785e854fSJed Brown ierr = PetscMalloc1(size,&nodes);CHKERRQ(ierr); 560e5c89e4eSSatish Balay lsize = size; 561c5929fdfSBarry Smith ierr = PetscOptionsGetIntArray(NULL,NULL,"-debugger_nodes",nodes,&lsize,&flag);CHKERRQ(ierr); 562e5c89e4eSSatish Balay if (flag) { 563e5c89e4eSSatish Balay for (i=0; i<lsize; i++) { 564e5c89e4eSSatish Balay if (nodes[i] == rank) { flag = PETSC_FALSE; break; } 565e5c89e4eSSatish Balay } 566e5c89e4eSSatish Balay } 567e5c89e4eSSatish Balay if (!flag) { 568e5c89e4eSSatish Balay ierr = PetscSetDebuggerFromString(string);CHKERRQ(ierr); 56902c9f0b5SLisandro Dalcin ierr = PetscPushErrorHandler(PetscAbortErrorHandler,NULL);CHKERRQ(ierr); 570e5c89e4eSSatish Balay if (flg1) { 571e5c89e4eSSatish Balay ierr = PetscAttachDebugger();CHKERRQ(ierr); 572e5c89e4eSSatish Balay } else { 573e5c89e4eSSatish Balay ierr = PetscStopForDebugger();CHKERRQ(ierr); 574e5c89e4eSSatish Balay } 57533c7d699SBarry Smith ierr = MPI_Comm_create_errhandler(Petsc_MPI_AbortOnError,&err_handler);CHKERRQ(ierr); 576d54338ecSKarl Rupp ierr = MPI_Comm_set_errhandler(comm,err_handler);CHKERRQ(ierr); 577e5c89e4eSSatish Balay } 578e5c89e4eSSatish Balay ierr = PetscFree(nodes);CHKERRQ(ierr); 579e5c89e4eSSatish Balay } 580e5c89e4eSSatish Balay 581589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-on_error_emacs",emacsmachinename,sizeof(emacsmachinename),&flg1);CHKERRQ(ierr); 582cb9801acSJed Brown if (flg1 && !rank) {ierr = PetscPushErrorHandler(PetscEmacsClientErrorHandler,emacsmachinename);CHKERRQ(ierr);} 583e5c89e4eSSatish Balay 584e5c89e4eSSatish Balay /* 585e5c89e4eSSatish Balay Setup profiling and logging 586e5c89e4eSSatish Balay */ 5876cf91177SBarry Smith #if defined(PETSC_USE_INFO) 5888bb29257SSatish Balay { 589e94e781bSJacob Faibussowitsch ierr = PetscInfoSetFromOptions(NULL);CHKERRQ(ierr); 590e5c89e4eSSatish Balay } 591865f6aa8SSatish Balay #endif 592aba4c478SBarry Smith ierr = PetscDetermineInitialFPTrap(); 593cc9df77eSBarry Smith flg1 = PETSC_FALSE; 594cc9df77eSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-fp_trap",&flg1,&flag);CHKERRQ(ierr); 595cc9df77eSBarry Smith if (flag) {ierr = PetscSetFPTrap((PetscFPTrap)flg1);CHKERRQ(ierr);} 596cc9df77eSBarry Smith ierr = PetscOptionsGetInt(NULL,NULL,"-check_pointer_intensity",&intensity,&flag);CHKERRQ(ierr); 597cc9df77eSBarry Smith if (flag) {ierr = PetscCheckPointerSetIntensity(intensity);CHKERRQ(ierr);} 598865f6aa8SSatish Balay #if defined(PETSC_USE_LOG) 599865f6aa8SSatish Balay mname[0] = 0; 600589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-history",mname,sizeof(mname),&flg1);CHKERRQ(ierr); 601865f6aa8SSatish Balay if (flg1) { 602865f6aa8SSatish Balay if (mname[0]) { 603f3dea69dSBarry Smith ierr = PetscOpenHistoryFile(mname,&petsc_history);CHKERRQ(ierr); 604865f6aa8SSatish Balay } else { 605706d7a88SBarry Smith ierr = PetscOpenHistoryFile(NULL,&petsc_history);CHKERRQ(ierr); 606865f6aa8SSatish Balay } 607865f6aa8SSatish Balay } 608217044c2SLisandro Dalcin 609217044c2SLisandro Dalcin ierr = PetscOptionsGetBool(NULL,NULL,"-log_sync",&PetscLogSyncOn,NULL);CHKERRQ(ierr); 610217044c2SLisandro Dalcin 611e5c89e4eSSatish Balay #if defined(PETSC_HAVE_MPE) 61290d69ab7SBarry Smith flg1 = PETSC_FALSE; 613c5929fdfSBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-log_mpe",&flg1);CHKERRQ(ierr); 614495fc317SBarry Smith if (flg1) {ierr = PetscLogMPEBegin();CHKERRQ(ierr);} 615e5c89e4eSSatish Balay #endif 61690d69ab7SBarry Smith flg1 = PETSC_FALSE; 61790d69ab7SBarry Smith flg3 = PETSC_FALSE; 618c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-log_all",&flg1,NULL);CHKERRQ(ierr); 619c5929fdfSBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-log_summary",&flg3);CHKERRQ(ierr); 620e5c89e4eSSatish Balay if (flg1) { ierr = PetscLogAllBegin();CHKERRQ(ierr); } 621bb1d7374SBarry Smith else if (flg3) { ierr = PetscLogDefaultBegin();CHKERRQ(ierr);} 622e5c89e4eSSatish Balay 623589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-log_trace",mname,sizeof(mname),&flg1);CHKERRQ(ierr); 624e5c89e4eSSatish Balay if (flg1) { 625e5c89e4eSSatish Balay char name[PETSC_MAX_PATH_LEN],fname[PETSC_MAX_PATH_LEN]; 626e5c89e4eSSatish Balay FILE *file; 627e5c89e4eSSatish Balay if (mname[0]) { 6282e924ca5SSatish Balay PetscSNPrintf(name,PETSC_MAX_PATH_LEN,"%s.%d",mname,rank); 629e5c89e4eSSatish Balay ierr = PetscFixFilename(name,fname);CHKERRQ(ierr); 630e5c89e4eSSatish Balay file = fopen(fname,"w"); 631f3dea69dSBarry Smith if (!file) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to open trace file: %s",fname); 632a297a907SKarl Rupp } else file = PETSC_STDOUT; 633e5c89e4eSSatish Balay ierr = PetscLogTraceBegin(file);CHKERRQ(ierr); 634e5c89e4eSSatish Balay } 635bb1d7374SBarry Smith 63616413a6aSBarry Smith ierr = PetscOptionsGetViewer(comm,NULL,NULL,"-log_view",NULL,&format,&flg4);CHKERRQ(ierr); 637bb1d7374SBarry Smith if (flg4) { 638bb1d7374SBarry Smith if (format == PETSC_VIEWER_ASCII_XML) { 639bb1d7374SBarry Smith ierr = PetscLogNestedBegin();CHKERRQ(ierr); 640bb1d7374SBarry Smith } else { 641bb1d7374SBarry Smith ierr = PetscLogDefaultBegin();CHKERRQ(ierr); 642bb1d7374SBarry Smith } 643eccbb886SLisandro Dalcin } 644eccbb886SLisandro Dalcin if (flg4 && format == PETSC_VIEWER_ASCII_XML) { 645eccbb886SLisandro Dalcin PetscReal threshold = PetscRealConstant(0.01); 646eccbb886SLisandro Dalcin ierr = PetscOptionsGetReal(NULL,NULL,"-log_threshold",&threshold,&flg1);CHKERRQ(ierr); 647eccbb886SLisandro Dalcin if (flg1) {ierr = PetscLogSetThreshold((PetscLogDouble)threshold,NULL);CHKERRQ(ierr);} 648bb1d7374SBarry Smith } 649e5c89e4eSSatish Balay #endif 650e5c89e4eSSatish Balay 651c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-saws_options",&PetscOptionsPublish,NULL);CHKERRQ(ierr); 652*05035670SJunchao Zhang ierr = PetscOptionsGetBool(NULL,NULL,"-use_gpu_aware_mpi",&use_gpu_aware_mpi,NULL);CHKERRQ(ierr); 6538d4e85a7SStefano Zampini /* 654*05035670SJunchao Zhang If collecting logging information, by default, wait for device to complete its operations 6558d4e85a7SStefano Zampini before returning to the CPU in order to get accurate timings of each event 6568d4e85a7SStefano Zampini */ 657cae85d06SJunchao Zhang ierr = PetscOptionsHasName(NULL,NULL,"-log_summary",&logView);CHKERRQ(ierr); 658*05035670SJunchao Zhang if (!logView) {ierr = PetscOptionsHasName(NULL,NULL,"-log_view",&logView);CHKERRQ(ierr);} 6598d4e85a7SStefano Zampini 660*05035670SJunchao Zhang #if defined(PETSC_HAVE_CUDA) 661*05035670SJunchao Zhang ierr = PetscOptionsCheckCUDA(logView);CHKERRQ(ierr); 662*05035670SJunchao Zhang #endif 663cae85d06SJunchao Zhang 664*05035670SJunchao Zhang #if defined(PETSC_HAVE_HIP) 665*05035670SJunchao Zhang ierr = PetscOptionsCheckHIP(logView);CHKERRQ(ierr); 6664b0a73b2SBarry Smith #endif 6674b0a73b2SBarry Smith 668e5c89e4eSSatish Balay /* 669e5c89e4eSSatish Balay Print basic help message 670e5c89e4eSSatish Balay */ 67157171095SVaclav Hapla if (hasHelp) { 672e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm,"Options for all PETSc programs:\n");CHKERRQ(ierr); 673d314f959SVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -version: prints PETSc version\n");CHKERRQ(ierr); 674d314f959SVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -help intro: prints example description and PETSc version, and exits\n");CHKERRQ(ierr); 675d314f959SVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -help: prints example description, PETSc version, and available options for used routines\n");CHKERRQ(ierr); 676301d30feSBarry Smith ierr = (*PetscHelpPrintf)(comm," -on_error_abort: cause an abort when an error is detected. Useful \n ");CHKERRQ(ierr); 677301d30feSBarry Smith ierr = (*PetscHelpPrintf)(comm," only when run in the debugger\n");CHKERRQ(ierr); 678e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -on_error_attach_debugger [gdb,dbx,xxgdb,ups,noxterm]\n");CHKERRQ(ierr); 679e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," start the debugger in new xterm\n");CHKERRQ(ierr); 680e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," unless noxterm is given\n");CHKERRQ(ierr); 681e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -start_in_debugger [gdb,dbx,xxgdb,ups,noxterm]\n");CHKERRQ(ierr); 682e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," start all processes in the debugger\n");CHKERRQ(ierr); 683e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -on_error_emacs <machinename>\n");CHKERRQ(ierr); 684e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," emacs jumps to error file\n");CHKERRQ(ierr); 685e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -debugger_nodes [n1,n2,..] Nodes to start in debugger\n");CHKERRQ(ierr); 686e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -debugger_pause [m] : delay (in seconds) to attach debugger\n");CHKERRQ(ierr); 687e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -stop_for_debugger : prints message on how to attach debugger manually\n");CHKERRQ(ierr); 688e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," waits the delay for you to attach\n");CHKERRQ(ierr); 6891cda70a7SBarry Smith ierr = (*PetscHelpPrintf)(comm," -display display: Location where X window graphics and debuggers are displayed\n");CHKERRQ(ierr); 690e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -no_signal_handler: do not trap error signals\n");CHKERRQ(ierr); 691e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -mpi_return_on_error: MPI returns error code, rather than abort on internal error\n");CHKERRQ(ierr); 692e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -fp_trap: stop on floating point exceptions\n");CHKERRQ(ierr); 693e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," note on IBM RS6000 this slows run greatly\n");CHKERRQ(ierr); 694e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -malloc_dump <optional filename>: dump list of unfreed memory at conclusion\n");CHKERRQ(ierr); 69579dccf82SBarry Smith ierr = (*PetscHelpPrintf)(comm," -malloc: use PETSc error checking malloc (deprecated, use -malloc_debug)\n");CHKERRQ(ierr); 69679dccf82SBarry Smith ierr = (*PetscHelpPrintf)(comm," -malloc no: don't use PETSc error checking malloc (deprecated, use -malloc_debug no)\n");CHKERRQ(ierr); 6974161f2a3SBarry Smith ierr = (*PetscHelpPrintf)(comm," -malloc_info: prints total memory usage\n");CHKERRQ(ierr); 69892f119d6SBarry Smith ierr = (*PetscHelpPrintf)(comm," -malloc_view <optional filename>: keeps log of all memory allocations, displays in PetscFinalize()\n");CHKERRQ(ierr); 69979dccf82SBarry Smith ierr = (*PetscHelpPrintf)(comm," -malloc_debug <true or false>: enables or disables extended checking for memory corruption\n");CHKERRQ(ierr); 70026a7e8d4SBarry Smith ierr = (*PetscHelpPrintf)(comm," -options_view: dump list of options inputted\n");CHKERRQ(ierr); 701e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -options_left: dump list of unused options\n");CHKERRQ(ierr); 702e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -options_left no: don't dump list of unused options\n");CHKERRQ(ierr); 703e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -tmp tmpdir: alternative /tmp directory\n");CHKERRQ(ierr); 704e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -shared_tmp: tmp directory is shared by all processors\n");CHKERRQ(ierr); 705a8c7a070SBarry Smith ierr = (*PetscHelpPrintf)(comm," -not_shared_tmp: each processor has separate tmp directory\n");CHKERRQ(ierr); 7060841954dSBarry Smith ierr = (*PetscHelpPrintf)(comm," -memory_view: print memory usage at end of run\n");CHKERRQ(ierr); 707e5c89e4eSSatish Balay #if defined(PETSC_USE_LOG) 708e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -get_total_flops: total flops over all processors\n");CHKERRQ(ierr); 709185ae32fSMatthew G. Knepley ierr = (*PetscHelpPrintf)(comm," -log_view [:filename:[format]]: logging objects and events\n");CHKERRQ(ierr); 710e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -log_trace [filename]: prints trace of all PETSc calls\n");CHKERRQ(ierr); 71156071f75SVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -log_exclude <list,of,classnames>: exclude given classes from logging\n");CHKERRQ(ierr); 712e5c89e4eSSatish Balay #if defined(PETSC_HAVE_MPE) 713495fc317SBarry Smith ierr = (*PetscHelpPrintf)(comm," -log_mpe: Also create logfile viewable through Jumpshot\n");CHKERRQ(ierr); 714e5c89e4eSSatish Balay #endif 715e94e781bSJacob Faibussowitsch #endif 716e94e781bSJacob Faibussowitsch #if defined(PETSC_USE_INFO) 717fe9b927eSVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -info [filename][:[~]<list,of,classnames>[:[~]self]]: print verbose information\n");CHKERRQ(ierr); 718e5c89e4eSSatish Balay #endif 719e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -options_file <file>: reads options from file\n");CHKERRQ(ierr); 720c5b5d8d5SVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -options_monitor: monitor options to standard output, including that set previously e.g. in option files\n");CHKERRQ(ierr); 721c5b5d8d5SVaclav Hapla ierr = (*PetscHelpPrintf)(comm," -options_monitor_cancel: cancels all hardwired option monitors\n");CHKERRQ(ierr); 722e5c89e4eSSatish Balay ierr = (*PetscHelpPrintf)(comm," -petsc_sleep n: sleeps n seconds before running program\n");CHKERRQ(ierr); 723e5c89e4eSSatish Balay } 724e5c89e4eSSatish Balay 72574ba8654SBarry Smith #if defined(PETSC_HAVE_POPEN) 72674ba8654SBarry Smith { 72774ba8654SBarry Smith char machine[128]; 728589a23caSBarry Smith ierr = PetscOptionsGetString(NULL,NULL,"-popen_machine",machine,sizeof(machine),&flg1);CHKERRQ(ierr); 72974ba8654SBarry Smith if (flg1) { 73074ba8654SBarry Smith ierr = PetscPOpenSetMachine(machine);CHKERRQ(ierr); 73174ba8654SBarry Smith } 73274ba8654SBarry Smith } 73374ba8654SBarry Smith #endif 73474ba8654SBarry Smith 735c5929fdfSBarry Smith ierr = PetscOptionsGetReal(NULL,NULL,"-petsc_sleep",&si,&flg1);CHKERRQ(ierr); 736e5c89e4eSSatish Balay if (flg1) { 737e5c89e4eSSatish Balay ierr = PetscSleep(si);CHKERRQ(ierr); 738e5c89e4eSSatish Balay } 739e5c89e4eSSatish Balay 740fdc842d1SBarry Smith #if defined(PETSC_HAVE_VIENNACL) 741c5929fdfSBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-log_summary",&flg3);CHKERRQ(ierr); 742f14045dbSBarry Smith if (!flg3) { 743c5929fdfSBarry Smith ierr = PetscOptionsHasName(NULL,NULL,"-log_view",&flg3);CHKERRQ(ierr); 744f14045dbSBarry Smith } 745c5929fdfSBarry Smith ierr = PetscOptionsGetBool(NULL,NULL,"-viennacl_synchronize",&flg3,NULL);CHKERRQ(ierr); 746f14045dbSBarry Smith PetscViennaCLSynchronize = flg3; 747fdc842d1SBarry Smith ierr = PetscViennaCLInit();CHKERRQ(ierr); 7484cf1874eSKarl Rupp #endif 74982f73ecaSAlejandro Lamas Daviña 750fdc842d1SBarry Smith /* 751fdc842d1SBarry Smith Creates the logging data structures; this is enabled even if logging is not turned on 752fdc842d1SBarry Smith This is the last thing we do before returning to the user code to prevent having the 753fdc842d1SBarry Smith logging numbers contaminated by any startup time associated with MPI and the GPUs 754fdc842d1SBarry Smith */ 755fdc842d1SBarry Smith #if defined(PETSC_USE_LOG) 756fdc842d1SBarry Smith ierr = PetscLogInitialize();CHKERRQ(ierr); 757f0a7718cSKarl Rupp #endif 758f0a7718cSKarl Rupp 759e5c89e4eSSatish Balay PetscFunctionReturn(0); 760e5c89e4eSSatish Balay } 761