diff --git a/src/Algorithm/LinearSolvers/IpMumpsSolverInterface.cpp b/src/Algorithm/LinearSolvers/IpMumpsSolverInterface.cpp index fb26a5bcb..51adb371f 100644 --- a/src/Algorithm/LinearSolvers/IpMumpsSolverInterface.cpp +++ b/src/Algorithm/LinearSolvers/IpMumpsSolverInterface.cpp @@ -92,13 +92,7 @@ MumpsSolverInterface::MumpsSolverInterface() DBG_START_METH("MumpsSolverInterface::MumpsSolverInterface()", dbg_verbosity); - //initialize mumps - MUMPS_STRUC_C* mumps_ = static_cast(calloc(1, sizeof(MUMPS_STRUC_C))); - mumps_->job = -1; //initialize mumps - mumps_->par = 1; //working host for sequential version - mumps_->sym = 2; //general symmetric matrix - - mumps_ptr_ = (void*) mumps_; + mumps_ptr_ = NULL; } MumpsSolverInterface::~MumpsSolverInterface() @@ -106,6 +100,9 @@ MumpsSolverInterface::~MumpsSolverInterface() DBG_START_METH("MumpsSolverInterface::~MumpsSolverInterface()", dbg_verbosity); + if( mumps_ptr_ == NULL ) + return; + #ifndef IPOPT_MUMPS_NOMUTEX const std::lock_guard lock(mumps_call_mutex); #endif @@ -217,27 +214,42 @@ bool MumpsSolverInterface::InitializeImpl( options.GetIntegerValue("mumps_scaling", mumps_scaling_, prefix); options.GetNumericValue("mumps_dep_tol", mumps_dep_tol_, prefix); - MUMPS_STRUC_C* mumps_ = static_cast(mumps_ptr_); + // Reset all private data + initialized_ = false; + pivtol_changed_ = false; + refactorize_ = false; + have_symbolic_factorization_ = false; + + // allocate and initialize MUMPS, if not done before + MUMPS_STRUC_C* mumps_; + if( mumps_ptr_ == NULL ) + { + mumps_ = static_cast(calloc(1, sizeof(MUMPS_STRUC_C))); + + mumps_->job = -1; //initialize mumps + mumps_->par = 1; //working host for sequential version + mumps_->sym = 2; //general symmetric matrix - Index mpi_comm; + Index mpi_comm; #ifndef COIN_USE_MUMPS_MPI_H - options.GetIntegerValue("mumps_mpi_communicator", mpi_comm, prefix); + options.GetIntegerValue("mumps_mpi_communicator", mpi_comm, prefix); #else - mpi_comm = USE_COMM_WORLD; + mpi_comm = USE_COMM_WORLD; #endif - mumps_->comm_fortran = static_cast(mpi_comm); + mumps_->comm_fortran = static_cast(mpi_comm); #ifndef IPOPT_MUMPS_NOMUTEX - const std::lock_guard lock(mumps_call_mutex); + const std::lock_guard lock(mumps_call_mutex); #endif - mumps_c(mumps_); + mumps_c(mumps_); - // Reset all private data - initialized_ = false; - pivtol_changed_ = false; - refactorize_ = false; - have_symbolic_factorization_ = false; + mumps_ptr_ = (void*) mumps_; + } + else + { + mumps_ = static_cast(mumps_ptr_); + } if( !warm_start_same_structure_ ) {