20 #include "libmesh/libmesh.h" 23 #include "libmesh/getpot.h" 24 #include "libmesh/reference_counter.h" 25 #include "libmesh/libmesh_singleton.h" 26 #include "libmesh/remote_elem.h" 27 #include "libmesh/threads.h" 28 #include "libmesh/parallel_only.h" 29 #include "libmesh/print_trace.h" 30 #include "libmesh/enum_solver_package.h" 31 #include "libmesh/perf_log.h" 32 #include "libmesh/thread_buffered_syncbuf.h" 43 #ifdef LIBMESH_ENABLE_EXCEPTIONS 48 #ifdef LIBMESH_HAVE_OPENMP 55 #if defined(LIBMESH_HAVE_MPI) 56 # include "libmesh/ignore_warnings.h" 58 # include "libmesh/restore_warnings.h" 59 #endif // #if defined(LIBMESH_HAVE_MPI) 61 #if defined(LIBMESH_HAVE_PETSC) 62 # include "libmesh/petsc_solver_exception.h" 64 # include <petscerror.h> 65 # include "libmesh/petscdmlibmesh.h" 66 # if defined(LIBMESH_HAVE_SLEPC) 68 # include "libmesh/ignore_warnings.h" 69 # include "libmesh/slepc_macro.h" 71 # include "libmesh/restore_warnings.h" 72 # endif // #if defined(LIBMESH_HAVE_SLEPC) 73 #endif // #if defined(LIBMESH_HAVE_PETSC) 75 #ifdef LIBMESH_HAVE_NETGEN 82 #include "netgen/nglib/nglib.h" 88 #if defined(LIBMESH_HAVE_MPI) && defined(LIBMESH_HAVE_VTK) 89 #include "libmesh/ignore_warnings.h" 90 # include "vtkMPIController.h" 91 #include "libmesh/restore_warnings.h" 94 #ifdef PETSC_HAVE_UMPIRE 95 #include "umpire/util/io.hpp" 104 std::unique_ptr<GetPot> command_line;
106 std::set<std::string> command_line_name_set;
108 std::unique_ptr<std::ofstream> _ofstream;
112 std::streambuf * out_buf (
nullptr);
113 std::streambuf * err_buf (
nullptr);
115 std::unique_ptr<libMesh::Threads::task_scheduler_init> task_scheduler;
116 #if defined(LIBMESH_HAVE_PETSC) 117 bool libmesh_initialized_petsc =
false;
119 #if defined(LIBMESH_HAVE_SLEPC) 120 bool libmesh_initialized_slepc =
false;
127 #ifdef LIBMESH_HAVE_MPI 130 libmesh_not_implemented();
145 namespace libMeshPrivateData {
161 #ifdef LIBMESH_HAVE_MPI 167 #ifdef LIBMESH_ENABLE_EXCEPTIONS 183 auto check_stored_buffer = [](
const auto *
const libmesh_dbg_var(stored_buffer)) {
184 libmesh_assert_msg(!stored_buffer,
185 "Oops, we've already stored a prewrapped buffer. We must be calling this " 186 "function a second time in which case we're going to lose the already " 187 "stored prewrapped buffer forever");
196 std::make_unique<ThreadBufferedSyncbuf>(*ob,
true);
206 std::make_unique<ThreadBufferedSyncbuf>(*eb,
true);
226 #ifdef PETSC_HAVE_UMPIRE 233 umpire::util::finalize_io();
273 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
281 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 297 #ifdef LIBMESH_HAVE_MPI 307 #if defined(LIBMESH_HAVE_PETSC) // PETSc is the default 309 #elif defined(LIBMESH_TRILINOS_HAVE_AZTECOO) // Use Trilinos if PETSc isn't there 311 #elif defined(LIBMESH_HAVE_EIGEN) // Use Eigen if neither are there 313 #elif defined(LIBMESH_HAVE_LASPACK) // Use LASPACK as a last resort 315 #else // No valid linear solver package at compile time 350 #if defined(LIBMESH_HAVE_MPI) 352 MPI_Initialized (&mpi_initialized);
358 #ifdef LIBMESH_ENABLE_EXCEPTIONS 377 command_line = std::make_unique<GetPot>(argc, argv);
385 auto check_empty_command_line_value = [](
auto & cl,
const std::string & option) {
386 libmesh_error_msg_if(cl.search(option),
387 "Detected option " << option <<
" with no value. Did you forget '='?");
396 std::vector<std::string> n_threads_opt(2);
397 n_threads_opt[0] =
"--n_threads";
398 n_threads_opt[1] =
"--n-threads";
404 for (
auto & option : n_threads_opt)
405 check_empty_command_line_value(*command_line, option);
411 #if !LIBMESH_USING_THREADS 415 libmesh_warning(
"Warning: You requested --n-threads>1 but no threading model is active!\n" 416 <<
"Forcing --n-threads==1 instead!");
421 #ifdef LIBMESH_HAVE_OPENMP 425 task_scheduler = std::make_unique<Threads::task_scheduler_init>(
libMesh::n_threads());
442 const bool handle_mpi_errors =
false;
444 #if defined(LIBMESH_HAVE_MPI) 449 int mpi_thread_request = using_threads;
451 if (mpi_thread_type.empty())
453 check_empty_command_line_value(*command_line,
"--mpi-thread-type");
454 #if defined(PETSC_HAVE_STRUMPACK) && defined(PETSC_HAVE_SLATE) 461 mpi_thread_request = 3;
466 if (mpi_thread_type ==
"single")
469 libmesh_error_msg(
"We are using threads, so we require more mpi thread support " 470 "than '--mpi-thread-type=single'");
471 mpi_thread_request = 0;
473 else if (mpi_thread_type ==
"funneled")
474 mpi_thread_request = 1;
475 else if (mpi_thread_type ==
"serialized")
476 mpi_thread_request = 2;
477 else if (mpi_thread_type ==
"multiple")
478 mpi_thread_request = 3;
481 "Unsupported mpi thread type '" 483 <<
"'. Allowed options are 'single', 'funneled', 'serialized', and 'multiple'");
488 handle_mpi_errors, COMM_WORLD_IN);
491 const std::string timpi_sync =
501 cast_int<processor_id_type>(this->
comm().
rank());
503 cast_int<processor_id_type>(this->
comm().
size());
525 libmesh_parallel_only(this->
comm());
535 #if defined(LIBMESH_HAVE_PETSC) 540 #if defined(LIBMESH_HAVE_MPI) 548 #ifdef LIBMESH_HAVE_MPI 552 this->
_comm->
get() = PETSC_COMM_SELF;
557 PetscBool petsc_already_initialized;
559 if (petsc_already_initialized != PETSC_TRUE)
560 libmesh_initialized_petsc =
true;
561 # if defined(LIBMESH_HAVE_SLEPC) 568 if (!SlepcInitializeCalled)
571 libmesh_initialized_slepc =
true;
574 if (libmesh_initialized_petsc)
582 #ifdef LIBMESH_HAVE_NETGEN 586 #if defined(LIBMESH_HAVE_MPI) && defined(LIBMESH_HAVE_VTK) 602 command_line = std::make_unique<GetPot>(argc, argv);
615 std::ios::sync_with_stdio(
false);
626 std::ostream * newout =
new std::ostream(std::cout.rdbuf());
628 std::ostream * newerr =
new std::ostream(std::cerr.rdbuf());
639 if (cmdline_has_redirect_stdout)
640 libmesh_warning(
"The --redirect-stdout command line option has been deprecated. " 641 "Use '--redirect-output basename' instead.");
647 if (cmdline_has_redirect_stdout || cmdline_has_redirect_output)
649 std::string basename =
"stdout";
652 if (cmdline_has_redirect_output)
655 command_line->search(1,
"--redirect-output");
658 std::string next_string =
"";
659 next_string = command_line->next(next_string);
664 if (next_string.size() > 0 && next_string.find_first_of(
"-") != 0)
665 basename = next_string;
668 std::ostringstream filename;
670 _ofstream = std::make_unique<std::ofstream>(filename.str().c_str());
701 #ifdef LIBMESH_ENABLE_EXCEPTIONS 717 #if defined(LIBMESH_HAVE_HDF5) && !defined(_MSC_VER) 730 setenv(
"HDF5_USE_FILE_LOCKING",
"FALSE", 0);
731 #endif // LIBMESH_HAVE_HDF5 760 #ifdef LIBMESH_ENABLE_EXCEPTIONS 761 if (!std::uncaught_exceptions())
773 task_scheduler.reset();
797 #if !defined(LIBMESH_ENABLE_REFERENCE_COUNTING) || defined(NDEBUG) 799 libMesh::err <<
"Compile in DEBUG mode with --enable-reference-counting" 801 <<
"for more information" 824 #ifdef LIBMESH_ENABLE_EXCEPTIONS 830 #ifdef LIBMESH_HAVE_NETGEN 837 #if defined(LIBMESH_HAVE_PETSC) 842 for (
const auto &
name : cli_names)
843 if (!
name.empty() &&
name[0] ==
'-')
848 PetscBool used = PETSC_FALSE;
849 auto ierr = PetscOptionsUsed(NULL,
name.c_str(), &used);
851 if (used == PETSC_FALSE)
853 ierr = PetscOptionsClearValue(NULL,
name.c_str());
860 #
if defined(LIBMESH_HAVE_MPI)
865 PetscErrorCode ierr = LIBMESH_PETSC_SUCCESS;
866 # if defined(LIBMESH_HAVE_SLEPC) 867 if (libmesh_initialized_slepc)
868 ierr = SlepcFinalize();
870 if (libmesh_initialized_petsc)
871 ierr = PetscFinalize();
877 #if defined(LIBMESH_HAVE_MPI) && defined(LIBMESH_HAVE_VTK) 884 #if defined(LIBMESH_HAVE_MPI) 908 static std::mutex command_line_names_mutex;
909 std::scoped_lock lock(command_line_names_mutex);
911 command_line_name_set.insert(
name);
918 for (
auto & getter : {&GetPot::get_requested_arguments,
919 &GetPot::get_requested_variables,
920 &GetPot::get_requested_sections})
921 for (
const std::string &
name : (getpot.*getter)())
928 return std::vector<std::string>(command_line_name_set.begin(),
929 command_line_name_set.end());
940 if (!command_line.get())
946 bool found_it = command_line->search(arg);
951 std::replace(arg.begin(), arg.end(),
'_',
'-');
952 found_it = command_line->search(arg);
958 auto name_begin = arg.begin();
959 while (*name_begin ==
'-')
961 std::replace(name_begin, arg.end(),
'-',
'_');
962 found_it = command_line->search(arg);
970 template <
typename T>
977 if (command_line->have_variable(
name))
985 const std::string stringvalue =
986 (*command_line)(
name, std::string());
993 template <
typename T>
1000 for (
const auto & entry : names)
1006 const std::string stringvalue =
1007 (*command_line)(entry, std::string());
1012 for (
const auto & entry : names)
1013 if (command_line->have_variable(entry))
1024 template <
typename T>
1036 return command_line->next(
value);
1043 template <
typename T>
1053 if (command_line->have_variable(
name))
1055 unsigned size = command_line->vector_variable_size(
name);
1058 for (
unsigned i=0; i<size; ++i)
1059 vec[i] = (*command_line)(
name, vec[i], i);
1068 static bool called =
false;
1076 #ifdef LIBMESH_HAVE_PETSC 1081 #ifdef LIBMESH_TRILINOS_HAVE_AZTECOO 1087 #ifdef LIBMESH_HAVE_EIGEN 1089 #
if defined(LIBMESH_HAVE_MPI)
1098 #ifdef LIBMESH_HAVE_LASPACK 1100 #
if defined(LIBMESH_HAVE_MPI)
1113 #
if defined(LIBMESH_HAVE_MPI)
1137 template LIBMESH_EXPORT std::string command_line_value<std::string> (
const std::string &, std::string);
1148 template LIBMESH_EXPORT std::string command_line_value<std::string> (
const std::vector<std::string> &, std::string);
1159 template LIBMESH_EXPORT std::string command_line_next<std::string> (std::string, std::string);
1171 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION template LIBMESH_EXPORT Real command_line_value< Real >(const std::string &, Real)
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
template LIBMESH_EXPORT double command_line_value< double >(const std::string &, double)
unsigned int _default_grainsize
Minimum number of elements/nodes/indices per thread above which we can split work onto more threads...
std::unique_ptr< ThreadBufferedSyncbuf > _err_syncd_thread_buffer
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line...
template LIBMESH_EXPORT char command_line_value< char >(const std::string &, char)
bool closed()
Checks that the library has been closed.
void install_thread_buffered_sync()
friend void libmesh_terminate_handler()
A terminate handler.
static unsigned int n_objects()
Prints the number of outstanding (created, but not yet destroyed) objects.
std::streambuf * _out_prewrap_buf
template LIBMESH_EXPORT float command_line_next< float >(std::string, float)
template LIBMESH_EXPORT void command_line_vector< long double >(const std::string &, std::vector< long double > &)
void sync_type(const SyncType st)
LibMeshInit(int argc, const char *const *argv, MPI_Comm COMM_WORLD_IN=MPI_COMM_WORLD, int n_threads=-1)
Initialize the library for use, with the command line options provided.
template LIBMESH_EXPORT long double command_line_value< long double >(const std::string &, long double)
void enableSEGV(bool on)
Toggle libMesh reporting of segmentation faults.
template LIBMESH_EXPORT unsigned char command_line_next< unsigned char >(std::string, unsigned char)
processor_id_type _n_processors
Total number of processors used.
bool warned_about_auto_ptr
template LIBMESH_EXPORT void command_line_vector< unsigned char >(const std::string &, std::vector< unsigned char > &)
processor_id_type rank() const
PerfLog perflog
A PerfLog object to log performance.
template LIBMESH_EXPORT void command_line_vector< unsigned int >(const std::string &, std::vector< unsigned int > &)
static void print_info(std::ostream &out_stream=libMesh::out)
Prints the reference information, by default to libMesh::out.
template LIBMESH_EXPORT Real command_line_next< Real >(std::string, Real)
MPI_Comm GLOBAL_COMM_WORLD
MPI Communicator used to initialize libMesh.
template LIBMESH_EXPORT float command_line_value< float >(const std::string &, float)
The libMesh namespace provides an interface to certain functionality in the library.
void reset(streamT &target)
Reset the proxy to point to a different target.
int _n_threads
Total number of threads possible.
vtkMPIController * _vtk_mpi_controller
static void setup()
Setup function.
EXTERN_C_BEGIN PETSC_EXTERN PetscErrorCode DMCreate_libMesh(DM)
uint8_t processor_id_type
const Number imaginary
The imaginary unit, .
const Parallel::Communicator & comm() const
Returns a Communicator created from the TIMPIInit object we hold, which will be a compatibility shim ...
SolverPackage default_solver_package()
The PerfLog class allows monitoring of specific events.
processor_id_type size() const
template LIBMESH_EXPORT void command_line_vector< int >(const std::string &, std::vector< int > &)
void libmesh_ignore(const Args &...)
std::unique_ptr< ThreadBufferedSyncbuf > _out_syncd_thread_buffer
T command_line_value(const std::string &, T)
template LIBMESH_EXPORT void command_line_vector< double >(const std::string &, std::vector< double > &)
static void enable_print_counter_info()
Methods to enable/disable the reference counter output from print_info().
bool _is_initialized
Flag that tells if init() has been called.
template LIBMESH_EXPORT unsigned int command_line_next< unsigned int >(std::string, unsigned int)
template LIBMESH_EXPORT int command_line_next< int >(std::string, int)
template LIBMESH_EXPORT void command_line_vector< short >(const std::string &, std::vector< short > &)
void cleanup_stream_buffers()
Helper to do cleanup from both destructor and terminate.
virtual ~LibMeshInit()
Destructor.
template LIBMESH_EXPORT int command_line_value< int >(const std::string &, int)
template LIBMESH_EXPORT unsigned char command_line_value< unsigned char >(const std::string &, unsigned char)
template LIBMESH_EXPORT double command_line_next< double >(std::string, double)
processor_id_type _processor_id
The local processor id.
void libmesh_abort()
Abort as soon as possible.
template LIBMESH_EXPORT unsigned short command_line_next< unsigned short >(std::string, unsigned short)
template LIBMESH_EXPORT unsigned int command_line_value< unsigned int >(const std::string &, unsigned int)
BasicOStreamProxy OStreamProxy
template LIBMESH_EXPORT void command_line_vector< unsigned short >(const std::string &, std::vector< unsigned short > &)
template LIBMESH_EXPORT short command_line_value< short >(const std::string &, short)
std::streambuf * _err_prewrap_buf
template LIBMESH_EXPORT short command_line_next< short >(std::string, short)
static PerfLog & perf_log()
streambufT * rdbuf() const
Get the associated stream buffer.
template LIBMESH_EXPORT unsigned short command_line_value< unsigned short >(const std::string &, unsigned short)
MPI_Errhandler libmesh_errhandler
TIMPI::TIMPIInit * _timpi_init
void clear()
Clears all the internal data and restores the data structures to a pristine state.
void enableFPE(bool on)
Toggle hardware trap floating point exceptions.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void add_command_line_names(const GetPot &getpot)
Merge a GetPot object's requested names into the set of queried command-line names.
void add_command_line_name(const std::string &name)
Add a name to the set of queried command-line names.
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator
void command_line_vector(const std::string &, std::vector< T > &)
std::vector< std::string > command_line_names()
processor_id_type global_processor_id()
void print_log() const
Print the log.
void enableSIGINT(bool on)
Toggle libMesh handling of SIGINT (Ctrl+C) interrupts.
bool initialized()
Checks that library initialization has been done.
void libMesh_MPI_Handler(MPI_Comm *, int *,...)
streamT * get()
Rather than implement every ostream/ios/ios_base function, we'll be lazy and make esoteric uses go th...
template LIBMESH_EXPORT void command_line_vector< char >(const std::string &, std::vector< char > &)
static void cleanup()
Cleanup function.
bool on_command_line(std::string arg)
SolverPackage
Defines an enum for various linear solver packages.
template LIBMESH_EXPORT char command_line_next< char >(std::string, char)
static void disable_print_counter_info()
SolverPackage _solver_package
The default solver package to use.
static std::terminate_handler _old_terminate_handler
template LIBMESH_EXPORT void command_line_vector< float >(const std::string &, std::vector< float > &)
template LIBMESH_EXPORT long double command_line_next< long double >(std::string, long double)
void uninstall_thread_buffered_sync()
void ErrorVector unsigned int
const Communicator & comm() const
template LIBMESH_EXPORT void command_line_vector< Real >(const std::string &, std::vector< Real > &)
Parallel::Communicator * _comm
const RemoteElem * remote_elem