34 #ifdef LIBMESH_ENABLE_EXCEPTIONS 38 #ifdef LIBMESH_HAVE_OPENMP 46 #ifdef LIBMESH_HAVE_FENV_H 49 #ifdef LIBMESH_HAVE_XMMINTRIN_H 50 # include <xmmintrin.h> 54 #if defined(LIBMESH_HAVE_MPI) 58 #endif // #if defined(LIBMESH_HAVE_MPI) 60 #if defined(LIBMESH_HAVE_PETSC) 63 # include <petscerror.h> 64 #if !PETSC_RELEASE_LESS_THAN(3,3,0) 67 # if defined(LIBMESH_HAVE_SLEPC) 73 # endif // #if defined(LIBMESH_HAVE_SLEPC) 74 #endif // #if defined(LIBMESH_HAVE_PETSC) 78 #if defined(LIBMESH_HAVE_MPI) && defined(LIBMESH_HAVE_VTK) 80 # include "vtkMPIController.h" 88 std::unique_ptr<GetPot> command_line;
89 std::unique_ptr<std::ofstream> _ofstream;
93 std::streambuf * out_buf (
nullptr);
94 std::streambuf * err_buf (
nullptr);
96 std::unique_ptr<libMesh::Threads::task_scheduler_init> task_scheduler;
97 #if defined(LIBMESH_HAVE_MPI) 98 bool libmesh_initialized_mpi =
false;
100 #if defined(LIBMESH_HAVE_PETSC) 101 bool libmesh_initialized_petsc =
false;
103 #if defined(LIBMESH_HAVE_SLEPC) 104 bool libmesh_initialized_slepc =
false;
112 #if LIBMESH_HAVE_DECL_SIGACTION 113 void libmesh_handleFPE(
int , siginfo_t * info,
void * )
117 switch (info->si_code)
119 case FPE_INTDIV:
libMesh::err <<
"integer divide by zero";
break;
120 case FPE_INTOVF:
libMesh::err <<
"integer overflow";
break;
121 case FPE_FLTDIV:
libMesh::err <<
"floating point divide by zero";
break;
122 case FPE_FLTOVF:
libMesh::err <<
"floating point overflow";
break;
123 case FPE_FLTUND:
libMesh::err <<
"floating point underflow";
break;
124 case FPE_FLTRES:
libMesh::err <<
"floating point inexact result";
break;
125 case FPE_FLTINV:
libMesh::err <<
"invalid floating point operation";
break;
126 case FPE_FLTSUB:
libMesh::err <<
"subscript out of range";
break;
131 libmesh_error_msg(
"\nTo track this down, compile in debug mode, then in gdb do:\n" \
132 <<
" break libmesh_handleFPE\n" \
138 void libmesh_handleSEGV(
int , siginfo_t * info,
void * )
141 libMesh::err <<
"Segmentation fault exception signaled (";
142 switch (info->si_code)
144 case SEGV_MAPERR:
libMesh::err <<
"Address not mapped";
break;
145 case SEGV_ACCERR:
libMesh::err <<
"Invalid permissions";
break;
150 libmesh_error_msg(
"\nTo track this down, compile in debug mode, then in gdb do:\n" \
151 <<
" break libmesh_handleSEGV\n" \
160 #ifdef LIBMESH_HAVE_MPI 163 libmesh_not_implemented();
178 namespace libMeshPrivateData {
194 #ifdef LIBMESH_HAVE_MPI 206 #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING
216 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 232 #ifdef LIBMESH_HAVE_MPI 241 #if defined(LIBMESH_HAVE_PETSC) // PETSc is the default 243 #elif defined(LIBMESH_TRILINOS_HAVE_AZTECOO) // Use Trilinos if PETSc isn't there 245 #elif defined(LIBMESH_HAVE_EIGEN) // Use Eigen if neither are there 247 #elif defined(LIBMESH_HAVE_LASPACK) // Use LASPACK as a last resort 249 #else // No valid linear solver package at compile time 271 #ifdef LIBMESH_ENABLE_EXCEPTIONS 311 #if defined(LIBMESH_HAVE_MPI) 313 MPI_Initialized (&mpi_initialized);
328 #ifndef LIBMESH_HAVE_MPI 332 MPI_Comm COMM_WORLD_IN)
339 command_line.reset (
new GetPot (argc, argv));
360 #if !LIBMESH_USING_THREADS 364 libmesh_warning(
"Warning: You requested --n-threads>1 but no threading model is active!\n" 365 <<
"Forcing --n-threads==1 instead!");
370 #ifdef LIBMESH_HAVE_OPENMP 384 #if defined(LIBMESH_HAVE_MPI) 392 libmesh_call_mpi(MPI_Initialized (&flag));
396 int mpi_thread_provided;
398 MPI_THREAD_FUNNELED :
402 (MPI_Init_thread (&argc, const_cast<char ***>(&argv),
403 mpi_thread_requested, &mpi_thread_provided));
406 (mpi_thread_provided < MPI_THREAD_FUNNELED))
408 libmesh_warning(
"Warning: MPI failed to guarantee MPI_THREAD_FUNNELED\n" 409 <<
"for a threaded run.\n" 410 <<
"Be sure your library is funneled-thread-safe..." 426 libmesh_initialized_mpi =
true;
432 this->_comm = COMM_WORLD_IN;
440 cast_int<processor_id_type>(this->comm().rank());
442 cast_int<processor_id_type>(this->comm().size());
464 libmesh_parallel_only(this->comm());
468 #if defined(LIBMESH_HAVE_PETSC) 473 #
if defined(LIBMESH_HAVE_MPI)
488 ierr = PetscInitialized(&petsc_already_initialized);
490 if (petsc_already_initialized != PETSC_TRUE)
491 libmesh_initialized_petsc =
true;
492 # if defined(LIBMESH_HAVE_SLEPC) 499 if (!SlepcInitializeCalled)
501 ierr = SlepcInitialize (&argc, const_cast<char ***>(&argv),
nullptr,
nullptr);
503 libmesh_initialized_slepc =
true;
506 if (libmesh_initialized_petsc)
508 ierr = PetscInitialize (&argc, const_cast<char ***>(&argv),
nullptr,
nullptr);
512 #if !PETSC_RELEASE_LESS_THAN(3,3,0) 514 #if PETSC_RELEASE_LESS_THAN(3,4,0) 524 #if defined(LIBMESH_HAVE_MPI) && defined(LIBMESH_HAVE_VTK) 526 _vtk_mpi_controller = vtkMPIController::New();
527 _vtk_mpi_controller->Initialize(&argc, const_cast<char ***>(&argv), 1);
528 _vtk_mpi_controller->SetGlobalController(_vtk_mpi_controller);
540 command_line.reset (
new GetPot (argc, argv));
548 std::ios::sync_with_stdio(
false);
559 std::ostream * newout =
new std::ostream(std::cout.rdbuf());
561 std::ostream * newerr =
new std::ostream(std::cerr.rdbuf());
572 if (cmdline_has_redirect_stdout)
573 libmesh_warning(
"The --redirect-stdout command line option has been deprecated. " 574 "Use '--redirect-output basename' instead.");
580 if (cmdline_has_redirect_stdout || cmdline_has_redirect_output)
582 std::string basename =
"stdout";
585 if (cmdline_has_redirect_output)
588 command_line->search(1,
"--redirect-output");
591 std::string next_string =
"";
592 next_string = command_line->next(next_string);
597 if (next_string.size() > 0 && next_string.find_first_of(
"-") != 0)
598 basename = next_string;
601 std::ostringstream filename;
603 _ofstream.reset (
new std::ofstream (filename.str().c_str()));
630 #ifdef LIBMESH_ENABLE_EXCEPTIONS 676 task_scheduler.reset();
693 #if !defined(LIBMESH_ENABLE_REFERENCE_COUNTING) || defined(NDEBUG) 695 libMesh::err <<
"Compile in DEBUG mode with --enable-reference-counting" 697 <<
"for more information" 737 #ifdef LIBMESH_ENABLE_EXCEPTIONS 747 #if defined(LIBMESH_HAVE_PETSC) 750 #
if defined(LIBMESH_HAVE_MPI)
755 # if defined(LIBMESH_HAVE_SLEPC) 756 if (libmesh_initialized_slepc)
759 if (libmesh_initialized_petsc)
765 #if defined(LIBMESH_HAVE_MPI) && defined(LIBMESH_HAVE_VTK) 770 #if defined(LIBMESH_HAVE_MPI) 776 if (libmesh_initialized_mpi)
780 unsigned int error_code = MPI_Finalize();
781 if (error_code != MPI_SUCCESS)
783 char error_string[MPI_MAX_ERROR_STRING+1];
784 int error_string_len;
785 MPI_Error_string(error_code, error_string,
787 std::cerr <<
"Failure from MPI_Finalize():\n" 788 << error_string << std::endl;
802 #if !defined(LIBMESH_HAVE_FEENABLEEXCEPT) && defined(LIBMESH_HAVE_XMMINTRIN_H) && !defined(__SUNPRO_CC) 803 static int flags = 0;
808 #ifdef LIBMESH_HAVE_FEENABLEEXCEPT 809 feenableexcept(FE_DIVBYZERO | FE_INVALID);
810 #elif LIBMESH_HAVE_XMMINTRIN_H 812 flags = _MM_GET_EXCEPTION_MASK();
813 _MM_SET_EXCEPTION_MASK(flags & ~_MM_MASK_INVALID);
817 #if LIBMESH_HAVE_DECL_SIGACTION 818 struct sigaction new_action, old_action;
821 new_action.sa_sigaction = libmesh_handleFPE;
822 sigemptyset (&new_action.sa_mask);
823 new_action.sa_flags = SA_SIGINFO;
825 sigaction (SIGFPE,
nullptr, &old_action);
826 if (old_action.sa_handler != SIG_IGN)
827 sigaction (SIGFPE, &new_action,
nullptr);
832 #ifdef LIBMESH_HAVE_FEDISABLEEXCEPT 833 fedisableexcept(FE_DIVBYZERO | FE_INVALID);
834 #elif LIBMESH_HAVE_XMMINTRIN_H 836 _MM_SET_EXCEPTION_MASK(flags);
839 signal(SIGFPE, SIG_DFL);
848 #if LIBMESH_HAVE_DECL_SIGACTION 849 static struct sigaction old_action;
850 static bool was_on =
false;
854 struct sigaction new_action;
858 new_action.sa_sigaction = libmesh_handleSEGV;
859 sigemptyset (&new_action.sa_mask);
860 new_action.sa_flags = SA_SIGINFO;
862 sigaction (SIGSEGV, &new_action, &old_action);
867 sigaction (SIGSEGV, &old_action,
nullptr);
870 libmesh_error_msg(
"System call sigaction not supported.");
879 libmesh_assert(command_line.get());
882 libmesh_assert(!arg.empty());
884 bool found_it = command_line->search(arg);
889 std::replace(arg.begin(), arg.end(),
'_',
'-');
890 found_it = command_line->search(arg);
896 auto name_begin = arg.begin();
897 while (*name_begin ==
'-')
899 std::replace(name_begin, arg.end(),
'-',
'_');
900 found_it = command_line->search(arg);
908 template <
typename T>
912 libmesh_assert(command_line.get());
915 if (command_line->have_variable(
name.c_str()))
921 template <
typename T>
925 libmesh_assert(command_line.get());
928 for (
const auto & entry :
name)
929 if (command_line->have_variable(entry.c_str()))
931 value = (*command_line)(entry.c_str(),
value);
940 template <
typename T>
946 return command_line->next(
value);
953 template <
typename T>
957 libmesh_assert(command_line.get());
960 if (command_line->have_variable(
name.c_str()))
962 unsigned size = command_line->vector_variable_size(
name.c_str());
965 for (
unsigned i=0; i<size; ++i)
966 vec[i] = (*command_line)(
name.c_str(), vec[i], i);
975 static bool called =
false;
983 #ifdef LIBMESH_HAVE_PETSC 988 #ifdef LIBMESH_TRILINOS_HAVE_AZTECOO 994 #ifdef LIBMESH_HAVE_EIGEN 996 #
if defined(LIBMESH_HAVE_MPI)
1005 #ifdef LIBMESH_HAVE_LASPACK 1007 #
if defined(LIBMESH_HAVE_MPI)
1020 #
if defined(LIBMESH_HAVE_MPI)
1042 template std::string command_line_value<std::string> (
const std::string &, std::string);
1051 template std::string command_line_value<std::string> (
const std::vector<std::string> &, std::string);
1060 template std::string command_line_next<std::string> (std::string, std::string);
std::string name(const ElemQuality q)
template float command_line_next< float >(std::string, float)
template unsigned short command_line_next< unsigned short >(std::string, unsigned short)
static unsigned int n_objects()
template int command_line_next< int >(std::string, int)
processor_id_type _n_processors
Parallel::Communicator _comm
template void command_line_vector< long double >(const std::string &, std::vector< long double > &)
bool warned_about_auto_ptr
uint8_t processor_id_type
template unsigned int command_line_next< unsigned int >(std::string, unsigned int)
MPI_Comm GLOBAL_COMM_WORLD
void reset(streamT &target)
vtkMPIController * _vtk_mpi_controller
template int command_line_value< int >(const std::string &, int)
PerfLog perflog("libMesh", #ifdef LIBMESH_ENABLE_PERFORMANCE_LOGGING true #else false #endif)
const Parallel::Communicator & comm() const
SolverPackage default_solver_package()
Responsible for timing and summarizing events.
template double command_line_next< double >(std::string, double)
template unsigned short command_line_value< unsigned short >(const std::string &, unsigned short)
LibMeshInit(int argc, const char *const *argv, MPI_Comm COMM_WORLD_IN=MPI_COMM_WORLD)
PetscErrorCode DMCreate_libMesh(DM dm)
template void command_line_vector< float >(const std::string &, std::vector< float > &)
template void command_line_vector< int >(const std::string &, std::vector< int > &)
std::terminate_handler old_terminate_handler
processor_id_type _processor_id
OStreamProxy err(std::cerr)
T command_line_next(std::string name, T value)
template void command_line_vector< unsigned short >(const std::string &, std::vector< unsigned short > &)
static void print_info(std::ostream &out=libMesh::out)
template void command_line_vector< unsigned int >(const std::string &, std::vector< unsigned int > &)
streambufT * rdbuf() const
MPI_Errhandler libmesh_errhandler
template unsigned int command_line_value< unsigned int >(const std::string &, unsigned int)
void command_line_vector(const std::string &name, std::vector< T > &vec)
processor_id_type global_processor_id()
template void command_line_vector< double >(const std::string &, std::vector< double > &)
template float command_line_value< float >(const std::string &, float)
void libMesh_MPI_Handler(MPI_Comm *, int *,...)
bool on_command_line(std::string arg)
template long double command_line_value< long double >(const std::string &, long double)
template void command_line_vector< short >(const std::string &, std::vector< short > &)
T command_line_value(const std::string &name, T value)
template short command_line_value< short >(const std::string &, short)
template double command_line_value< double >(const std::string &, double)
template long double command_line_next< long double >(std::string, long double)
static void disable_print_counter_info()
OStreamProxy out(std::cout)
SolverPackage _solver_package
template short command_line_next< short >(std::string, short)
void libmesh_terminate_handler()
const RemoteElem * remote_elem