From: Alberto Sartori Date: Wed, 4 Oct 2017 10:04:57 +0000 (+0200) Subject: fix sundials interface for NON-MPI installations X-Git-Tag: v9.0.0-rc1~988^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a48e8b11de23abdf304c5a5a38bdcde0d7b9ad0c;p=dealii.git fix sundials interface for NON-MPI installations --- diff --git a/cmake/modules/FindSUNDIALS.cmake b/cmake/modules/FindSUNDIALS.cmake index cad258d87e..bddb8c8d51 100644 --- a/cmake/modules/FindSUNDIALS.cmake +++ b/cmake/modules/FindSUNDIALS.cmake @@ -79,8 +79,6 @@ IF(DEAL_II_WITH_MPI) PATH_SUFFIXES lib${LIB_SUFFIX} lib64 lib ) SET(_sundials_additional_libs SUNDIALS_LIB_PAR) -ENDIF() - DEAL_II_PACKAGE_HANDLE(SUNDIALS LIBRARIES REQUIRED SUNDIALS_LIB_IDA SUNDIALS_LIB_ARKODE SUNDIALS_LIB_KINSOL SUNDIALS_LIB_SER SUNDIALS_LIB_PAR @@ -89,5 +87,19 @@ DEAL_II_PACKAGE_HANDLE(SUNDIALS USER_INCLUDE_DIRS REQUIRED SUNDIALS_INCLUDE_DIR CLEAR SUNDIALS_LIB_IDA SUNDIALS_LIB_ARKODE SUNDIALS_LIB_KINSOL - SUNDIALS_LIB_SER SUNDIALS_LIB_PAR SUN_INC + SUNDIALS_LIB_SER SUNDIALS_LIB_PAR ) +ELSE() +DEAL_II_PACKAGE_HANDLE(SUNDIALS + LIBRARIES REQUIRED + SUNDIALS_LIB_IDA SUNDIALS_LIB_ARKODE SUNDIALS_LIB_KINSOL SUNDIALS_LIB_SER + ${_sundials_additional_libs} + INCLUDE_DIRS REQUIRED SUNDIALS_INCLUDE_DIR + USER_INCLUDE_DIRS REQUIRED SUNDIALS_INCLUDE_DIR + CLEAR + SUNDIALS_LIB_IDA SUNDIALS_LIB_ARKODE SUNDIALS_LIB_KINSOL + SUNDIALS_LIB_SER + ) + +ENDIF() + diff --git a/include/deal.II/sundials/arkode.h b/include/deal.II/sundials/arkode.h index 5877e64dd2..c8b90f4115 100644 --- a/include/deal.II/sundials/arkode.h +++ b/include/deal.II/sundials/arkode.h @@ -17,6 +17,7 @@ #define dealii_sundials_arkode_h #include +#include #ifdef DEAL_II_WITH_SUNDIALS #include @@ -36,6 +37,9 @@ #include #include #include +#ifdef DEAL_II_WITH_MPI +#include +#endif #include #include @@ -360,7 +364,7 @@ namespace SUNDIALS maximum_non_linear_iterations(maximum_non_linear_iterations), implicit_function_is_linear(implicit_function_is_linear), implicit_function_is_time_independent(implicit_function_is_time_independent) - {}; + {} /** * Add all AdditionalData() parameters to the given ParameterHandler @@ -487,6 +491,9 @@ namespace SUNDIALS * passing an AdditionalData() object that sets all of the solver * parameters. * + * The MPI communicator is simply ignored in the serial case. + * + * * @param data ARKode configuration data * @param mpi_comm MPI communicator */ @@ -851,12 +858,12 @@ namespace SUNDIALS */ N_Vector abs_tolls; -#ifdef DEAL_II_WITH_MPI /** - * MPI communicator. SUNDIALS solver runs happily in parallel. + * MPI communicator. SUNDIALS solver runs happily in + * parallel. Note that if the library is compiled without MPI + * support, MPI_Comm is typedefed as int. */ MPI_Comm communicator; -#endif /** * Memory pool of vectors. diff --git a/include/deal.II/sundials/copy.h b/include/deal.II/sundials/copy.h index b4e25b37f9..3b1994b003 100644 --- a/include/deal.II/sundials/copy.h +++ b/include/deal.II/sundials/copy.h @@ -20,18 +20,23 @@ #ifdef DEAL_II_WITH_SUNDIALS #include +#ifdef DEAL_II_WITH_MPI #include +#endif #include #include #include +#ifdef DEAL_II_WITH_TRILINOS #include #include +#endif +#ifdef DEAL_II_WITH_PETSC #include #include - +#endif DEAL_II_NAMESPACE_OPEN namespace SUNDIALS diff --git a/include/deal.II/sundials/ida.h b/include/deal.II/sundials/ida.h index 38bddded39..f13fe1be1a 100644 --- a/include/deal.II/sundials/ida.h +++ b/include/deal.II/sundials/ida.h @@ -17,6 +17,7 @@ #define dealii_sundials_ida_h #include +#include #ifdef DEAL_II_WITH_SUNDIALS #include @@ -328,7 +329,7 @@ namespace SUNDIALS maximum_non_linear_iterations_ic(maximum_non_linear_iterations_ic), maximum_non_linear_iterations(maximum_non_linear_iterations), use_local_tolerances(use_local_tolerances) - {}; + {} /** * Add all AdditionalData() parameters to the given ParameterHandler @@ -562,6 +563,8 @@ namespace SUNDIALS * consistent. Then you can choose how these are made consistent, using the same three * options that you used for the initial conditions in `reset_type`. * + * The MPI communicator is simply ignored in the serial case. + * * @param data IDA configuration data * @param mpi_comm MPI communicator */ @@ -804,12 +807,12 @@ namespace SUNDIALS */ N_Vector diff_id; -#ifdef DEAL_II_WITH_MPI /** - * MPI communicator. SUNDIALS solver runs happily in parallel. + * MPI communicator. SUNDIALS solver runs happily in + * parallel. Note that if the library is compiled without MPI + * support, MPI_Comm is typedefed as int. */ MPI_Comm communicator; -#endif /** * Memory pool of vectors. diff --git a/source/sundials/arkode.cc b/source/sundials/arkode.cc index b6a6dad4e8..abd5d307c6 100644 --- a/source/sundials/arkode.cc +++ b/source/sundials/arkode.cc @@ -208,7 +208,8 @@ namespace SUNDIALS } template - ARKode::ARKode(const AdditionalData &data, const MPI_Comm mpi_comm) : + ARKode::ARKode(const AdditionalData &data, + const MPI_Comm mpi_comm) : data(data), arkode_mem(nullptr), communicator(Utilities::MPI::duplicate_communicator(mpi_comm)) @@ -221,7 +222,9 @@ namespace SUNDIALS { if (arkode_mem) ARKodeFree(&arkode_mem); +#ifdef DEAL_II_WITH_MPI MPI_Comm_free(&communicator); +#endif } @@ -231,7 +234,6 @@ namespace SUNDIALS { unsigned int system_size = solution.size(); - unsigned int local_system_size = system_size; double t = data.initial_time; double h = data.initial_step_size; @@ -246,8 +248,8 @@ namespace SUNDIALS #ifdef DEAL_II_WITH_MPI if (is_serial_vector::value == false) { - IndexSet is = solution.locally_owned_elements(); - local_system_size = is.n_elements(); + const IndexSet is = solution.locally_owned_elements(); + const size_t local_system_size = is.n_elements(); yy = N_VNew_Parallel(communicator, local_system_size, @@ -320,7 +322,6 @@ namespace SUNDIALS { unsigned int system_size; - unsigned int local_system_size; if (arkode_mem) ARKodeFree(&arkode_mem); @@ -350,8 +351,8 @@ namespace SUNDIALS #ifdef DEAL_II_WITH_MPI if (is_serial_vector::value == false) { - IndexSet is = solution.locally_owned_elements(); - local_system_size = is.n_elements(); + const IndexSet is = solution.locally_owned_elements(); + const size_t local_system_size = is.n_elements(); yy = N_VNew_Parallel(communicator, local_system_size, diff --git a/source/sundials/copy.cc b/source/sundials/copy.cc index 767c7f625e..0dd6eb6089 100644 --- a/source/sundials/copy.cc +++ b/source/sundials/copy.cc @@ -42,11 +42,13 @@ namespace SUNDIALS length = NV_LENGTH_S(vec); break; } +#ifdef DEAL_II_WITH_MPI case SUNDIALS_NVEC_PARALLEL: { length = NV_LOCLENGTH_P(vec); break; } +#endif default: Assert(false, ExcNotImplemented()); } @@ -62,9 +64,10 @@ namespace SUNDIALS void copy(TrilinosWrappers::MPI::Vector &dst, const N_Vector &src) { - IndexSet is = dst.locally_owned_elements(); - AssertDimension(is.n_elements(), N_Vector_length(src)); - for (unsigned int i=0; i &dst, const N_Vector &src) { - AssertDimension(N_Vector_length(src), dst.size()); - for (unsigned int i=0; i &src) { - AssertDimension(N_Vector_length(dst), src.size()); - for (unsigned int i=0; i &dst, const N_Vector &src) { - AssertDimension(N_Vector_length(src), dst.size()); - for (unsigned int i=0; i &src) { - AssertDimension(N_Vector_length(dst), src.size()); - for (unsigned int i=0; i - IDA::IDA(const AdditionalData &data, const MPI_Comm mpi_comm) : + IDA::IDA(const AdditionalData &data, + const MPI_Comm mpi_comm) : data(data), ida_mem(nullptr), communicator(Utilities::MPI::duplicate_communicator(mpi_comm)) @@ -151,7 +152,9 @@ namespace SUNDIALS { if (ida_mem) IDAFree(&ida_mem); +#ifdef DEAL_II_WITH_MPI MPI_Comm_free(&communicator); +#endif } @@ -162,7 +165,6 @@ namespace SUNDIALS { unsigned int system_size = solution.size(); - unsigned int local_system_size = system_size; double t = data.initial_time; double h = data.initial_step_size; @@ -177,8 +179,8 @@ namespace SUNDIALS #ifdef DEAL_II_WITH_MPI if (is_serial_vector::value == false) { - IndexSet is = solution.locally_owned_elements(); - local_system_size = is.n_elements(); + const IndexSet is = solution.locally_owned_elements(); + const size_t local_system_size = is.n_elements(); yy = N_VNew_Parallel(communicator, local_system_size, @@ -266,7 +268,6 @@ namespace SUNDIALS { unsigned int system_size; - unsigned int local_system_size; bool first_step = (current_time == data.initial_time); if (ida_mem) @@ -302,8 +303,8 @@ namespace SUNDIALS #ifdef DEAL_II_WITH_MPI if (is_serial_vector::value == false) { - IndexSet is = solution.locally_owned_elements(); - local_system_size = is.n_elements(); + const IndexSet is = solution.locally_owned_elements(); + const size_t local_system_size = is.n_elements(); yy = N_VNew_Parallel(communicator, local_system_size,