/* This file defines the initialization of PETSc, including PetscInitialize() */ #include /*I "petscsys.h" I*/ #include #include #if defined(PETSC_USE_LOG) PETSC_INTERN PetscErrorCode PetscLogInitialize(void); PETSC_INTERN PetscErrorCode PetscLogFinalize(void); #endif #if defined(PETSC_SERIALIZE_FUNCTIONS) PETSC_INTERN PetscFPT PetscFPTData; PetscFPT PetscFPTData = 0; #endif #if defined(PETSC_HAVE_SAWS) #include #endif /* -----------------------------------------------------------------------------------------*/ PETSC_INTERN FILE *petsc_history; PETSC_INTERN PetscErrorCode PetscInitialize_DynamicLibraries(void); PETSC_INTERN PetscErrorCode PetscFinalize_DynamicLibraries(void); PETSC_INTERN PetscErrorCode PetscFunctionListPrintAll(void); PETSC_INTERN PetscErrorCode PetscSequentialPhaseBegin_Private(MPI_Comm,int); PETSC_INTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm,int); PETSC_INTERN PetscErrorCode PetscCloseHistoryFile(FILE**); /* user may set this BEFORE calling PetscInitialize() */ MPI_Comm PETSC_COMM_WORLD = MPI_COMM_NULL; PetscMPIInt Petsc_Counter_keyval = MPI_KEYVAL_INVALID; PetscMPIInt Petsc_InnerComm_keyval = MPI_KEYVAL_INVALID; PetscMPIInt Petsc_OuterComm_keyval = MPI_KEYVAL_INVALID; PetscMPIInt Petsc_ShmComm_keyval = MPI_KEYVAL_INVALID; /* Declare and set all the string names of the PETSc enums */ const char *const PetscBools[] = {"FALSE","TRUE","PetscBool","PETSC_",0}; const char *const PetscCopyModes[] = {"COPY_VALUES","OWN_POINTER","USE_POINTER","PetscCopyMode","PETSC_",0}; PetscBool PetscPreLoadingUsed = PETSC_FALSE; PetscBool PetscPreLoadingOn = PETSC_FALSE; PetscInt PetscHotRegionDepth; #if defined(PETSC_HAVE_THREADSAFETY) PetscSpinlock PetscViewerASCIISpinLockOpen; PetscSpinlock PetscViewerASCIISpinLockStdout; PetscSpinlock PetscViewerASCIISpinLockStderr; PetscSpinlock PetscCommSpinLock; #endif /* Checks the options database for initializations related to the PETSc components */ PETSC_INTERN PetscErrorCode PetscOptionsCheckInitial_Components(void) { PetscBool flg; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscOptionsHasHelp(NULL,&flg);CHKERRQ(ierr); if (flg) { #if defined(PETSC_USE_LOG) MPI_Comm comm = PETSC_COMM_WORLD; ierr = (*PetscHelpPrintf)(comm,"------Additional PETSc component options--------\n");CHKERRQ(ierr); ierr = (*PetscHelpPrintf)(comm," -log_exclude: \n");CHKERRQ(ierr); ierr = (*PetscHelpPrintf)(comm," -info_exclude: \n");CHKERRQ(ierr); ierr = (*PetscHelpPrintf)(comm,"-----------------------------------------------\n");CHKERRQ(ierr); #endif } PetscFunctionReturn(0); } /* PetscInitializeNoPointers - Calls PetscInitialize() from C/C++ without the pointers to argc and args Collective Level: advanced Notes: this is called only by the PETSc Julia interface. Even though it might start MPI it sets the flag to indicate that it did NOT start MPI so that the PetscFinalize() does not end MPI, thus allowing PetscInitialize() to be called multiple times from Julia without the problem of trying to initialize MPI more than once. Developer Note: Turns off PETSc signal handling to allow Julia to manage signals .seealso: PetscInitialize(), PetscInitializeFortran(), PetscInitializeNoArguments() */ PetscErrorCode PetscInitializeNoPointers(int argc,char **args,const char *filename,const char *help) { PetscErrorCode ierr; int myargc = argc; char **myargs = args; PetscFunctionBegin; ierr = PetscInitialize(&myargc,&myargs,filename,help);CHKERRQ(ierr); ierr = PetscPopSignalHandler();CHKERRQ(ierr); PetscBeganMPI = PETSC_FALSE; PetscFunctionReturn(ierr); } /* Used by Julia interface to get communicator */ PetscErrorCode PetscGetPETSC_COMM_SELF(MPI_Comm *comm) { PetscFunctionBegin; *comm = PETSC_COMM_SELF; PetscFunctionReturn(0); } /*@C PetscInitializeNoArguments - Calls PetscInitialize() from C/C++ without the command line arguments. Collective Level: advanced .seealso: PetscInitialize(), PetscInitializeFortran() @*/ PetscErrorCode PetscInitializeNoArguments(void) { PetscErrorCode ierr; int argc = 0; char **args = 0; PetscFunctionBegin; ierr = PetscInitialize(&argc,&args,NULL,NULL); PetscFunctionReturn(ierr); } /*@ PetscInitialized - Determine whether PETSc is initialized. Level: beginner .seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran() @*/ PetscErrorCode PetscInitialized(PetscBool *isInitialized) { *isInitialized = PetscInitializeCalled; return 0; } /*@ PetscFinalized - Determine whether PetscFinalize() has been called yet Level: developer .seealso: PetscInitialize(), PetscInitializeNoArguments(), PetscInitializeFortran() @*/ PetscErrorCode PetscFinalized(PetscBool *isFinalized) { *isFinalized = PetscFinalizeCalled; return 0; } PETSC_INTERN PetscErrorCode PetscOptionsCheckInitial_Private(void); /* This function is the MPI reduction operation used to compute the sum of the first half of the datatype and the max of the second half. */ MPI_Op MPIU_MAXSUM_OP = 0; PETSC_INTERN void MPIAPI MPIU_MaxSum_Local(void *in,void *out,int *cnt,MPI_Datatype *datatype) { PetscInt *xin = (PetscInt*)in,*xout = (PetscInt*)out,i,count = *cnt; PetscFunctionBegin; if (*datatype != MPIU_2INT) { (*PetscErrorPrintf)("Can only handle MPIU_2INT data types"); MPI_Abort(MPI_COMM_WORLD,1); } for (i=0; iPetscRealPartComplex(xin[i]) ? xin[i] : xout[i]; } } #endif else { (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_SCALAR data (i.e. double or complex) types"); MPI_Abort(MPI_COMM_WORLD,1); } PetscFunctionReturnVoid(); } #endif /* Private routine to delete internal tag/name counter storage when a communicator is freed. This is called by MPI, not by users. This is called by MPI_Comm_free() when the communicator that has this data as an attribute is freed. Note: this is declared extern "C" because it is passed to MPI_Comm_create_keyval() */ PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelCounter(MPI_Comm comm,PetscMPIInt keyval,void *count_val,void *extra_state) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscInfo1(0,"Deleting counter data in an MPI_Comm %ld\n",(long)comm);CHKERRMPI(ierr); ierr = PetscFree(count_val);CHKERRMPI(ierr); PetscFunctionReturn(MPI_SUCCESS); } /* This is invoked on the outer comm as a result of either PetscCommDestroy() (via MPI_Comm_delete_attr) or when the user calls MPI_Comm_free(). This is the only entry point for breaking the links between inner and outer comms. This is called by MPI, not by users. This is called when MPI_Comm_free() is called on the communicator. Note: this is declared extern "C" because it is passed to MPI_Comm_create_keyval() */ PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Outer(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state) { PetscErrorCode ierr; PetscMPIInt flg; union {MPI_Comm comm; void *ptr;} icomm,ocomm; PetscFunctionBegin; if (keyval != Petsc_InnerComm_keyval) SETERRMPI(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Unexpected keyval"); icomm.ptr = attr_val; ierr = MPI_Comm_get_attr(icomm.comm,Petsc_OuterComm_keyval,&ocomm,&flg);CHKERRMPI(ierr); if (!flg) SETERRMPI(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm does not have expected reference to outer comm"); if (ocomm.comm != comm) SETERRMPI(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Inner MPI_Comm has reference to non-matching outer comm"); ierr = MPI_Comm_delete_attr(icomm.comm,Petsc_OuterComm_keyval);CHKERRMPI(ierr); ierr = PetscInfo1(0,"User MPI_Comm %ld is being freed after removing reference from inner PETSc comm to this outer comm\n",(long)comm);CHKERRMPI(ierr); PetscFunctionReturn(MPI_SUCCESS); } /* * This is invoked on the inner comm when Petsc_DelComm_Outer calls MPI_Comm_delete_attr. It should not be reached any other way. */ PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Inner(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscInfo1(0,"Removing reference to PETSc communicator embedded in a user MPI_Comm %ld\n",(long)comm);CHKERRMPI(ierr); PetscFunctionReturn(MPI_SUCCESS); } PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelComm_Shm(MPI_Comm,PetscMPIInt,void *,void *); #if defined(PETSC_USE_PETSC_MPI_EXTERNAL32) PETSC_EXTERN PetscMPIInt PetscDataRep_extent_fn(MPI_Datatype,MPI_Aint*,void*); PETSC_EXTERN PetscMPIInt PetscDataRep_read_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*); PETSC_EXTERN PetscMPIInt PetscDataRep_write_conv_fn(void*, MPI_Datatype,PetscMPIInt,void*,MPI_Offset,void*); #endif PetscMPIInt PETSC_MPI_ERROR_CLASS,PETSC_MPI_ERROR_CODE; PETSC_INTERN int PetscGlobalArgc; PETSC_INTERN char **PetscGlobalArgs; int PetscGlobalArgc = 0; char **PetscGlobalArgs = 0; PetscSegBuffer PetscCitationsList; PetscErrorCode PetscCitationsInitialize(void) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscSegBufferCreate(1,10000,&PetscCitationsList);CHKERRQ(ierr); ierr = PetscCitationsRegister("@TechReport{petsc-user-ref,\n Author = {Satish Balay and Shrirang Abhyankar and Mark F. Adams and Jed Brown \n and Peter Brune and Kris Buschelman and Lisandro Dalcin and\n Victor Eijkhout and William D. Gropp and Dmitry Karpeyev and\n Dinesh Kaushik and Matthew G. Knepley and Dave A. May and Lois Curfman McInnes\n and Richard Tran Mills and Todd Munson and Karl Rupp and Patrick Sanan\n and Barry F. Smith and Stefano Zampini and Hong Zhang and Hong Zhang},\n Title = {{PETS}c Users Manual},\n Number = {ANL-95/11 - Revision 3.11},\n Institution = {Argonne National Laboratory},\n Year = {2019}\n}\n",NULL);CHKERRQ(ierr); ierr = PetscCitationsRegister("@InProceedings{petsc-efficient,\n Author = {Satish Balay and William D. Gropp and Lois Curfman McInnes and Barry F. Smith},\n Title = {Efficient Management of Parallelism in Object Oriented Numerical Software Libraries},\n Booktitle = {Modern Software Tools in Scientific Computing},\n Editor = {E. Arge and A. M. Bruaset and H. P. Langtangen},\n Pages = {163--202},\n Publisher = {Birkh{\\\"{a}}user Press},\n Year = {1997}\n}\n",NULL);CHKERRQ(ierr); PetscFunctionReturn(0); } static char programname[PETSC_MAX_PATH_LEN] = ""; /* HP includes entire path in name */ PetscErrorCode PetscSetProgramName(const char name[]) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscStrncpy(programname,name,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); PetscFunctionReturn(0); } /*@C PetscGetProgramName - Gets the name of the running program. Not Collective Input Parameter: . len - length of the string name Output Parameter: . name - the name of the running program Level: advanced Notes: The name of the program is copied into the user-provided character array of length len. On some machines the program name includes its entire path, so one should generally set len >= PETSC_MAX_PATH_LEN. @*/ PetscErrorCode PetscGetProgramName(char name[],size_t len) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscStrncpy(name,programname,len);CHKERRQ(ierr); PetscFunctionReturn(0); } /*@C PetscGetArgs - Allows you to access the raw command line arguments anywhere after PetscInitialize() is called but before PetscFinalize(). Not Collective Output Parameters: + argc - count of number of command line arguments - args - the command line arguments Level: intermediate Notes: This is usually used to pass the command line arguments into other libraries that are called internally deep in PETSc or the application. The first argument contains the program name as is normal for C arguments. .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArguments() @*/ PetscErrorCode PetscGetArgs(int *argc,char ***args) { PetscFunctionBegin; if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()"); *argc = PetscGlobalArgc; *args = PetscGlobalArgs; PetscFunctionReturn(0); } /*@C PetscGetArguments - Allows you to access the command line arguments anywhere after PetscInitialize() is called but before PetscFinalize(). Not Collective Output Parameters: . args - the command line arguments Level: intermediate Notes: This does NOT start with the program name and IS null terminated (final arg is void) .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscFreeArguments() @*/ PetscErrorCode PetscGetArguments(char ***args) { PetscInt i,argc = PetscGlobalArgc; PetscErrorCode ierr; PetscFunctionBegin; if (!PetscInitializeCalled && PetscFinalizeCalled) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"You must call after PetscInitialize() but before PetscFinalize()"); if (!argc) {*args = NULL; PetscFunctionReturn(0);} ierr = PetscMalloc1(argc,args);CHKERRQ(ierr); for (i=0; i PETSC_INTERN PetscErrorCode PetscInitializeSAWs(const char help[]) { if (!PetscGlobalRank) { char cert[PETSC_MAX_PATH_LEN],root[PETSC_MAX_PATH_LEN],*intro,programname[64],*appline,*options,version[64]; int port; PetscBool flg,rootlocal = PETSC_FALSE,flg2,selectport = PETSC_FALSE; size_t applinelen,introlen; PetscErrorCode ierr; char sawsurl[256]; ierr = PetscOptionsHasName(NULL,NULL,"-saws_log",&flg);CHKERRQ(ierr); if (flg) { char sawslog[PETSC_MAX_PATH_LEN]; ierr = PetscOptionsGetString(NULL,NULL,"-saws_log",sawslog,PETSC_MAX_PATH_LEN,NULL);CHKERRQ(ierr); if (sawslog[0]) { PetscStackCallSAWs(SAWs_Set_Use_Logfile,(sawslog)); } else { PetscStackCallSAWs(SAWs_Set_Use_Logfile,(NULL)); } } ierr = PetscOptionsGetString(NULL,NULL,"-saws_https",cert,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); if (flg) { PetscStackCallSAWs(SAWs_Set_Use_HTTPS,(cert)); } ierr = PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select",&selectport,NULL);CHKERRQ(ierr); if (selectport) { PetscStackCallSAWs(SAWs_Get_Available_Port,(&port)); PetscStackCallSAWs(SAWs_Set_Port,(port)); } else { ierr = PetscOptionsGetInt(NULL,NULL,"-saws_port",&port,&flg);CHKERRQ(ierr); if (flg) { PetscStackCallSAWs(SAWs_Set_Port,(port)); } } ierr = PetscOptionsGetString(NULL,NULL,"-saws_root",root,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr); if (flg) { PetscStackCallSAWs(SAWs_Set_Document_Root,(root));CHKERRQ(ierr); ierr = PetscStrcmp(root,".",&rootlocal);CHKERRQ(ierr); } else { ierr = PetscOptionsHasName(NULL,NULL,"-saws_options",&flg);CHKERRQ(ierr); if (flg) { ierr = PetscStrreplace(PETSC_COMM_WORLD,"${PETSC_DIR}/share/petsc/saws",root,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); PetscStackCallSAWs(SAWs_Set_Document_Root,(root));CHKERRQ(ierr); } } ierr = PetscOptionsHasName(NULL,NULL,"-saws_local",&flg2);CHKERRQ(ierr); if (flg2) { char jsdir[PETSC_MAX_PATH_LEN]; if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"-saws_local option requires -saws_root option"); ierr = PetscSNPrintf(jsdir,PETSC_MAX_PATH_LEN,"%s/js",root);CHKERRQ(ierr); ierr = PetscTestDirectory(jsdir,'r',&flg);CHKERRQ(ierr); if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_READ,"-saws_local option requires js directory in root directory"); PetscStackCallSAWs(SAWs_Push_Local_Header,());CHKERRQ(ierr); } ierr = PetscGetProgramName(programname,64);CHKERRQ(ierr); ierr = PetscStrlen(help,&applinelen);CHKERRQ(ierr); introlen = 4096 + applinelen; applinelen += 1024; ierr = PetscMalloc(applinelen,&appline);CHKERRQ(ierr); ierr = PetscMalloc(introlen,&intro);CHKERRQ(ierr); if (rootlocal) { ierr = PetscSNPrintf(appline,applinelen,"%s.c.html",programname);CHKERRQ(ierr); ierr = PetscTestFile(appline,'r',&rootlocal);CHKERRQ(ierr); } ierr = PetscOptionsGetAll(NULL,&options);CHKERRQ(ierr); if (rootlocal && help) { ierr = PetscSNPrintf(appline,applinelen,"
Running %s %s

%s

\n",programname,programname,options,help);CHKERRQ(ierr); } else if (help) { ierr = PetscSNPrintf(appline,applinelen,"
Running %s %s

%s

",programname,options,help);CHKERRQ(ierr); } else { ierr = PetscSNPrintf(appline,applinelen,"
Running %s %s

\n",programname,options);CHKERRQ(ierr); } ierr = PetscFree(options);CHKERRQ(ierr); ierr = PetscGetVersion(version,sizeof(version));CHKERRQ(ierr); ierr = PetscSNPrintf(intro,introlen,"\n" "

PETSc Application Web server powered by SAWs

\n" "
This is the default PETSc application dashboard, from it you can access any published PETSc objects or logging data

%s configured with %s

\n" "%s",version,petscconfigureoptions,appline);CHKERRQ(ierr); PetscStackCallSAWs(SAWs_Push_Body,("index.html",0,intro)); ierr = PetscFree(intro);CHKERRQ(ierr); ierr = PetscFree(appline);CHKERRQ(ierr); if (selectport) { PetscBool silent; ierr = SAWs_Initialize(); /* another process may have grabbed the port so keep trying */ while (ierr) { PetscStackCallSAWs(SAWs_Get_Available_Port,(&port)); PetscStackCallSAWs(SAWs_Set_Port,(port)); ierr = SAWs_Initialize(); } ierr = PetscOptionsGetBool(NULL,NULL,"-saws_port_auto_select_silent",&silent,NULL);CHKERRQ(ierr); if (!silent) { PetscStackCallSAWs(SAWs_Get_FullURL,(sizeof(sawsurl),sawsurl)); ierr = PetscPrintf(PETSC_COMM_WORLD,"Point your browser to %s for SAWs\n",sawsurl);CHKERRQ(ierr); } } else { PetscStackCallSAWs(SAWs_Initialize,()); } ierr = PetscCitationsRegister("@TechReport{ saws,\n" " Author = {Matt Otten and Jed Brown and Barry Smith},\n" " Title = {Scientific Application Web Server (SAWs) Users Manual},\n" " Institution = {Argonne National Laboratory},\n" " Year = 2013\n}\n",NULL);CHKERRQ(ierr); } PetscFunctionReturn(0); } #endif #if defined(PETSC_HAVE_ADIOS) #include #include int64_t Petsc_adios_group; #endif #if defined(PETSC_HAVE_ADIOS2) #include #endif #if defined(PETSC_HAVE_OPENMP) #include PetscInt PetscNumOMPThreads; #endif /*@C PetscInitialize - Initializes the PETSc database and MPI. PetscInitialize() calls MPI_Init() if that has yet to be called, so this routine should always be called near the beginning of your program -- usually the very first line! Collective on MPI_COMM_WORLD or PETSC_COMM_WORLD if it has been set Input Parameters: + argc - count of number of command line arguments . args - the command line arguments . file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use NULL to not check for code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files - help - [optional] Help message to print, use NULL for no message If you wish PETSc code to run ONLY on a subcommunicator of MPI_COMM_WORLD, create that communicator first and assign it to PETSC_COMM_WORLD BEFORE calling PetscInitialize(). Thus if you are running a four process job and two processes will run PETSc and have PetscInitialize() and PetscFinalize() and two process will not, then do this. If ALL processes in the job are using PetscInitialize() and PetscFinalize() then you don't need to do this, even if different subcommunicators of the job are doing different things with PETSc. Options Database Keys: + -help [intro] - prints help method for each option; if intro is given the program stops after printing the introductory help message . -start_in_debugger [noxterm,dbx,xdb,gdb,...] - Starts program in debugger . -on_error_attach_debugger [noxterm,dbx,xdb,gdb,...] - Starts debugger when error detected . -on_error_emacs - causes emacsclient to jump to error file . -on_error_abort - calls abort() when error detected (no traceback) . -on_error_mpiabort - calls MPI_abort() when error detected . -error_output_stderr - prints error messages to stderr instead of the default stdout . -error_output_none - does not print the error messages (but handles errors in the same way as if this was not called) . -debugger_nodes [node1,node2,...] - Indicates nodes to start in debugger . -debugger_pause [sleeptime] (in seconds) - Pauses debugger . -stop_for_debugger - Print message on how to attach debugger manually to process and wait (-debugger_pause) seconds for attachment . -malloc - Indicates use of PETSc error-checking malloc (on by default for debug version of libraries) . -malloc no - Indicates not to use error-checking malloc . -malloc_debug - check for memory corruption at EVERY malloc or free . -malloc_dump - prints a list of all unfreed memory at the end of the run . -malloc_test - like -malloc_dump -malloc_debug, but only active for debugging builds . -fp_trap - Stops on floating point exceptions (Note that on the IBM RS6000 this slows code by at least a factor of 10.) . -no_signal_handler - Indicates not to trap error signals . -shared_tmp - indicates /tmp directory is shared by all processors . -not_shared_tmp - each processor has own /tmp . -tmp - alternative name of /tmp directory . -get_total_flops - returns total flops done by all processors - -memory_view - Print memory usage at end of run Options Database Keys for Profiling: See Users-Manual: ch_profiling for details. + -info - Prints verbose information to the screen . -info_exclude - Excludes some of the verbose messages . -log_sync - Enable barrier synchronization for all events. This option is useful to debug imbalance within each event, however it slows things down and gives a distorted view of the overall runtime. . -log_trace [filename] - Print traces of all PETSc calls to the screen (useful to determine where a program hangs without running in the debugger). See PetscLogTraceBegin(). . -log_view [:filename:format] - Prints summary of flop and timing information to screen or file, see PetscLogView(). . -log_summary [filename] - (Deprecated, use -log_view) Prints summary of flop and timing information to screen. If the filename is specified the summary is written to the file. See PetscLogView(). . -log_exclude: - excludes subset of object classes from logging . -log_all [filename] - Logs extensive profiling information See PetscLogDump(). . -log [filename] - Logs basic profiline information See PetscLogDump(). . -log_mpe [filename] - Creates a logfile viewable by the utility Jumpshot (in MPICH distribution) . -viewfromoptions on,off - Enable or disable XXXSetFromOptions() calls, for applications with many small solves turn this off - -check_pointer_intensity 0,1,2 - if pointers are checked for validity (debug version only), using 0 will result in faster code Only one of -log_trace, -log_view, -log_view, -log_all, -log, or -log_mpe may be used at a time Options Database Keys for SAWs: + -saws_port - port number to publish SAWs data, default is 8080 . -saws_port_auto_select - have SAWs select a new unique port number where it publishes the data, the URL is printed to the screen this is useful when you are running many jobs that utilize SAWs at the same time . -saws_log - save a log of all SAWs communication . -saws_https - have SAWs use HTTPS instead of HTTP - -saws_root - allow SAWs to have access to the given directory to search for requested resources and files Environmental Variables: + PETSC_TMP - alternative tmp directory . PETSC_SHARED_TMP - tmp is shared by all processes . PETSC_NOT_SHARED_TMP - each process has its own private tmp . PETSC_VIEWER_SOCKET_PORT - socket number to use for socket viewer - PETSC_VIEWER_SOCKET_MACHINE - machine to use for socket viewer to connect to Level: beginner Notes: If for some reason you must call MPI_Init() separately, call it before PetscInitialize(). Fortran Version: In Fortran this routine has the format $ call PetscInitialize(file,ierr) + ierr - error return code - file - [optional] PETSc database file, also checks ~username/.petscrc and .petscrc use PETSC_NULL_CHARACTER to not check for code specific file. Use -skip_petscrc in the code specific file to skip the .petscrc files Important Fortran Note: In Fortran, you MUST use PETSC_NULL_CHARACTER to indicate a null character string; you CANNOT just use NULL as in the C version. See Users-Manual: ch_fortran for details. If your main program is C but you call Fortran code that also uses PETSc you need to call PetscInitializeFortran() soon after calling PetscInitialize(). .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscInitializeNoArguments() @*/ PetscErrorCode PetscInitialize(int *argc,char ***args,const char file[],const char help[]) { PetscErrorCode ierr; PetscMPIInt flag, size; PetscBool flg = PETSC_TRUE; char hostname[256]; PetscFunctionBegin; if (PetscInitializeCalled) PetscFunctionReturn(0); /* The checking over compatible runtime libraries is complicated by the MPI ABI initiative https://wiki.mpich.org/mpich/index.php/ABI_Compatibility_Initiative which started with MPICH v3.1 (Released Feburary 2014) IBM MPI v2.1 (December 2014) IntelĀ® MPI Library v5.0 (2014) Cray MPT v7.0.0 (June 2014) As of July 31, 2017 the ABI number still appears to be 12, that is all of the versions listed above and since that time are compatible. Unfortunately the MPI ABI initiative has not defined a way to determine the ABI number at compile time or runtime. Thus we will need to systematically track the allowed versions and how they are represented in the mpi.h and MPI_Get_library_version() output in order to perform the checking. Currently we only check for pre MPI ABI versions (and packages that do not follow the MPI ABI). Questions: Should the checks for ABI incompatibility be only on the major version number below? Presumably the output to stderr will be removed before a release. */ #if defined(PETSC_HAVE_MPI_GET_LIBRARY_VERSION) { char mpilibraryversion[MPI_MAX_LIBRARY_VERSION_STRING]; PetscMPIInt mpilibraryversionlength; ierr = MPI_Get_library_version(mpilibraryversion,&mpilibraryversionlength);if (ierr) return ierr; /* check for MPICH versions before MPI ABI initiative */ #if defined(MPICH_VERSION) #if MPICH_NUMVERSION < 30100000 { char *ver,*lf; flg = PETSC_FALSE; ierr = PetscStrstr(mpilibraryversion,"MPICH Version:",&ver);if (ierr) return ierr; if (ver) { ierr = PetscStrchr(ver,'\n',&lf);if (ierr) return ierr; if (lf) { *lf = 0; ierr = PetscStrendswith(ver,MPICH_VERSION,&flg);if (ierr) return ierr; } } if (!flg) { fprintf(stderr,"PETSc Error --- MPICH library version \n%s does not match what PETSc was compiled with %s, aborting\n",mpilibraryversion,MPICH_VERSION); return PETSC_ERR_MPI_LIB_INCOMP; } } #endif /* check for OpenMPI version, it is not part of the MPI ABI initiative (is it part of another initiative that needs to be handled?) */ #elif defined(OMPI_MAJOR_VERSION) { char *ver,bs[32],*bsf; flg = PETSC_FALSE; ierr = PetscStrstr(mpilibraryversion,"Open MPI",&ver);if (ierr) return ierr; if (ver) { PetscSNPrintf(bs,32,"v%d.%d",OMPI_MAJOR_VERSION,OMPI_MINOR_VERSION); ierr = PetscStrstr(ver,bs,&bsf);if (ierr) return ierr; if (bsf) flg = PETSC_TRUE; } if (!flg) { fprintf(stderr,"PETSc Error --- Open MPI library version \n%s does not match what PETSc was compiled with %d.%d, aborting\n",mpilibraryversion,OMPI_MAJOR_VERSION,OMPI_MINOR_VERSION); return PETSC_ERR_MPI_LIB_INCOMP; } } #endif } #endif /* these must be initialized in a routine, not as a constant declaration*/ PETSC_STDOUT = stdout; PETSC_STDERR = stderr; /* on Windows - set printf to default to printing 2 digit exponents */ #if defined(PETSC_HAVE__SET_OUTPUT_FORMAT) _set_output_format(_TWO_DIGIT_EXPONENT); #endif ierr = PetscOptionsCreateDefault();CHKERRQ(ierr); /* We initialize the program name here (before MPI_Init()) because MPICH has a bug in it that it sets args[0] on all processors to be args[0] on the first processor. */ if (argc && *argc) { ierr = PetscSetProgramName(**args);CHKERRQ(ierr); } else { ierr = PetscSetProgramName("Unknown Name");CHKERRQ(ierr); } ierr = MPI_Initialized(&flag);CHKERRQ(ierr); if (!flag) { if (PETSC_COMM_WORLD != MPI_COMM_NULL) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You cannot set PETSC_COMM_WORLD if you have not initialized MPI first"); #if defined(PETSC_HAVE_MPI_INIT_THREAD) { PetscMPIInt provided; ierr = MPI_Init_thread(argc,args,MPI_THREAD_FUNNELED,&provided);CHKERRQ(ierr); } #else ierr = MPI_Init(argc,args);CHKERRQ(ierr); #endif PetscBeganMPI = PETSC_TRUE; } if (argc && args) { PetscGlobalArgc = *argc; PetscGlobalArgs = *args; } PetscFinalizeCalled = PETSC_FALSE; ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockOpen);CHKERRQ(ierr); ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockStdout);CHKERRQ(ierr); ierr = PetscSpinlockCreate(&PetscViewerASCIISpinLockStderr);CHKERRQ(ierr); ierr = PetscSpinlockCreate(&PetscCommSpinLock);CHKERRQ(ierr); if (PETSC_COMM_WORLD == MPI_COMM_NULL) PETSC_COMM_WORLD = MPI_COMM_WORLD; ierr = MPI_Comm_set_errhandler(PETSC_COMM_WORLD,MPI_ERRORS_RETURN);CHKERRQ(ierr); ierr = MPI_Add_error_class(&PETSC_MPI_ERROR_CLASS);CHKERRQ(ierr); ierr = MPI_Add_error_code(PETSC_MPI_ERROR_CLASS,&PETSC_MPI_ERROR_CODE);CHKERRQ(ierr); /* Done after init due to a bug in MPICH-GM? */ ierr = PetscErrorPrintfInitialize();CHKERRQ(ierr); ierr = MPI_Comm_rank(MPI_COMM_WORLD,&PetscGlobalRank);CHKERRQ(ierr); ierr = MPI_Comm_size(MPI_COMM_WORLD,&PetscGlobalSize);CHKERRQ(ierr); MPIU_BOOL = MPI_INT; MPIU_ENUM = MPI_INT; MPIU_FORTRANADDR = (sizeof(void*) == sizeof(int)) ? MPI_INT : MPIU_INT64; if (sizeof(size_t) == sizeof(unsigned)) MPIU_SIZE_T = MPI_UNSIGNED; else if (sizeof(size_t) == sizeof(unsigned long)) MPIU_SIZE_T = MPI_UNSIGNED_LONG; #if defined(PETSC_SIZEOF_LONG_LONG) else if (sizeof(size_t) == sizeof(unsigned long long)) MPIU_SIZE_T = MPI_UNSIGNED_LONG_LONG; #endif else {(*PetscErrorPrintf)("PetscInitialize: Could not find MPI type for size_t\n"); return PETSC_ERR_SUP_SYS;} /* Initialized the global complex variable; this is because with shared libraries the constructors for global variables are not called; at least on IRIX. */ #if defined(PETSC_HAVE_COMPLEX) { #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_REAL___FLOAT128) PetscComplex ic(0.0,1.0); PETSC_i = ic; #else PETSC_i = _Complex_I; #endif } #if !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU_C_DOUBLE_COMPLEX);CHKERRQ(ierr); ierr = MPI_Type_contiguous(2,MPI_FLOAT,&MPIU_C_COMPLEX);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU_C_COMPLEX);CHKERRQ(ierr); #endif #endif /* PETSC_HAVE_COMPLEX */ /* Create the PETSc MPI reduction operator that sums of the first half of the entries and maxes the second half. */ ierr = MPI_Op_create(MPIU_MaxSum_Local,1,&MPIU_MAXSUM_OP);CHKERRQ(ierr); #if defined(PETSC_USE_REAL___FLOAT128) ierr = MPI_Type_contiguous(2,MPI_DOUBLE,&MPIU___FLOAT128);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU___FLOAT128);CHKERRQ(ierr); #if defined(PETSC_HAVE_COMPLEX) ierr = MPI_Type_contiguous(4,MPI_DOUBLE,&MPIU___COMPLEX128);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU___COMPLEX128);CHKERRQ(ierr); #endif ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX);CHKERRQ(ierr); ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN);CHKERRQ(ierr); #elif defined(PETSC_USE_REAL___FP16) ierr = MPI_Type_contiguous(2,MPI_CHAR,&MPIU___FP16);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU___FP16);CHKERRQ(ierr); ierr = MPI_Op_create(PetscMax_Local,1,&MPIU_MAX);CHKERRQ(ierr); ierr = MPI_Op_create(PetscMin_Local,1,&MPIU_MIN);CHKERRQ(ierr); #endif #if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16) ierr = MPI_Op_create(PetscSum_Local,1,&MPIU_SUM);CHKERRQ(ierr); #endif ierr = MPI_Type_contiguous(2,MPIU_SCALAR,&MPIU_2SCALAR);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU_2SCALAR);CHKERRQ(ierr); #if defined(PETSC_USE_64BIT_INDICES) ierr = MPI_Type_contiguous(2,MPIU_INT,&MPIU_2INT);CHKERRQ(ierr); ierr = MPI_Type_commit(&MPIU_2INT);CHKERRQ(ierr); #endif /* Attributes to be set on PETSc communicators */ ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_DelCounter,&Petsc_Counter_keyval,(void*)0);CHKERRQ(ierr); ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_DelComm_Outer,&Petsc_InnerComm_keyval,(void*)0);CHKERRQ(ierr); ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_DelComm_Inner,&Petsc_OuterComm_keyval,(void*)0);CHKERRQ(ierr); ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_DelComm_Shm,&Petsc_ShmComm_keyval,(void*)0);CHKERRQ(ierr); /* Build the options database */ ierr = PetscOptionsInsert(NULL,argc,args,file);CHKERRQ(ierr); /* call a second time so it can look in the options database */ ierr = PetscErrorPrintfInitialize();CHKERRQ(ierr); /* Print main application help message */ ierr = PetscOptionsHasHelp(NULL,&flg);CHKERRQ(ierr); if (help && flg) { ierr = PetscPrintf(PETSC_COMM_WORLD,help);CHKERRQ(ierr); } ierr = PetscOptionsCheckInitial_Private();CHKERRQ(ierr); ierr = PetscCitationsInitialize();CHKERRQ(ierr); #if defined(PETSC_HAVE_SAWS) ierr = PetscInitializeSAWs(help);CHKERRQ(ierr); #endif /* Creates the logging data structures; this is enabled even if logging is not turned on */ #if defined(PETSC_USE_LOG) ierr = PetscLogInitialize();CHKERRQ(ierr); #endif /* Load the dynamic libraries (on machines that support them), this registers all the solvers etc. (On non-dynamic machines this initializes the PetscDraw and PetscViewer classes) */ ierr = PetscInitialize_DynamicLibraries();CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); ierr = PetscInfo1(0,"PETSc successfully started: number of processors = %d\n",size);CHKERRQ(ierr); ierr = PetscGetHostName(hostname,256);CHKERRQ(ierr); ierr = PetscInfo1(0,"Running on machine: %s\n",hostname);CHKERRQ(ierr); #if defined(PETSC_HAVE_OPENMP) { PetscBool omp_view_flag; char *threads = getenv("OMP_NUM_THREADS"); if (threads) { ierr = PetscInfo1(0,"Number of OpenMP threads %s (given by OMP_NUM_THREADS)\n",threads);CHKERRQ(ierr); (void) sscanf(threads, "%" PetscInt_FMT,&PetscNumOMPThreads); } else { #define NMAX 10000 int i; PetscScalar *x; ierr = PetscMalloc1(NMAX,&x);CHKERRQ(ierr); #pragma omp parallel for for (i=0; i