diff --git a/.gitignore b/.gitignore index faa269899..ba4be7dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -91,6 +91,7 @@ examples/fullCovarianceRandomCoefficient examples/blockDiagonalCovarianceRandomCoefficients examples/4d_interp examples/4d_interp_read +examples/example_SharedPtr src/core/inc/queso.h src/libqueso.la @@ -206,3 +207,10 @@ test/test_InterpolationSurrogateHelper test/test_build_InterpolationSurrogateBuilder test/test_write_InterpolationSurrogateBuilder_1.dat test/test_write_InterpolationSurrogateBuilder_2.dat +test/output_test_optimizer_options +test/test_optimizer/input_test_optimizer_options +test/test_optimizer_options +test/test_SharedPtr +test/output_test_serialEnv +test/test_Environment/input_test_serialEnv +test/test_serialEnv diff --git a/.travis.yml b/.travis.yml index 4faf0838b..c0d1ce08b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,9 @@ before_script: - sudo apt-get install -q build-essential - sudo apt-get install -q libgsl0-dev - sudo apt-get install -q openmpi-bin openmpi-dev - - sudo apt-get install -q libboost-all-dev -script: ./bootstrap && CC="mpicc" CXX="mpicxx" ./configure && make -j2 && make check + - sudo apt-get install -q libboost-dev libboost-math-dev libboost-program-options-dev +script: + - ./bootstrap + - ./configure CC="mpicc" CXX="mpicxx" + - make -j4 + - make check -j4 diff --git a/CHANGES b/CHANGES index a3951f628..be1920e46 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,16 @@ QUESO: Quantification of Uncertainty for Estimation, Simulation, and Optimization. ----------------------------------------------------- +Version 0.54.0 + * Fix memory leak in test_GslVector + * Make MPI optional + * Optimise GSLMatrix::operator() and GslVector::operator[] + * Add 'txt' file output option + * Add SharedPtr + * Add input file options for optimisation and monitoring + * Fix some compiler warnings + * Fix HDF5 #include issues + Version 0.53.0 * Add linear interpolation surrogates * Refactor input options processing diff --git a/configure.ac b/configure.ac index ede3b25d6..8e2d95948 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.65) -AC_INIT([queso], [0.53.1], [queso-users@googlegroups.com]) +AC_INIT([queso], [0.54.0], [queso-users@googlegroups.com]) PACKAGE_DESCRIPTION="The parallel C++ statistical library QUESO: Quantification of uncertainty for estimation, simulation and optimization" AC_SUBST([PACKAGE_DESCRIPTION]) PACKAGE_URL="https://github.com/libqueso/queso" @@ -75,17 +75,37 @@ else AC_MSG_RESULT(no) fi +############################################# +# Check if the user explicitly disabled mpi # +############################################# +AC_ARG_ENABLE(mpi, + AS_HELP_STRING([--disable-mpi], + [build without message passing support]), + [enable_mpi=no], + [enable_mpi=yes]) + #------------------- # Compilers and MPI #------------------- - AC_PROG_CC AC_PROG_CXX AC_PROG_FC AC_LANG([C]) -ACX_MPI([CC="$MPICC"], [AC_MSG_ERROR([Could not find MPI.])]) + +HAVE_MPI=0 +if test "x$enable_mpi" = "xyes"; then + ACX_MPI(CC="$MPICC", [AC_MSG_ERROR([Could not find MPI.])]) + HAVE_MPI=1 +fi + AC_LANG([C++]) -ACX_MPI([CXX="$MPICXX"], [AC_MSG_ERROR([Could not find MPI.])]) + +if test "x$enable_mpi" = "xyes"; then + ACX_MPI(CXX="$MPICXX", [AC_MSG_ERROR([Could not find MPI.])]) + HAVE_MPI=1 +fi +AC_SUBST(HAVE_MPI) +AM_CONDITIONAL(MPI_ENABLED, test x$HAVE_MPI = x1) #------------------------- # External Library Checks @@ -124,6 +144,7 @@ AC_LANG([C++]) BOOST_REQUIRE([1.35]) BOOST_PROGRAM_OPTIONS BOOST_FIND_HEADER([boost/scoped_ptr.hpp]) +BOOST_FIND_HEADER([boost/shared_ptr.hpp]) AC_CACHE_SAVE # Check for GLPK (optional) @@ -218,6 +239,8 @@ AC_CONFIG_FILES([ test/test_InputOptionsParser/test_options_good.txt test/test_InputOptionsParser/test_options_bad.txt test/test_InputOptionsParser/test_options_default.txt + test/test_optimizer/input_test_optimizer_options + test/test_Environment/input_test_serialEnv ]) AC_CONFIG_FILES([test/test_Regression/test_cobra_samples_diff.sh diff --git a/examples/Makefile.am b/examples/Makefile.am index a0451662b..f742beb3d 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -436,6 +436,20 @@ dist_interpsurrg_DATA += ${4d_interp_read_SOURCES} dist_interpsurrg_DATA += interpolation_surrogate/input.in dist_interpsurrg_DATA += interpolation_surrogate/4d_interp_data_coarse.dat +##################### +# SharedPtr example # +##################### +pointersdir = $(prefix)/examples/pointers + +pointers_PROGRAMS = example_SharedPtr + +example_SharedPtr_SOURCES = pointers/example_SharedPtr.C +example_SharedPtr_LDADD = $(top_builddir)/src/libqueso.la +example_SharedPtr_CPPFLAGS = $(QUESO_CPPFLAGS) + +dist_pointers_DATA = +dist_pointers_DATA += ${example_SharedPtr_SOURCES} + if CODE_COVERAGE_ENABLED CLEANFILES = *.gcda *.gcno endif diff --git a/examples/bimodal/src/bimodal_likelihood.C b/examples/bimodal/src/bimodal_likelihood.C index ddd688a5a..c82cda427 100644 --- a/examples/bimodal/src/bimodal_likelihood.C +++ b/examples/bimodal/src/bimodal_likelihood.C @@ -76,7 +76,7 @@ double likelihoodRoutine( if (paramValues.env().exceptionalCircumstance()) { if ((paramValues.env().subDisplayFile() ) && - (paramValues.env().displayVerbosity() >= 0)) { // detailed output debug + (paramValues.env().displayVerbosity() > 0)) { // detailed output debug *paramValues.env().subDisplayFile() << "Leaving likelihood function" << ": paramValues = " << paramValues << ", returnValue = " << returnValue diff --git a/examples/bimodal/src/bimodal_main.C b/examples/bimodal/src/bimodal_main.C index ba71f7035..bee46c4e8 100644 --- a/examples/bimodal/src/bimodal_main.C +++ b/examples/bimodal/src/bimodal_main.C @@ -27,14 +27,20 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute compute(*env); // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gaussian_likelihoods/blockDiagonalCovariance.C b/examples/gaussian_likelihoods/blockDiagonalCovariance.C index 55ecd5f1b..c916f401b 100644 --- a/examples/gaussian_likelihoods/blockDiagonalCovariance.C +++ b/examples/gaussian_likelihoods/blockDiagonalCovariance.C @@ -60,9 +60,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -121,7 +124,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gaussian_likelihoods/blockDiagonalCovarianceRandomCoefficients.C b/examples/gaussian_likelihoods/blockDiagonalCovarianceRandomCoefficients.C index 480f3b5e5..68a20833d 100644 --- a/examples/gaussian_likelihoods/blockDiagonalCovarianceRandomCoefficients.C +++ b/examples/gaussian_likelihoods/blockDiagonalCovarianceRandomCoefficients.C @@ -60,9 +60,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif // Need 3 dims because two are for the hyperparameters QUESO::VectorSpace paramSpace(env, @@ -127,7 +130,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gaussian_likelihoods/diagonalCovariance.C b/examples/gaussian_likelihoods/diagonalCovariance.C index af27f2ee1..9c559aa11 100644 --- a/examples/gaussian_likelihoods/diagonalCovariance.C +++ b/examples/gaussian_likelihoods/diagonalCovariance.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -116,7 +119,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gaussian_likelihoods/fullCovariance.C b/examples/gaussian_likelihoods/fullCovariance.C index 3d157b8ee..ece16beb1 100644 --- a/examples/gaussian_likelihoods/fullCovariance.C +++ b/examples/gaussian_likelihoods/fullCovariance.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -118,7 +121,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gaussian_likelihoods/fullCovarianceRandomCoefficient.C b/examples/gaussian_likelihoods/fullCovarianceRandomCoefficient.C index 9dda05692..d9c9413cb 100644 --- a/examples/gaussian_likelihoods/fullCovarianceRandomCoefficient.C +++ b/examples/gaussian_likelihoods/fullCovarianceRandomCoefficient.C @@ -65,16 +65,16 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 2, NULL); - double min_val = 0.0; - double max_val = 1.0; - QUESO::GslVector paramMins(paramSpace.zeroVector()); QUESO::GslVector paramMaxs(paramSpace.zeroVector()); @@ -131,7 +131,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gaussian_likelihoods/scalarCovariance.C b/examples/gaussian_likelihoods/scalarCovariance.C index e97c4bcd0..1267bbf7d 100644 --- a/examples/gaussian_likelihoods/scalarCovariance.C +++ b/examples/gaussian_likelihoods/scalarCovariance.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -111,7 +114,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gp/scalar/gpmsa_scalar.C b/examples/gp/scalar/gpmsa_scalar.C index c8c447089..15ad47eea 100644 --- a/examples/gp/scalar/gpmsa_scalar.C +++ b/examples/gp/scalar/gpmsa_scalar.C @@ -98,10 +98,14 @@ int main(int argc, char ** argv) { unsigned int numEta = 1; // Number of responses the model is returning unsigned int experimentSize = 1; // Size of each experiment +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); // Step 1: Set up QUESO environment QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif // Step 2: Set up prior for calibration parameters QUESO::VectorSpace paramSpace(env, @@ -283,7 +287,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/gravity/src/gravity_main.C b/examples/gravity/src/gravity_main.C index 4bbcb026c..9a9bf01c9 100644 --- a/examples/gravity/src/gravity_main.C +++ b/examples/gravity/src/gravity_main.C @@ -49,16 +49,23 @@ int main(int argc, char* argv[]) { // Initialize QUESO environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = + new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Call application computeGravityAndTraveledDistance(*env); // Finalize QUESO environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/hysteretic/src/example_main.C b/examples/hysteretic/src/example_main.C index ee5eaa787..1ecd8d419 100644 --- a/examples/hysteretic/src/example_main.C +++ b/examples/hysteretic/src/example_main.C @@ -35,9 +35,14 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = + new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute #if 1 @@ -48,7 +53,9 @@ int main(int argc, char* argv[]) // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/infinite_dim/gaussian_fields/gaussian_random_field.C b/examples/infinite_dim/gaussian_fields/gaussian_random_field.C index 39cae1e3a..6b4535d6a 100644 --- a/examples/infinite_dim/gaussian_fields/gaussian_random_field.C +++ b/examples/infinite_dim/gaussian_fields/gaussian_random_field.C @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/examples/infinite_dim/gaussian_fields/gaussian_random_field_genmesh.C b/examples/infinite_dim/gaussian_fields/gaussian_random_field_genmesh.C index 805205d4c..75dd1adef 100644 --- a/examples/infinite_dim/gaussian_fields/gaussian_random_field_genmesh.C +++ b/examples/infinite_dim/gaussian_fields/gaussian_random_field_genmesh.C @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/examples/infinite_dim/inverse_problem.C b/examples/infinite_dim/inverse_problem.C index 558ccf6ff..255643154 100644 --- a/examples/infinite_dim/inverse_problem.C +++ b/examples/infinite_dim/inverse_problem.C @@ -2,10 +2,6 @@ #include #include -// GSL includes -#include -#include - // Boost includes #include @@ -20,6 +16,7 @@ #include // QUESO includes +#include #include #include #include @@ -28,6 +25,10 @@ #include #include +// GSL includes +#include +#include + // The likelihood object subclass class Likelihood : public QUESO::InfiniteDimensionalLikelihoodBase { diff --git a/examples/infinite_dim/parallel_inverse_problem.C b/examples/infinite_dim/parallel_inverse_problem.C index e7f889351..844327dd0 100644 --- a/examples/infinite_dim/parallel_inverse_problem.C +++ b/examples/infinite_dim/parallel_inverse_problem.C @@ -3,10 +3,6 @@ #include #include -// GSL includes -#include -#include - // Boost includes #include @@ -23,6 +19,7 @@ #include // QUESO includes +#include #include #include #include @@ -31,6 +28,10 @@ #include #include +// GSL includes +#include +#include + // The likelihood object subclass class Likelihood : public QUESO::InfiniteDimensionalLikelihoodBase { diff --git a/examples/interpolation_surrogate/4d_interp.C b/examples/interpolation_surrogate/4d_interp.C index 5c41ddae6..44e5eeda7 100644 --- a/examples/interpolation_surrogate/4d_interp.C +++ b/examples/interpolation_surrogate/4d_interp.C @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -62,8 +63,12 @@ int main(int argc, char ** argv) } std::string filename = argv[1]; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, filename.c_str(), "", NULL); +#else + QUESO::FullEnvironment env(filename.c_str(), "", NULL); +#endif // Define the parameter space. It's 4-dimensional in this example. QUESO::VectorSpace @@ -166,10 +171,12 @@ int main(int argc, char ** argv) << "======================================" << std::endl; } - MPI_Barrier(MPI_COMM_WORLD); + env.fullComm().Barrier(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/interpolation_surrogate/4d_interp_read.C b/examples/interpolation_surrogate/4d_interp_read.C index c90eb4740..08e7d5178 100644 --- a/examples/interpolation_surrogate/4d_interp_read.C +++ b/examples/interpolation_surrogate/4d_interp_read.C @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -38,8 +39,12 @@ int main(int argc, char ** argv) } std::string filename = argv[1]; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, filename.c_str(), "", NULL); +#else + QUESO::FullEnvironment env(filename.c_str(), "", NULL); +#endif // We will read in the previously computed interpolation data QUESO::InterpolationSurrogateIOASCII @@ -82,10 +87,12 @@ int main(int argc, char ** argv) << "======================================" << std::endl; } - MPI_Barrier(MPI_COMM_WORLD); + env.fullComm().Barrier(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/pointers/example_SharedPtr.C b/examples/pointers/example_SharedPtr.C new file mode 100644 index 000000000..8aef4646d --- /dev/null +++ b/examples/pointers/example_SharedPtr.C @@ -0,0 +1,42 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// QUESO - a library to support the Quantification of Uncertainty +// for Estimation, Simulation and Optimization +// +// Copyright (C) 2008-2015 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include +#include + +int main(int argc, char* argv[]) +{ + QUESO::SharedPtr::Type int_ptr1(new int(1)); + + QUESO::SharedPtr::Type int_ptr2(int_ptr1); + + *int_ptr2 = 2; + + std::cout << "*int_ptr1 is: " << *int_ptr1 << std::endl; + std::cout << "*int_ptr2 is: " << *int_ptr2 << std::endl; + + queso_require_equal_to_msg(*int_ptr1, 2, "pointed-to values are not equal!"); + + return 0; +} diff --git a/examples/simpleStatisticalForwardProblem/src/simple_sfp_example_main.C b/examples/simpleStatisticalForwardProblem/src/simple_sfp_example_main.C index 285b3b87b..0d51c8d06 100644 --- a/examples/simpleStatisticalForwardProblem/src/simple_sfp_example_main.C +++ b/examples/simpleStatisticalForwardProblem/src/simple_sfp_example_main.C @@ -27,19 +27,26 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); UQ_FATAL_TEST_MACRO(argc != 2, QUESO::UQ_UNAVAILABLE_RANK, "main()", "input file must be specified in command line as argv[1], just after executable argv[0]"); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = + new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute compute(*env); // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/simpleStatisticalInverseProblem/src/example_main.C b/examples/simpleStatisticalInverseProblem/src/example_main.C index 4eddb1098..6d1bc44bc 100644 --- a/examples/simpleStatisticalInverseProblem/src/example_main.C +++ b/examples/simpleStatisticalInverseProblem/src/example_main.C @@ -27,6 +27,7 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); UQ_FATAL_TEST_MACRO(argc != 2, @@ -35,13 +36,18 @@ int main(int argc, char* argv[]) "input file must be specified in command line as argv[1], just after executable argv[0]"); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute compute(*env); // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/validationCycle/src/exTgaValidationCycle_gsl.C b/examples/validationCycle/src/exTgaValidationCycle_gsl.C index 6707e2f4d..05da9f6e7 100644 --- a/examples/validationCycle/src/exTgaValidationCycle_gsl.C +++ b/examples/validationCycle/src/exTgaValidationCycle_gsl.C @@ -62,7 +62,9 @@ int main(int argc, char* argv[]) //************************************************ // Initialize environment //************************************************ +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); +#endif QUESO::EnvOptionsValues* envOptionsValues = NULL; #ifdef UQ_EXAMPLES_USES_QUESO_INPUT_FILE @@ -70,7 +72,11 @@ int main(int argc, char* argv[]) QUESO::UQ_UNAVAILABLE_RANK, "main()", "input file must be specified in command line as argv[1], just after executable argv[0]"); +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",envOptionsValues); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",envOptionsValues); +#endif #else envOptionsValues = new QUESO::EnvOptionsValues(); @@ -80,7 +86,11 @@ int main(int argc, char* argv[]) envOptionsValues->m_displayVerbosity = 2; envOptionsValues->m_seed = 0; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"","",envOptionsValues); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment("","",envOptionsValues); +#endif #endif //************************************************ @@ -97,6 +107,8 @@ int main(int argc, char* argv[]) //************************************************ delete env; delete envOptionsValues; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/examples/validationCycle2/src/tga2_gsl.C b/examples/validationCycle2/src/tga2_gsl.C index 7cfb5dfcb..a2fba79bf 100644 --- a/examples/validationCycle2/src/tga2_gsl.C +++ b/examples/validationCycle2/src/tga2_gsl.C @@ -31,6 +31,7 @@ int main(int argc, char* argv[]) //************************************************ // Initialize environment //************************************************ +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); UQ_FATAL_TEST_MACRO(argc != 2, @@ -38,6 +39,9 @@ int main(int argc, char* argv[]) "main()", "input file must be specified in command line as argv[1], just after executable argv[0]"); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",NULL); +#endif //************************************************ // Run application @@ -48,6 +52,8 @@ int main(int argc, char* argv[]) // Finalize environment //************************************************ delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/inc/queso/Makefile.am b/inc/queso/Makefile.am index 81811cbb0..d450c2401 100644 --- a/inc/queso/Makefile.am +++ b/inc/queso/Makefile.am @@ -60,6 +60,7 @@ BUILT_SOURCES += RngBase.h BUILT_SOURCES += RngBoost.h BUILT_SOURCES += RngGsl.h BUILT_SOURCES += ScopedPtr.h +BUILT_SOURCES += SharedPtr.h BUILT_SOURCES += TeuchosMatrix.h BUILT_SOURCES += TeuchosVector.h BUILT_SOURCES += Vector.h @@ -306,6 +307,8 @@ RngGsl.h: $(top_srcdir)/src/core/inc/RngGsl.h $(AM_V_GEN)rm -f $@ && $(LN_S) $< $@ ScopedPtr.h: $(top_srcdir)/src/core/inc/ScopedPtr.h $(AM_V_GEN)rm -f $@ && $(LN_S) $< $@ +SharedPtr.h: $(top_srcdir)/src/core/inc/SharedPtr.h + $(AM_V_GEN)rm -f $@ && $(LN_S) $< $@ TeuchosMatrix.h: $(top_srcdir)/src/core/inc/TeuchosMatrix.h $(AM_V_GEN)rm -f $@ && $(LN_S) $< $@ TeuchosVector.h: $(top_srcdir)/src/core/inc/TeuchosVector.h diff --git a/m4/common/acx_mpi.m4 b/m4/common/acx_mpi.m4 index bb2cb3132..2c292b91f 100644 --- a/m4/common/acx_mpi.m4 +++ b/m4/common/acx_mpi.m4 @@ -176,6 +176,7 @@ if test x = x"$MPILIBS"; then : else ifelse([$1],,[AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.])],[$1]) + AC_DEFINE(HAVE_MPI,1,[Define if you have the MPI library.]) : fi ])dnl ACX_MPI diff --git a/m4/config_summary.m4 b/m4/config_summary.m4 index 7582004b0..d3a6d4007 100644 --- a/m4/config_summary.m4 +++ b/m4/config_summary.m4 @@ -43,6 +43,12 @@ echo Optional Features: # Optional Features Enabled? +if test "$HAVE_MPI" = "1"; then + echo ' 'Link with MPI.............. : yes +else + echo ' 'Link with MPI.............. : no +fi + if test "$HAVE_GRVY" = "0"; then echo ' 'Link with GRVY............. : no else diff --git a/src/Makefile.am b/src/Makefile.am index c31c5b4ee..cba4bf411 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -323,6 +323,7 @@ libqueso_include_HEADERS += core/inc/InfiniteDimensionalLikelihoodBase.h libqueso_include_HEADERS += core/inc/FunctionOperatorBuilder.h libqueso_include_HEADERS += core/inc/GslBlockMatrix.h libqueso_include_HEADERS += core/inc/ScopedPtr.h +libqueso_include_HEADERS += core/inc/SharedPtr.h # Headers to install from misc/inc diff --git a/src/basic/inc/ScalarSequence.h b/src/basic/inc/ScalarSequence.h index 7ad8569dc..b679cba4a 100644 --- a/src/basic/inc/ScalarSequence.h +++ b/src/basic/inc/ScalarSequence.h @@ -486,6 +486,15 @@ class ScalarSequence /*! This routine deletes all stored computed scalars. */ void copy (const ScalarSequence& src); + //! Helper function to write header info for matlab files from all chains + void writeUnifiedMatlabHeader(std::ofstream & ofs, double sequenceSize) const; + + //! Helper function to write header info for matlab files from one chain + void writeSubMatlabHeader(std::ofstream & ofs, double sequenceSize) const; + + //! Helper function to write txt info for matlab files + void writeTxtHeader(std::ofstream & ofs, double sequenceSize) const; + //! Extracts a sequence of scalars. /*! The sequence of scalars has size \c numPos, and it will be extracted starting at position * (\c initialPos) of \c this sequence of scalars, given spacing \c spacing.*/ diff --git a/src/basic/inc/SequenceOfVectors.h b/src/basic/inc/SequenceOfVectors.h index 49e73454c..e5559bd64 100644 --- a/src/basic/inc/SequenceOfVectors.h +++ b/src/basic/inc/SequenceOfVectors.h @@ -411,6 +411,21 @@ class SequenceOfVectors : public BaseVectorSequence unsigned int paramId, std::vector& rawData) const; + //! Helper function to write matlab-specific header info for vectors + void writeSubMatlabHeader(std::ofstream & ofs, + double sequenceSize, + double vectorSizeLocal) const; + + void writeUnifiedMatlabHeader(std::ofstream & ofs, + double sequenceSize, + double vectorSizeLocal) const; + + //! Helper function to write plain txt info for vectors + void writeTxtHeader(std::ofstream & ofs, + double sequenceSize, + double vectorSizeLocal) const; + + using BaseVectorSequence::m_env; using BaseVectorSequence::m_vectorSpace; using BaseVectorSequence::m_name; diff --git a/src/basic/src/ScalarSequence.C b/src/basic/src/ScalarSequence.C index 535b6cd39..532ee6ef2 100644 --- a/src/basic/src/ScalarSequence.C +++ b/src/basic/src/ScalarSequence.C @@ -152,7 +152,7 @@ ScalarSequence::unifiedSequenceSize(bool useOnlyInter0Comm) const if (useOnlyInter0Comm) { if (m_env.inter0Rank() >= 0) { unsigned int subNumSamples = this->subSequenceSize(); - m_env.inter0Comm().Allreduce((void *) &subNumSamples, (void *) &unifiedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&subNumSamples, &unifiedNumSamples, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedSequenceSize()", "failed MPI.Allreduce() for unifiedSequenceSize()"); } @@ -252,7 +252,7 @@ ScalarSequence::getUnifiedContentsAtProc0Only( // Use MPI_Gatherv for the case different nodes have different amount of data // KAUST4 //****************************************************************** std::vector recvcnts(m_env.inter0Comm().NumProc(),0); // '0' is NOT the correct value for recvcnts[0] - m_env.inter0Comm().Gather((void *) &auxSubSize, 1, RawValue_MPI_INT, (void *) &recvcnts[0], (int) 1, RawValue_MPI_INT, 0, + m_env.inter0Comm().template Gather(&auxSubSize, 1, &recvcnts[0], (int) 1, 0, "ScalarSequence::getUnifiedContentsAtProc0Only()", "failed MPI.Gather()"); if (m_env.inter0Rank() == 0) { @@ -281,9 +281,11 @@ ScalarSequence::getUnifiedContentsAtProc0Only( } } #endif - m_env.inter0Comm().Gatherv((void *) &m_seq[0], auxSubSize, RawValue_MPI_DOUBLE, (void *) &outputVec[0], (int *) &recvcnts[0], (int *) &displs[0], RawValue_MPI_DOUBLE, 0, - "ScalarSequence::getUnifiedContentsAtProc0Only()", - "failed MPI.Gatherv()"); + + m_env.inter0Comm().template Gatherv(&m_seq[0], auxSubSize, + &outputVec[0], (int *) &recvcnts[0], (int *) &displs[0], 0, + "ScalarSequence::getUnifiedContentsAtProc0Only()", + "failed MPI.Gatherv()"); #if 0 // for debug only if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 0)) { @@ -908,7 +910,7 @@ ScalarSequence::unifiedMeanExtra( // << std::endl; //sleep(1); unsigned int unifiedNumPos = 0; - m_env.inter0Comm().Allreduce((void *) &numPos, (void *) &unifiedNumPos, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedMeanExtra()", "failed MPI.Allreduce() for numPos"); @@ -919,7 +921,7 @@ ScalarSequence::unifiedMeanExtra( << std::endl; } - m_env.inter0Comm().Allreduce((void *) &localSum, (void *) &unifiedMeanValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localSum, &unifiedMeanValue, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedMeanExtra()", "failed MPI.Allreduce() for sum"); @@ -1097,11 +1099,11 @@ ScalarSequence::unifiedSampleVarianceExtra( } unsigned int unifiedNumPos = 0; - m_env.inter0Comm().Allreduce((void *) &numPos, (void *) &unifiedNumPos, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedSampleVarianceExtra()", "failed MPI.Allreduce() for numPos"); - m_env.inter0Comm().Allreduce((void *) &localSamValue, (void *) &unifiedSamValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localSamValue, &unifiedSamValue, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedSampleVarianceExtra()", "failed MPI.Allreduce() for samValue"); @@ -1184,11 +1186,11 @@ ScalarSequence::unifiedSampleStd( } unsigned int unifiedNumPos = 0; - m_env.inter0Comm().Allreduce((void *) &numPos, (void *) &unifiedNumPos, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedSampleStd()", "failed MPI.Allreduce() for numPos"); - m_env.inter0Comm().Allreduce((void *) &localStdValue, (void *) &unifiedStdValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localStdValue, &unifiedStdValue, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedSampleStd()", "failed MPI.Allreduce() for stdValue"); @@ -1271,11 +1273,11 @@ ScalarSequence::unifiedPopulationVariance( } unsigned int unifiedNumPos = 0; - m_env.inter0Comm().Allreduce((void *) &numPos, (void *) &unifiedNumPos, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedPopulationVariance()", "failed MPI.Allreduce() for numPos"); - m_env.inter0Comm().Allreduce((void *) &localPopValue, (void *) &unifiedPopValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localPopValue, &unifiedPopValue, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedPopulationVariance()", "failed MPI.Allreduce() for popValue"); @@ -1366,11 +1368,11 @@ ScalarSequence::autoCorrViaFft( { unsigned int fftSize = 0; { +#warning WTF are 4 lines of unused code doing here? - RHS double tmp = log((double) maxLag)/log(2.); double fractionalPart = tmp - ((double) ((unsigned int) tmp)); if (fractionalPart > 0.) tmp += (1. - fractionalPart); unsigned int fftSize1 = (unsigned int) std::pow(2.,tmp+1.); // Yes, tmp+1 - fftSize1 = fftSize1; // To remove warning tmp = log((double) numPos)/log(2.); fractionalPart = tmp - ((double) ((unsigned int) tmp)); @@ -1567,7 +1569,7 @@ ScalarSequence::unifiedMinMaxExtra( for (unsigned int i = 0; i < sendBuf.size(); ++i) { sendBuf[i] = minValue; } - m_env.inter0Comm().Allreduce((void *) &sendBuf[0], (void *) &unifiedMinValue, (int) sendBuf.size(), RawValue_MPI_DOUBLE, RawValue_MPI_MIN, + m_env.inter0Comm().template Allreduce(&sendBuf[0], &unifiedMinValue, (int) sendBuf.size(), RawValue_MPI_MIN, "ScalarSequence::unifiedMinMaxExtra()", "failed MPI.Allreduce() for min"); @@ -1575,7 +1577,7 @@ ScalarSequence::unifiedMinMaxExtra( for (unsigned int i = 0; i < sendBuf.size(); ++i) { sendBuf[i] = maxValue; } - m_env.inter0Comm().Allreduce((void *) &sendBuf[0], (void *) &unifiedMaxValue, (int) sendBuf.size(), RawValue_MPI_DOUBLE, RawValue_MPI_MAX, + m_env.inter0Comm().template Allreduce(&sendBuf[0], &unifiedMaxValue, (int) sendBuf.size(), RawValue_MPI_MAX, "ScalarSequence::unifiedMinMaxExtra()", "failed MPI.Allreduce() for max"); @@ -1708,7 +1710,7 @@ ScalarSequence::unifiedHistogram( } } - m_env.inter0Comm().Allreduce((void *) &localBins[0], (void *) &unifiedBins[0], (int) localBins.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localBins[0], &unifiedBins[0], (int) localBins.size(), RawValue_MPI_SUM, "ScalarSequence::unifiedHistogram()", "failed MPI.Allreduce() for bins"); @@ -1964,7 +1966,7 @@ ScalarSequence::unifiedSort( "failed MPI.Bcast() for unified data size"); unsigned int sumOfNumPos = 0; - m_env.inter0Comm().Allreduce((void *) &localNumPos, (void *) &sumOfNumPos, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localNumPos, &sumOfNumPos, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedSort()", "failed MPI.Allreduce() for data size"); @@ -2138,7 +2140,7 @@ ScalarSequence::unifiedInterQuantileRange( unsigned int localDataSize = this->subSequenceSize() - initialPos; unsigned int sumOfLocalSizes = 0; - m_env.inter0Comm().Allreduce((void *) &localDataSize, (void *) &sumOfLocalSizes, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localDataSize, &sumOfLocalSizes, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedInterQuantileRange()", "failed MPI.Allreduce() for data size"); @@ -2277,7 +2279,7 @@ ScalarSequence::unifiedScaleForKde( unifiedMeanValue); unsigned int unifiedDataSize = 0; - m_env.inter0Comm().Allreduce((void *) &localDataSize, (void *) &unifiedDataSize, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localDataSize, &unifiedDataSize, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedScaleForKde()", "failed MPI.Allreduce() for data size"); @@ -2371,7 +2373,7 @@ ScalarSequence::unifiedGaussian1dKde( unsigned int localDataSize = this->subSequenceSize() - initialPos; unsigned int unifiedDataSize = 0; - m_env.inter0Comm().Allreduce((void *) &localDataSize, (void *) &unifiedDataSize, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localDataSize, &unifiedDataSize, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedGaussian1dKde()", "failed MPI.Allreduce() for data size"); @@ -2392,7 +2394,7 @@ ScalarSequence::unifiedGaussian1dKde( for (unsigned int j = 0; j < numEvals; ++j) { unifiedDensityValues[j] = 0.; } - m_env.inter0Comm().Allreduce((void *) &densityValues[0], (void *) &unifiedDensityValues[0], (int) numEvals, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&densityValues[0], &unifiedDensityValues[0], (int) numEvals, RawValue_MPI_SUM, "ScalarSequence::unifiedGaussian1dKde()", "failed MPI.Allreduce() for density values"); @@ -2604,25 +2606,27 @@ ScalarSequence::subWriteContents( template void ScalarSequence::subWriteContents( // rr0 - unsigned int initialPos, - unsigned int numPos, + unsigned int /* initialPos */, + unsigned int /* numPos */, std::ofstream& ofs, - const std::string& fileType) const // "m or hdf" + const std::string& fileType) const { - if (initialPos) {}; // just to remove compiler warning - if (numPos) {}; // just to remove compiler warning - if (&fileType) {}; // just to remove compiler warning - ofs << m_name << "_sub" << m_env.subIdString() << " = zeros(" << this->subSequenceSize() - << "," << 1 - << ");" - << std::endl; - ofs << m_name << "_sub" << m_env.subIdString() << " = ["; + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + this->writeSubMatlabHeader(ofs, this->subSequenceSize()); + } + else if (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT) { + this->writeTxtHeader(ofs, this->subSequenceSize()); + } + unsigned int chainSize = this->subSequenceSize(); for (unsigned int j = 0; j < chainSize; ++j) { ofs << m_seq[j] << std::endl; } - ofs << "];\n"; + + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + ofs << "];\n"; + } return; } @@ -2691,13 +2695,19 @@ ScalarSequence::unifiedWriteContents( //std::cout << "\n In ScalarSequence::unifiedWriteContents(), pos 001 \n" << std::endl; unsigned int chainSize = this->subSequenceSize(); - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { + + // Write header info if (r == 0) { - *unifiedFilePtrSet.ofsVar << m_name << "_unified" << " = zeros(" << this->subSequenceSize()*m_env.inter0Comm().NumProc() - << "," << 1 - << ");" - << std::endl; - *unifiedFilePtrSet.ofsVar << m_name << "_unified" << " = ["; + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + this->writeUnifiedMatlabHeader(*unifiedFilePtrSet.ofsVar, + this->subSequenceSize()*m_env.inter0Comm().NumProc()); + } + else { // It's definitely txt if we get in here + this->writeTxtHeader(*unifiedFilePtrSet.ofsVar, + this->subSequenceSize()*m_env.inter0Comm().NumProc()); + } } for (unsigned int j = 0; j < chainSize; ++j) { @@ -2706,7 +2716,7 @@ ScalarSequence::unifiedWriteContents( } m_env.closeFile(unifiedFilePtrSet,fileType); - } + } #ifdef QUESO_HAS_HDF5 else if (fileType == UQ_FILE_EXTENSION_FOR_HDF_FORMAT) { unsigned int numParams = 1; // m_vectorSpace.dimLocal(); @@ -2798,13 +2808,18 @@ ScalarSequence::unifiedWriteContents( } // for r if (m_env.inter0Rank() == 0) { - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { FilePtrSetStruct unifiedFilePtrSet; if (m_env.openUnifiedOutputFile(fileName, fileType, false, // Yes, 'writeOver = false' in order to close the array for matlab unifiedFilePtrSet)) { - *unifiedFilePtrSet.ofsVar << "];\n"; + + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + *unifiedFilePtrSet.ofsVar << "];\n"; + } + m_env.closeFile(unifiedFilePtrSet,fileType); } } @@ -2827,6 +2842,39 @@ ScalarSequence::unifiedWriteContents( return; } + +template +void +ScalarSequence::writeUnifiedMatlabHeader(std::ofstream & ofs, + double sequenceSize) const +{ + ofs << m_name << "_unified" << " = zeros(" << sequenceSize + << "," << 1 + << ");" + << std::endl; + ofs << m_name << "_unified" << " = ["; +} + +template +void +ScalarSequence::writeSubMatlabHeader(std::ofstream & ofs, + double sequenceSize) const +{ + ofs << m_name << "_sub" << m_env.subIdString() << " = zeros(" << sequenceSize + << "," << 1 + << ");" + << std::endl; + ofs << m_name << "_sub" << m_env.subIdString() << " = ["; +} + +template +void +ScalarSequence::writeTxtHeader(std::ofstream & ofs, + double sequenceSize) const +{ + ofs << sequenceSize << " " << 1 << std::endl; +} + // -------------------------------------------------- template void @@ -2835,6 +2883,7 @@ ScalarSequence::unifiedReadContents( const std::string& inputFileType, const unsigned int subReadSize) { + queso_require_not_equal_to_msg(inputFileType, UQ_FILE_EXTENSION_FOR_TXT_FORMAT, "reading txt files is not yet supported"); std::string fileType(inputFileType); #ifdef QUESO_HAS_HDF5 // Do nothing @@ -2892,11 +2941,12 @@ ScalarSequence::unifiedReadContents( if (m_env.openUnifiedInputFile(fileName, fileType, unifiedFilePtrSet)) { - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { if (r == 0) { // Read number of chain positions in the file by taking care of the first line, // which resembles something like 'variable_name = zeros(n_positions,m_params);' - std::string tmpString; + std::string tmpString; // Read 'variable name' string *unifiedFilePtrSet.ifsVar >> tmpString; @@ -3428,11 +3478,11 @@ ScalarSequence::unifiedMeanCltStd( } unsigned int unifiedNumPos = 0; - m_env.inter0Comm().Allreduce((void *) &numPos, (void *) &unifiedNumPos, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&numPos, &unifiedNumPos, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedMeanCltStd()", "failed MPI.Allreduce() for numPos"); - m_env.inter0Comm().Allreduce((void *) &localStdValue, (void *) &unifiedStdValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localStdValue, &unifiedStdValue, (int) 1, RawValue_MPI_SUM, "ScalarSequence::unifiedMeanCltStd()", "failed MPI.Allreduce() for stdValue"); @@ -4046,12 +4096,12 @@ ComputeCovCorrBetweenScalarSequences( // Compute unified covariance if (env.inter0Rank() >= 0) { unsigned int unifiedNumSamples = 0; - env.inter0Comm().Allreduce((void *) &subNumSamples, (void *) &unifiedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + env.inter0Comm().template Allreduce(&subNumSamples, &unifiedNumSamples, (int) 1, RawValue_MPI_SUM, "ComputeCovCorrBetweenScalarSequences()", "failed MPI.Allreduce() for subNumSamples"); double aux = 0.; - env.inter0Comm().Allreduce((void *) &covValue, (void *) &aux, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + env.inter0Comm().template Allreduce(&covValue, &aux, (int) 1, RawValue_MPI_SUM, "ComputeCovCorrBetweenScalarSequences()", "failed MPI.Allreduce() for a matrix position"); covValue = aux/((double) (unifiedNumSamples-1)); // Yes, '-1' in order to compensate for the 'N-1' denominator factor in the calculations of sample variances above (whose square roots will be used below) diff --git a/src/basic/src/SequenceOfVectors.C b/src/basic/src/SequenceOfVectors.C index b9eeba695..a97e2c243 100644 --- a/src/basic/src/SequenceOfVectors.C +++ b/src/basic/src/SequenceOfVectors.C @@ -1317,7 +1317,8 @@ SequenceOfVectors::subWriteContents( { queso_require_msg(filePtrSet.ofsVar, "filePtrSet.ofsVar should not be NULL"); - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT || + fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT) { this->subWriteContents(initialPos, numPos, *filePtrSet.ofsVar, @@ -1339,18 +1340,22 @@ SequenceOfVectors::subWriteContents( unsigned int initialPos, unsigned int numPos, std::ofstream& ofs, - const std::string& fileType) const // "m or hdf" + const std::string& fileType) const { queso_require_less_equal_msg((initialPos+numPos), this->subSequenceSize(), "invalid routine input parameters"); - if (fileType.c_str()) {}; // just to avoid compiler warning - if (initialPos == 0) { - ofs << m_name << "_sub" << m_env.subIdString() << " = zeros(" << this->subSequenceSize() - << "," << this->vectorSizeLocal() - << ");" - << std::endl; - ofs << m_name << "_sub" << m_env.subIdString() << " = ["; + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + // Need sub matlab header here since this is subWriteContents + this->writeSubMatlabHeader(ofs, + this->subSequenceSize(), + this->vectorSizeLocal()); + } + else if (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT) { + this->writeTxtHeader(ofs, + this->subSequenceSize(), + this->vectorSizeLocal()); + } } for (unsigned int j = initialPos; j < initialPos+numPos; ++j) { @@ -1365,12 +1370,47 @@ SequenceOfVectors::subWriteContents( m_seq[j]->setPrintHorizontally(savedVectorPrintState); m_seq[j]->setPrintScientific (savedVectorPrintScientific); } - if ((initialPos+numPos) == this->subSequenceSize()) { + + // Write Matlab-specific ending if desired + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) && + ((initialPos + numPos) == this->subSequenceSize())) { ofs << "];\n"; } +} - return; +template +void +SequenceOfVectors::writeSubMatlabHeader(std::ofstream & ofs, + double sequenceSize, double vectorSizeLocal) const +{ + ofs << m_name << "_sub" << m_env.subIdString() << " = zeros(" << sequenceSize + << "," << vectorSizeLocal + << ");" + << std::endl; + ofs << m_name << "_sub" << m_env.subIdString() << " = ["; +} + +template +void +SequenceOfVectors::writeUnifiedMatlabHeader(std::ofstream & ofs, + double sequenceSize, double vectorSizeLocal) const +{ + ofs << m_name << "_unified" << " = zeros(" << sequenceSize + << "," << vectorSizeLocal + << ");" + << std::endl; + ofs<< m_name << "_unified" << " = ["; } + +template +void +SequenceOfVectors::writeTxtHeader(std::ofstream & ofs, + double sequenceSize, double vectorSizeLocal) const +{ + ofs << sequenceSize << " " << vectorSizeLocal + << std::endl; +} + //--------------------------------------------------- template void @@ -1457,13 +1497,20 @@ SequenceOfVectors::unifiedWriteContents( } unsigned int chainSize = this->subSequenceSize(); - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { if (r == 0) { - *unifiedFilePtrSet.ofsVar << m_name << "_unified" << " = zeros(" << this->subSequenceSize()*m_env.inter0Comm().NumProc() - << "," << this->vectorSizeLocal() - << ");" - << std::endl; - *unifiedFilePtrSet.ofsVar << m_name << "_unified" << " = ["; + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + // Need unified matlab header here since this is unifiedWriteContents + writeUnifiedMatlabHeader(*unifiedFilePtrSet.ofsVar, + this->subSequenceSize()*m_env.inter0Comm().NumProc(), + this->vectorSizeLocal()); + } + else { // If we get here it's definitely a txt file not matlab + writeTxtHeader(*unifiedFilePtrSet.ofsVar, + this->subSequenceSize()*m_env.inter0Comm().NumProc(), + this->vectorSizeLocal()); + } } for (unsigned int j = 0; j < chainSize; ++j) { // 2013-02-23 @@ -1609,13 +1656,18 @@ SequenceOfVectors::unifiedWriteContents( } // for r if (m_env.inter0Rank() == 0) { - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { FilePtrSetStruct unifiedFilePtrSet; if (m_env.openUnifiedOutputFile(fileName, fileType, false, // Yes, 'writeOver = false' in order to close the array for matlab unifiedFilePtrSet)) { - *unifiedFilePtrSet.ofsVar << "];\n"; + + if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + *unifiedFilePtrSet.ofsVar << "];\n"; + } + m_env.closeFile(unifiedFilePtrSet,fileType); } } @@ -1702,7 +1754,8 @@ SequenceOfVectors::unifiedReadContents( if (m_env.openUnifiedInputFile(fileName, fileType, unifiedFilePtrSet)) { - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { if (r == 0) { // Read number of chain positions in the file by taking care of the first line, // which resembles something like 'variable_name = zeros(n_positions,m_params);' @@ -1909,12 +1962,10 @@ SequenceOfVectors::unifiedReadContents( //--------------------------------------------------- template void -SequenceOfVectors::select(const std::vector& idsOfUniquePositions) +SequenceOfVectors::select(const std::vector& /* idsOfUniquePositions */) { queso_error_msg("Code is not complete yet"); - if (&idsOfUniquePositions) {}; // just to remove compiler warning - return; } //--------------------------------------------------- diff --git a/src/basic/src/VectorSequence.C b/src/basic/src/VectorSequence.C index f038d08d0..ed8360913 100644 --- a/src/basic/src/VectorSequence.C +++ b/src/basic/src/VectorSequence.C @@ -76,7 +76,7 @@ BaseVectorSequence::unifiedSequenceSize() const if (useOnlyInter0Comm) { if (m_env.inter0Rank() >= 0) { unsigned int subNumSamples = this->subSequenceSize(); - m_env.inter0Comm().Allreduce((void *) &subNumSamples, (void *) &unifiedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&subNumSamples, &unifiedNumSamples, (int) 1, RawValue_MPI_SUM, "BaseVectorSequence::unifiedSequenceSize()", "failed MPI.Allreduce() for unifiedSequenceSize()"); } @@ -442,7 +442,7 @@ BaseVectorSequence::unifiedPositionsOfMaximum( // rr0 for (unsigned int i = 0; i < sendbufPos.size(); ++i) { sendbufPos[i] = subMaxValue; } - m_env.inter0Comm().Allreduce((void *) &sendbufPos[0], (void *) &unifiedMaxValue, (int) sendbufPos.size(), RawValue_MPI_DOUBLE, RawValue_MPI_MAX, + m_env.inter0Comm().template Allreduce(&sendbufPos[0], &unifiedMaxValue, (int) sendbufPos.size(), RawValue_MPI_MAX, "BaseVectorSequence::unifiedPositionsOfMaximum()", "failed MPI.Allreduce() for max"); @@ -474,7 +474,7 @@ BaseVectorSequence::unifiedPositionsOfMaximum( // rr0 std::vector auxBuf(1,0); int unifiedNumPos = 0; // Yes, 'int', due to MPI to be used soon auxBuf[0] = subNumPos; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &unifiedNumPos, (int) auxBuf.size(), RawValue_MPI_INT, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &unifiedNumPos, (int) auxBuf.size(), RawValue_MPI_SUM, "BaseVectorSequence::unifiedPositionsOfMaximum()", "failed MPI.Allreduce() for sum"); @@ -488,7 +488,7 @@ BaseVectorSequence::unifiedPositionsOfMaximum( // rr0 unsigned int Np = (unsigned int) m_env.inter0Comm().NumProc(); std::vector recvcntsPos(Np,0); // '0' is NOT the correct value for recvcntsPos[0] - m_env.inter0Comm().Gather((void *) &subNumPos, 1, RawValue_MPI_INT, (void *) &recvcntsPos[0], (int) 1, RawValue_MPI_INT, 0, + m_env.inter0Comm().template Gather(&subNumPos, 1, &recvcntsPos[0], (int) 1, 0, "BaseVectorSequence::unifiedPositionsOfMaximum()", "failed MPI.Gatherv()"); if (m_env.inter0Rank() == 0) { @@ -515,7 +515,7 @@ BaseVectorSequence::unifiedPositionsOfMaximum( // rr0 unsigned int dimSize = m_vectorSpace.dimLocal(); int subNumDbs = subNumPos * dimSize; // Yes, 'int', due to MPI to be used soon std::vector recvcntsDbs(Np,0); // '0' is NOT the correct value for recvcntsDbs[0] - m_env.inter0Comm().Gather((void *) &subNumDbs, 1, RawValue_MPI_INT, (void *) &recvcntsDbs[0], (int) 1, RawValue_MPI_INT, 0, + m_env.inter0Comm().template Gather(&subNumDbs, 1, &recvcntsDbs[0], (int) 1, 0, "BaseVectorSequence::unifiedPositionsOfMaximum()", "failed MPI.Gatherv()"); if (m_env.inter0Rank() == 0) { @@ -548,9 +548,10 @@ BaseVectorSequence::unifiedPositionsOfMaximum( // rr0 std::vector recvbufDbs(unifiedNumPos * dimSize); // Gather up all states that attain maxima and store then in recvbufDbs - m_env.inter0Comm().Gatherv((void *) &sendbufDbs[0], (int) subNumDbs, RawValue_MPI_DOUBLE, (void *) &recvbufDbs[0], (int *) &recvcntsDbs[0], (int *) &displsDbs[0], RawValue_MPI_DOUBLE, 0, - "BaseVectorSequence::unifiedPositionsOfMaximum()", - "failed MPI.Gatherv()"); + m_env.inter0Comm().template Gatherv(&sendbufDbs[0], (int) subNumDbs, + &recvbufDbs[0], (int *) &recvcntsDbs[0], (int *) &displsDbs[0], 0, + "BaseVectorSequence::unifiedPositionsOfMaximum()", + "failed MPI.Gatherv()"); //****************************************************************** // Transfer data from 'recvbuf' to 'unifiedPositionsOfMaximum' @@ -2777,6 +2778,9 @@ ComputeCovCorrMatricesBetweenVectorSequences( P_M& pqCovMatrix, P_M& pqCorrMatrix) { + queso_require_greater_equal_msg(subNumSamples, 2, + "must provide at least 2 samples to compute correlation matrices"); + // Check input data consistency const BaseEnvironment& env = subPSeq.vectorSpace().zeroVector().env(); @@ -2839,18 +2843,26 @@ ComputeCovCorrMatricesBetweenVectorSequences( unifiedMeanQ, unifiedSampleVarianceQ); + // Check the variance is positive in every component + double minSampleVarianceP; + double minSampleVarianceQ; + minSampleVarianceP = unifiedSampleVarianceP.getMinValue(); + minSampleVarianceQ = unifiedSampleVarianceQ.getMinValue(); + queso_require_greater_msg(minSampleVarianceP, 0, "sample variance is not positive"); + queso_require_greater_msg(minSampleVarianceQ, 0, "sample variance is not positive"); + // Compute unified covariance matrix if (useOnlyInter0Comm) { if (env.inter0Rank() >= 0) { unsigned int unifiedNumSamples = 0; - env.inter0Comm().Allreduce((void *) &subNumSamples, (void *) &unifiedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + env.inter0Comm().template Allreduce(&subNumSamples, &unifiedNumSamples, (int) 1, RawValue_MPI_SUM, "ComputeCovCorrMatricesBetweenVectorSequences()", "failed MPI.Allreduce() for subNumSamples"); for (unsigned i = 0; i < numRowsLocal; ++i) { for (unsigned j = 0; j < numCols; ++j) { double aux = 0.; - env.inter0Comm().Allreduce((void *) &pqCovMatrix(i,j), (void *) &aux, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + env.inter0Comm().template Allreduce(&pqCovMatrix(i,j), &aux, (int) 1, RawValue_MPI_SUM, "ComputeCovCorrMatricesBetweenVectorSequences()", "failed MPI.Allreduce() for a matrix position"); pqCovMatrix(i,j) = aux/((double) (unifiedNumSamples-1)); // Yes, '-1' in order to compensate for the 'N-1' denominator factor in the calculations of sample variances above (whose square roots will be used below) diff --git a/src/core/inc/BoostInputOptionsParser.h b/src/core/inc/BoostInputOptionsParser.h index cdb03cb7b..1dc9b93b9 100644 --- a/src/core/inc/BoostInputOptionsParser.h +++ b/src/core/inc/BoostInputOptionsParser.h @@ -87,9 +87,13 @@ class BoostInputOptionsParser : public BaseInputOptionsParser const BoostInputOptionsParser & parser); protected: - const std::string & m_filename; - typename ScopedPtr::Type m_optionsDescription; - typename ScopedPtr::Type m_optionsMap; + // Needs to be a copy, not a reference; we don't want to force users + // to keep their strings around and non-temporary, and we don't have + // a non-temporary "" string for internal use. + const std::string m_filename; + + ScopedPtr::Type m_optionsDescription; + ScopedPtr::Type m_optionsMap; private: bool m_scannedInputFile; diff --git a/src/core/inc/Defines.h b/src/core/inc/Defines.h index 1120de556..a79f2107a 100644 --- a/src/core/inc/Defines.h +++ b/src/core/inc/Defines.h @@ -44,17 +44,30 @@ #define QUESO_HAS_ANN #endif -//! This define is deprecated. Remove any #ifdef statements in user code. +#ifdef QUESO_HAVE_MPI #define QUESO_HAS_MPI +#endif //! This define is deprecated. Remove any #ifdef statements in user code. #define QUESO_EXPECTS_LN_LIKELIHOOD_INSTEAD_OF_MINUS_2_LN +// Use GSL inline functions +#define HAVE_INLINE + +// And only do GSL range-checking if we're really debugging +#ifndef DEBUG +#define GSL_RANGE_CHECK_OFF +#endif + #include #include // For exit() #include #include + +#ifdef QUESO_HAS_MPI #include +#endif + #include // for queso_error handler namespace QUESO { @@ -87,6 +100,7 @@ const int UQ_INVALID_SPACE_COMPONENT_ID_RC = -10; const int UQ_MATRIX_SVD_FAILED_RC = -11; #define UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT "m" +#define UQ_FILE_EXTENSION_FOR_TXT_FORMAT "txt" #define UQ_FILE_EXTENSION_FOR_HDF_FORMAT "h5" diff --git a/src/core/inc/Environment.h b/src/core/inc/Environment.h index 784389bfe..af51dfb0d 100644 --- a/src/core/inc/Environment.h +++ b/src/core/inc/Environment.h @@ -417,10 +417,22 @@ class FullEnvironment : public BaseEnvironment { public: //! @name Constructor/Destructor methods //@{ - //! Default constructor. - /*! It initializes the full communicator, reads the options, deals with multiple sub-environments, - * e.g. dealing with sub/self/inter0-communicators, handles path for output files. */ + //! Parallel constructor. + /*! + * Initializes the full communicator, reads the options, deals with multiple + * sub-environments, e.g. dealing with sub/self/inter0-communicators, handles + * path for output files. + */ +#ifdef QUESO_HAS_MPI FullEnvironment(RawType_MPI_Comm inputComm, const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues); +#endif + + //! Serial constructor. + /*! + * No communicator is passed. Output path handling is exactly as in the + * parallel ctor. + */ + FullEnvironment(const char* passedOptionsInputFileName, const char* prefix, EnvOptionsValues* alternativeOptionsValues); //! Destructor ~FullEnvironment(); diff --git a/src/core/inc/GslMatrix.h b/src/core/inc/GslMatrix.h index 6913e9951..5c052367f 100644 --- a/src/core/inc/GslMatrix.h +++ b/src/core/inc/GslMatrix.h @@ -29,10 +29,12 @@ \brief QUESO matrix class using GSL. */ +#include +#include #include + #include #include -#include namespace QUESO { @@ -99,10 +101,23 @@ class GslMatrix : public Matrix //! @name Accessor methods //@{ //! Element access method (non-const). - double& operator()(unsigned int i, unsigned int j); + double& operator()(unsigned int i, unsigned int j) + { + // Changing the matrix changes its decomposition(s). We'll + // invalidate for now; recalculate later if needed. + this->resetLU(); + queso_require_less_msg(i, m_mat->size1, "i is too large"); + queso_require_less_msg(j, m_mat->size2, "j is too large"); + return *gsl_matrix_ptr(m_mat,i,j); + } //! Element access method (const). - const double& operator()(unsigned int i, unsigned int j) const; + const double& operator()(unsigned int i, unsigned int j) const + { + queso_require_less_msg(i, m_mat->size1, "i is too large"); + queso_require_less_msg(j, m_mat->size2, "j is too large"); + return *gsl_matrix_ptr(m_mat,i,j); + } //@} diff --git a/src/core/inc/GslVector.h b/src/core/inc/GslVector.h index 4c246fbf2..efe3a6758 100644 --- a/src/core/inc/GslVector.h +++ b/src/core/inc/GslVector.h @@ -32,6 +32,7 @@ #include #include + #include namespace QUESO { @@ -256,6 +257,23 @@ GslVector operator- (const GslVector& x, const GslVector& y ); bool operator== (const GslVector& lhs, const GslVector& rhs); std::ostream& operator<< (std::ostream& os, const GslVector& obj); + +inline +double& +GslVector::operator[](unsigned int i) +{ + return *gsl_vector_ptr(m_vec,i); +} + + +inline +const double& +GslVector::operator[](unsigned int i) const +{ + return *gsl_vector_const_ptr(m_vec,i); +} + + } // End namespace QUESO #endif // UQ_GSL_VECTOR_H diff --git a/src/core/inc/MpiComm.h b/src/core/inc/MpiComm.h index 44e8a6163..bee647746 100644 --- a/src/core/inc/MpiComm.h +++ b/src/core/inc/MpiComm.h @@ -31,17 +31,20 @@ #include #endif +#ifdef QUESO_HAS_MPI #include +#endif namespace QUESO { +#ifdef QUESO_HAS_MPI typedef MPI_Comm RawType_MPI_Comm ; typedef MPI_Group RawType_MPI_Group ; typedef MPI_Datatype RawType_MPI_Datatype ; +typedef MPI_Datatype data_type ; typedef MPI_Op RawType_MPI_Op ; typedef MPI_Status RawType_MPI_Status ; #define RawValue_MPI_COMM_SELF MPI_COMM_SELF -#define RawValue_MPI_IN_PLACE MPI_IN_PLACE #define RawValue_MPI_ANY_SOURCE MPI_ANY_SOURCE #define RawValue_MPI_CHAR MPI_CHAR #define RawValue_MPI_INT MPI_INT @@ -50,11 +53,140 @@ typedef MPI_Status RawType_MPI_Status ; #define RawValue_MPI_MIN MPI_MIN #define RawValue_MPI_MAX MPI_MAX #define RawValue_MPI_SUM MPI_SUM +#else +typedef int RawType_MPI_Comm; +typedef int RawType_MPI_Group; +typedef int RawType_MPI_Datatype; +struct data_type { }; +typedef int RawType_MPI_Op; +typedef int RawType_MPI_Status; +#define RawValue_MPI_COMM_SELF 0 +#define RawValue_MPI_ANY_SOURCE -1 +#define RawValue_MPI_CHAR 0 +#define RawValue_MPI_INT 1 +#define RawValue_MPI_DOUBLE 2 +#define RawValue_MPI_UNSIGNED 3 +#define RawValue_MPI_MIN 0 +#define RawValue_MPI_MAX 1 +#define RawValue_MPI_SUM 2 +#endif -} // End namespace QUESO +/** + * Encapsulates the MPI_Datatype. Taken from libmesh. + */ +class DataType +{ +public: + DataType () : _datatype() {} + + DataType (const DataType &other) : + _datatype(other._datatype) + {} + + DataType (const RawType_MPI_Datatype &type) : + _datatype(type) + {} + +#ifdef QUESO_HAS_MPI + DataType (const DataType &other, unsigned int count) + { + // FIXME - if we nest an inner type here will we run into bug + // https://github.com/libMesh/libmesh/issues/631 again? + MPI_Type_contiguous(count, other._datatype, &_datatype); + this->commit(); + } +#else + DataType (const DataType &, unsigned int) + { + } +#endif + DataType & operator = (const DataType &other) + { _datatype = other._datatype; return *this; } -namespace QUESO { + DataType & operator = (const RawType_MPI_Datatype &type) + { _datatype = type; return *this; } + + operator const RawType_MPI_Datatype & () const + { return _datatype; } + + operator RawType_MPI_Datatype & () + { return _datatype; } + + void commit () + { +#ifdef QUESO_HAS_MPI + MPI_Type_commit (&_datatype); +#endif + } + + void free () + { +#ifdef QUESO_HAS_MPI + MPI_Type_free (&_datatype); +#endif + } + +protected: + RawType_MPI_Datatype _datatype; +}; + +/** + * Templated class to provide the appropriate MPI datatype + * for use with built-in C types or simple C++ constructions. + * + * More complicated data types may need to provide a pointer-to-T so + * that we can use MPI_Address without constructing a new T. + */ +template +class StandardType : public DataType +{ +#ifdef QUESO_HAS_CXX11 // This macro isn't defined (yet) + // Get a slightly better compiler diagnostic if we have C++11 + static_assert(dependent_false::value, + "Only specializations of StandardType may be used, did you forget to include a header file (e.g. parallel_algebra.h)?"); +#endif + + /* + * The unspecialized class is useless, so we make its constructor + * private to catch mistakes at compile-time rather than link-time. + * Specializations should have a public constructor of the same + * form. + */ +private: + StandardType(const T* example = NULL); +}; + +#ifdef QUESO_HAS_MPI + +#define STANDARD_TYPE(cxxtype,mpitype) \ + template<> \ + class StandardType : public DataType \ + { \ + public: \ + explicit \ + StandardType(const cxxtype* = NULL) : DataType(mpitype) {} \ + } + +#else + +#define STANDARD_TYPE(cxxtype,mpitype) \ + template<> \ + class StandardType : public DataType \ + { \ + public: \ + explicit \ + StandardType(const cxxtype* = NULL) : DataType() {} \ + } + +#endif + +STANDARD_TYPE(char,MPI_CHAR); +STANDARD_TYPE(int,MPI_INT); +STANDARD_TYPE(unsigned int,MPI_UNSIGNED); +STANDARD_TYPE(double,MPI_DOUBLE); + +class BaseEnvironment; /*! \file MpiComm.h \brief MPI Communicator Class. @@ -68,21 +200,31 @@ namespace QUESO { the user from the specifics of communication that are not required for normal manipulation of linear algebra objects. */ - - -class BaseEnvironment; - class MpiComm { public: //! @name Constructor/Destructor methods //@{ - //! QUESO MpiComm MPI Constructor. - /*! This constructs an MpiComm that uses the given "raw" MPI communicator underneath. - * The MPI_Comm must be valid for the lifetime of this MpiComm.*/ + //! QUESO MpiComm MPI parallel constructor. + /*! + * This constructs an MpiComm that uses the given "raw" MPI communicator + * underneath. MPI_Init *must* have been called before instantiating an + * object of this type. + * + * The MPI_Comm must be valid for the lifetime of this MpiComm. + */ MpiComm(const BaseEnvironment& env, RawType_MPI_Comm inputRawComm); + //! QUESO MpiComm MPI serial constructor. + /*! + * This constructs an MpiComm that defaults to MPI_COMM_SELF + * underneath. MPI_Init need not be called before using this constructor. + * + * The MPI_Comm must be valid for the lifetime of this MpiComm. + */ + MpiComm(const BaseEnvironment& env); + //! Copy Constructor. /** Makes an exact copy of an existing MpiComm instance.*/ MpiComm(const MpiComm& src); @@ -117,10 +259,24 @@ class MpiComm * \param count number of elements in send buffer * \param datatype data type of elements of send buffer * \param op operation - * \param recvbuf (output) starting address of receive buffer*/ + * \param recvbuf (output) starting address of receive buffer + * + * This method is deprecated. Use the templated Allreduce method instead. + */ void Allreduce(void* sendbuf, void* recvbuf, int count, RawType_MPI_Datatype datatype, RawType_MPI_Op op, const char* whereMsg, const char* whatMsg) const; + //! Combines values from all processes and distributes the result back to all processes + /*! + * \param sendbuf starting address of send buffer containing elements of type T + * \param count number of elements in send buffer + * \param op operation + * \param recvbuf (output) starting address of receive buffer containing elements of type T + */ + template + void Allreduce(const T * sendbuf, T * recvbuf, int count, RawType_MPI_Op op, + const char* whereMsg, const char* whatMsg) const; + //! Pause every process in *this communicator until all the processes reach this point. /*! Blocks the caller until all processes in the communicator have called it; that is, * the call returns at any process only after all members of the communicator have entered the call.*/ @@ -142,12 +298,27 @@ class MpiComm * \param recvcount number of elements for any single receive * \param recvtype data type of recv buffer elements * \param root rank of receiving process - * \param recvbuf (output) address of receive buffer */ + * \param recvbuf (output) address of receive buffer + * + * This method is deprecated. Use the templated Gather method instead. + */ void Gather (void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype, void *recvbuf, int recvcount, RawType_MPI_Datatype recvtype, int root, const char* whereMsg, const char* whatMsg) const; + //! Gather values from each process to collect on all processes. + /*! + * \param sendbuf starting address of send buffer containing elements of type T + * \param sendcnt number of elements in send buffer + * \param recvcount number of elements for any single receive + * \param root rank of receiving process + * \param recvbuf (output) address of receive buffer containing elements of type T + */ + template + void Gather(const T * sendbuf, int sendcnt, T * recvbuf, int recvcount, int root, + const char * whereMsg, const char * whatMsg) const; + //! Gathers into specified locations from all processes in a group /*! \param sendbuf starting address of send buffer * \param sendcount number of elements in send buffer @@ -163,6 +334,22 @@ class MpiComm int root, const char* whereMsg, const char* whatMsg) const; + //! Gathers into specified locations from all processes in a group + /*! + * \param sendbuf starting address of send buffer containing elements of type T + * \param sendcnt number of elements in send buffer + * \param recvcnts integer array (of length group size) containing the number + * of elements that are received from each process + * \param displs integer array (of length group size). Entry i specifies the + * displacement relative to recvbuf at which to place the incoming data from + * process i + * \param root rank of receiving process + */ + template + void Gatherv(const T * sendbuf, int sendcnt, T * recvbuf, int * recvcnts, + int * displs, int root, const char * whereMsg, + const char * whatMsg) const; + //! Blocking receive of data from this process to another process. /*!\param buf (output) initial address of receive buffer * \param status (output) status object diff --git a/src/core/inc/RngGsl.h b/src/core/inc/RngGsl.h index 61d489aa4..1cef86d9f 100644 --- a/src/core/inc/RngGsl.h +++ b/src/core/inc/RngGsl.h @@ -26,6 +26,8 @@ #define UQ_RNG_GSL_H #include + +#include #include diff --git a/src/core/inc/SharedPtr.h b/src/core/inc/SharedPtr.h new file mode 100644 index 000000000..323429b8a --- /dev/null +++ b/src/core/inc/SharedPtr.h @@ -0,0 +1,56 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// QUESO - a library to support the Quantification of Uncertainty +// for Estimation, Simulation and Optimization +// +// Copyright (C) 2008-2015 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#ifndef UQ_SHARED_PTR_H +#define UQ_SHARED_PTR_H + +#include + +#ifdef QUESO_HAVE_CXX11_UNIQUE_PTR +#include +#elif QUESO_HAVE_BOOST_SHARED_PTR_HPP +#include +#endif + +namespace QUESO +{ +#ifdef QUESO_HAVE_CXX11_SHARED_PTR + template + struct SharedPtr + { + typedef std::shared_ptr Type; + }; +#elif QUESO_HAVE_BOOST_SHARED_PTR_HPP + template + struct SharedPtr + { + typedef boost::shared_ptr Type; + }; +#else +# error "No valid definition for SharedPtr found!" +#endif + +} // end namespace QUESO + +#endif // UQ_SHARED_PTR_H diff --git a/src/core/inc/exceptions.h b/src/core/inc/exceptions.h index 382841e55..fb7399493 100644 --- a/src/core/inc/exceptions.h +++ b/src/core/inc/exceptions.h @@ -29,7 +29,11 @@ #include #include #include // std::set_terminate -#include // for MPI_ABORT in uncaught exceptions + +#ifdef QUESO_HAS_MPI +#include +#endif + #include // exit(1) namespace QUESO diff --git a/src/core/src/BasicPdfsBase.C b/src/core/src/BasicPdfsBase.C index 246efedaf..deb463b59 100644 --- a/src/core/src/BasicPdfsBase.C +++ b/src/core/src/BasicPdfsBase.C @@ -23,7 +23,6 @@ //-----------------------------------------------------------------------el- #include -#include namespace QUESO { diff --git a/src/core/src/BasicPdfsBoost.C b/src/core/src/BasicPdfsBoost.C index 8dfec19c6..79212b511 100644 --- a/src/core/src/BasicPdfsBoost.C +++ b/src/core/src/BasicPdfsBoost.C @@ -23,7 +23,6 @@ //-----------------------------------------------------------------------el- #include -#include namespace QUESO { diff --git a/src/core/src/BasicPdfsGsl.C b/src/core/src/BasicPdfsGsl.C index b7087ab3c..c28e565be 100644 --- a/src/core/src/BasicPdfsGsl.C +++ b/src/core/src/BasicPdfsGsl.C @@ -23,8 +23,8 @@ //-----------------------------------------------------------------------el- #include +#include #include -#include #include namespace QUESO { diff --git a/src/core/src/Defines.C b/src/core/src/Defines.C index d15e96512..28ba59a49 100644 --- a/src/core/src/Defines.C +++ b/src/core/src/Defines.C @@ -23,15 +23,20 @@ //-----------------------------------------------------------------------el- #include + +#ifdef QUESO_HAS_MPI #include +#endif namespace QUESO { int MyWorldfullRank() { int result = 0; +#ifdef QUESO_HAS_MPI int iRC; iRC = MPI_Comm_rank(MPI_COMM_WORLD,&result); if (iRC) {}; // just to remove compiler warning +#endif return result; } diff --git a/src/core/src/Environment.C b/src/core/src/Environment.C index 8a2a1cd68..f325a81d8 100644 --- a/src/core/src/Environment.C +++ b/src/core/src/Environment.C @@ -562,7 +562,8 @@ BaseEnvironment::openOutputFile( ////////////////////////////////////////////////////////////// // Write over an eventual pre-existing file ////////////////////////////////////////////////////////////// - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(), std::ofstream::out | std::ofstream::trunc); } @@ -586,7 +587,8 @@ BaseEnvironment::openOutputFile( ////////////////////////////////////////////////////////////// // Write at the end of an eventual pre-existing file ////////////////////////////////////////////////////////////// - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { #if 0 filePtrSet.ofsVar = new std::ofstream((baseFileName+"_sub"+this->subIdString()+"."+fileType).c_str(), std::ofstream::in); @@ -740,7 +742,8 @@ BaseEnvironment::openUnifiedOutputFile( //////////////////////////////////////////////////////////////// // Write over an eventual pre-existing file //////////////////////////////////////////////////////////////// - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { filePtrSet.ofsVar = new std::ofstream((baseFileName+"."+fileType).c_str(), std::ofstream::out | std::ofstream::trunc); } @@ -770,7 +773,8 @@ BaseEnvironment::openUnifiedOutputFile( // Write at the end of an eventual pre-existing file // 'm' and Ranger nodes behave differently on ofstream constructor... prudenci 2010/03/05 //////////////////////////////////////////////////////////////// - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { filePtrSet.ofsVar = new std::ofstream((baseFileName+"."+fileType).c_str(), std::ofstream::out /*| std::ofstream::in*/ | std::ofstream::app); } @@ -893,7 +897,8 @@ BaseEnvironment::openInputFile( int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str()); queso_require_greater_equal_msg(irtrn, 0, "unable to verify input path"); - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { filePtrSet.ifsVar = new std::ifstream((baseFileName+"."+fileType).c_str(), std::ofstream::in); if ((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)) { @@ -985,7 +990,8 @@ BaseEnvironment::openUnifiedInputFile( int irtrn = CheckFilePath((baseFileName+"."+fileType).c_str()); queso_require_greater_equal_msg(irtrn, 0, "unable to verify input path"); - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { filePtrSet.ifsVar = new std::ifstream((baseFileName+"."+fileType).c_str(), std::ofstream::in); if ((filePtrSet.ifsVar == NULL) || (filePtrSet.ifsVar->is_open() == false)) { @@ -1046,7 +1052,8 @@ BaseEnvironment::closeFile( } #endif - if (fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) { + if ((fileType == UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT) || + (fileType == UQ_FILE_EXTENSION_FOR_TXT_FORMAT)) { //filePtrSet.ofsVar->close(); // close() crashes on Mac; need to use delete(); why? prudenci 2010/June delete filePtrSet.ofsVar; filePtrSet.ofsVar = NULL; @@ -1104,6 +1111,7 @@ EmptyEnvironment::print(std::ostream& os) const //***************************************************** // Full Environment //***************************************************** +#ifdef QUESO_HAS_MPI FullEnvironment::FullEnvironment( RawType_MPI_Comm inputComm, const char* passedOptionsInputFileName, @@ -1123,6 +1131,7 @@ FullEnvironment::FullEnvironment( queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed to get world fullRank()"); m_fullComm = new MpiComm(*this,inputComm); + m_fullRank = m_fullComm->MyPID(); m_fullCommSize = m_fullComm->NumProc(); @@ -1363,6 +1372,236 @@ FullEnvironment::FullEnvironment( return; } +#endif // QUESO_HAS_MPI + +FullEnvironment::FullEnvironment( + const char* passedOptionsInputFileName, + const char* prefix, + EnvOptionsValues* alternativeOptionsValues) + : + BaseEnvironment(passedOptionsInputFileName,alternativeOptionsValues) +{ +#ifdef QUESO_MEMORY_DEBUGGING + std::cout << "Entering FullEnv" << std::endl; +#endif + + m_worldRank = 0; + + m_fullComm = new MpiComm(*this); + m_fullRank = 0; + m_fullCommSize = 1; + +#ifndef QUESO_HAS_MPI + m_fullGroup = 0; +#endif + + // saving old uncaught exception handler, invoking queso_terminate + old_terminate_handler = std::set_terminate(queso_terminate_handler); + +#ifdef QUESO_MEMORY_DEBUGGING + std::cout << "In FullEnv, finished dealing with MPI initially" << std::endl; +#endif + + ////////////////////////////////////////////////// + // Read options + ////////////////////////////////////////////////// + // If NULL, we create one + if (m_optionsObj == NULL) { + EnvOptionsValues * tempOptions = new EnvOptionsValues(this, prefix); + + // If there's an input file, we grab the options from there. Otherwise the + // defaults are used + if (m_optionsInputFileName != "") { + m_allOptionsMap = new boost::program_options::variables_map(); + m_allOptionsDesc = new boost::program_options::options_description("Allowed options"); + + readOptionsInputFile(); + } + + // We did this dance because scanOptionsValues is not a const method, but + // m_optionsObj is a pointer to const + m_optionsObj = tempOptions; + } + + // If help option was supplied, print info + if (m_optionsObj->m_help != "") { + // We write to std::cout because subDisplayFile() isn't ready yet? + std::cout << (*m_optionsObj) << std::endl; + } + + queso_require_equal_to_msg( + fullComm().NumProc() % m_optionsObj->m_numSubEnvironments, 0, + "total number of processors in environment must be multiple of the specified number of subEnvironments"); + +#ifdef QUESO_MEMORY_DEBUGGING + std::cout << "In FullEnv, finished scanning options" << std::endl; +#endif + + // Only display these messages if the user wants them + // NOTE: This got moved below the Read Options section + // because we need the options to be read to know what + // the verbosity level is. + if (this->displayVerbosity() > 0) { + ////////////////////////////////////////////////// + // Display main initial messages + // 'std::cout' is for: main trace messages + synchronized trace messages + error messages prior to 'exit()' or 'abort()' + ////////////////////////////////////////////////// + /*int iRC = 0;*/ + /*iRC = */gettimeofday(&m_timevalBegin, NULL); + + QUESO_version_print(std::cout); + + std::cout << "Beginning run at " << ctime(&m_timevalBegin.tv_sec) + << std::endl; + } + + m_subId = 0; + char tmpSubId[16]; + sprintf(tmpSubId,"%u",m_subId); + m_subIdString = tmpSubId; + + if (m_optionsObj->m_subDisplayAllowAll) { + m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId); + } + + int fullRanksOfMySubEnvironment = 1; + +#ifndef QUESO_HAS_MPI + m_subGroup = 0; +#endif + + m_subComm = new MpiComm(*this); + m_subRank = 0; + m_subCommSize = 1; + + ////////////////////////////////////////////////// + // Deal with multiple subEnvironments: create the self communicator + ////////////////////////////////////////////////// + m_selfComm = new MpiComm(*this); + + ////////////////////////////////////////////////// + // Deal with multiple subEnvironments: create the inter0 communicator + ////////////////////////////////////////////////// + int fullRanksOfInter0 = 0; +#ifndef QUESO_HAS_MPI + m_inter0Group = 0; +#endif + m_inter0Comm = new MpiComm(*this); + m_inter0Rank = 0; + m_inter0CommSize = 1; + + if (m_optionsObj->m_subDisplayAllowAll) { + // This situation has been already taken care of above + } + else if (m_optionsObj->m_subDisplayAllowInter0) { + if (m_inter0Rank >= 0) { + m_optionsObj->m_subDisplayAllowedSet.insert((unsigned int) m_subId); + } + } + + + ////////////////////////////////////////////////// + // Open "screen" file + ////////////////////////////////////////////////// + bool openFile = false; + if ((m_subRank == 0 ) && + (m_optionsObj->m_subDisplayFileName != UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE ) && + (m_optionsObj->m_subDisplayAllowedSet.find(m_subId) != m_optionsObj->m_subDisplayAllowedSet.end())) { + openFile = true; + } + + if (openFile && m_worldRank == 0) { + ////////////////////////////////////////////////////////////////// + // Verify parent directory exists (for cases when a user + // specifies a relative path for the desired output file). + ////////////////////////////////////////////////////////////////// + int irtrn = CheckFilePath((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str()); + queso_require_greater_equal_msg(irtrn, 0, "unable to verify output path"); + } + + //////////////////////////////////////////////////////////////////// + // Ensure that rank 0 has created path, if necessary, before other tasks use it + //////////////////////////////////////////////////////////////////// + m_fullComm->Barrier(); + + if (openFile) { + ////////////////////////////////////////////////////////////////// + // Always write over an eventual pre-existing file + ////////////////////////////////////////////////////////////////// + m_subDisplayFile = new std::ofstream((m_optionsObj->m_subDisplayFileName+"_sub"+m_subIdString+".txt").c_str(), + std::ofstream::out | std::ofstream::trunc); + queso_require_msg((m_subDisplayFile && m_subDisplayFile->is_open()), "failed to open sub screen file"); + + QUESO_version_print(*m_subDisplayFile); + + *m_subDisplayFile << "Beginning run at " << ctime(&m_timevalBegin.tv_sec) + << std::endl; + } + + ////////////////////////////////////////////////// + // Debug message related to subEnvironments + ////////////////////////////////////////////////// + if (this->displayVerbosity() >= 2) { + for (int i = 0; i < m_fullCommSize; ++i) { + if (i == m_fullRank) { + //std::cout << "In FullEnvironment::commonConstructor()" + std::cout << "MPI node of worldRank " << m_worldRank + << " has fullRank " << m_fullRank + << ", belongs to subEnvironment of id " << m_subId + << ", and has subRank " << m_subRank + << std::endl; + + std::cout << "MPI node of worldRank " << m_worldRank + << " belongs to sub communicator with full ranks"; + std::cout << " " << fullRanksOfMySubEnvironment; + std::cout << "\n"; + + if (m_inter0Comm) { + std::cout << "MPI node of worldRank " << m_worldRank + << " also belongs to inter0 communicator with full ranks"; + std::cout << " " << fullRanksOfInter0; + std::cout << ", and has inter0Rank " << m_inter0Rank; + } + std::cout << "\n"; + + std::cout << std::endl; + } + m_fullComm->Barrier(); + } + } + + ////////////////////////////////////////////////// + // Deal with seed + ////////////////////////////////////////////////// + if (m_optionsObj->m_rngType == "gsl") { + m_rngObject = new RngGsl(m_optionsObj->m_seed,m_worldRank); + m_basicPdfs = new BasicPdfsGsl(m_worldRank); + } + else if (m_optionsObj->m_rngType == "boost") { + m_rngObject = new RngBoost(m_optionsObj->m_seed,m_worldRank); + m_basicPdfs = new BasicPdfsBoost(m_worldRank); + } + else { + std::cerr << "In Environment::constructor()" + << ": rngType = " << m_optionsObj->m_rngType + << std::endl; + queso_error_msg("the requested 'rngType' is not supported yet"); + } + + ////////////////////////////////////////////////// + // Leave commonConstructor() + ////////////////////////////////////////////////// + m_fullComm->Barrier(); + m_fullEnvIsReady = true; + + if ((m_subDisplayFile) && (this->displayVerbosity() >= 5)) { + *m_subDisplayFile << "Done with initializations at FullEnvironment::commonConstructor()" + << std::endl; + } + + return; +} + //------------------------------------------------------- FullEnvironment::~FullEnvironment() { @@ -1377,6 +1616,7 @@ FullEnvironment::print(std::ostream& os) const void queso_terminate_handler() { +#ifdef QUESO_HAS_MPI int mpi_initialized; MPI_Initialized (&mpi_initialized); @@ -1392,6 +1632,9 @@ void queso_terminate_handler() // their own terminate handler that we want to call. old_terminate_handler(); } +#else + old_terminate_handler(); +#endif exit(1); } diff --git a/src/core/src/GslMatrix.C b/src/core/src/GslMatrix.C index d438734b1..dbe7f71d4 100644 --- a/src/core/src/GslMatrix.C +++ b/src/core/src/GslMatrix.C @@ -214,32 +214,7 @@ GslMatrix::operator-=(const GslMatrix& rhs) return *this; } -// Acessor methods (operators) ---------------------------------------- -double& -GslMatrix::operator()(unsigned int i, unsigned int j) -{ - this->resetLU(); - if ((i >= m_mat->size1) || - (j >= m_mat->size2)) { - std::cerr << "In GslMatrix::operator(i,j)" - << ": i = " << i - << ", j = " << j - << ", m_mat->size1 = " << m_mat->size1 - << ", m_mat->size2 = " << m_mat->size2 - << std::endl; - queso_require_less_msg(i, m_mat->size1, "i is too large"); - queso_require_less_msg(j, m_mat->size2, "j is too large"); - } - return *gsl_matrix_ptr(m_mat,i,j); -} -const double& -GslMatrix::operator()(unsigned int i, unsigned int j) const -{ - queso_require_less_msg(i, m_mat->size1, "i is too large"); - queso_require_less_msg(j, m_mat->size2, "j is too large"); - return *gsl_matrix_const_ptr(m_mat,i,j); -} void GslMatrix::copy(const GslMatrix& src) @@ -1710,7 +1685,7 @@ GslMatrix::mpiSum( const MpiComm& comm, GslMatrix& M_global ) const } } - comm.Allreduce((void*) &local[0], (void*) &global[0], size, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + comm.Allreduce(&local[0], &global[0], size, RawValue_MPI_SUM, "GslMatrix::mpiSum()", "failed MPI.Allreduce()"); diff --git a/src/core/src/GslOptimizer.C b/src/core/src/GslOptimizer.C index bdecf3df0..436f0be7e 100644 --- a/src/core/src/GslOptimizer.C +++ b/src/core/src/GslOptimizer.C @@ -24,14 +24,16 @@ #include -#include -#include +#include #include #include #include #include #include +#include +#include + namespace QUESO { // We need to extern "C" because gsl needs a pointer to a C function to diff --git a/src/core/src/GslVector.C b/src/core/src/GslVector.C index 624f1cc1b..bbadf36ee 100644 --- a/src/core/src/GslVector.C +++ b/src/core/src/GslVector.C @@ -226,18 +226,6 @@ GslVector::operator-=(const GslVector& rhs) return *this; } -double& -GslVector::operator[](unsigned int i) -{ - return *gsl_vector_ptr(m_vec,i); -} - -const double& -GslVector::operator[](unsigned int i) const -{ - return *gsl_vector_const_ptr(m_vec,i); -} - void GslVector::copy(const GslVector& src) { @@ -655,7 +643,7 @@ GslVector::mpiBcast(int srcRank, const MpiComm& bcastComm) // Check number of participant nodes double localNumNodes = 1.; double totalNumNodes = 0.; - bcastComm.Allreduce((void *) &localNumNodes, (void *) &totalNumNodes, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + bcastComm.Allreduce(&localNumNodes, &totalNumNodes, (int) 1, RawValue_MPI_SUM, "GslVector::mpiBcast()", "failed MPI.Allreduce() for numNodes"); queso_require_equal_to_msg(((int) totalNumNodes), bcastComm.NumProc(), "inconsistent numNodes"); @@ -663,7 +651,7 @@ GslVector::mpiBcast(int srcRank, const MpiComm& bcastComm) // Check that all participant nodes have the same vector size double localVectorSize = this->sizeLocal(); double sumOfVectorSizes = 0.; - bcastComm.Allreduce((void *) &localVectorSize, (void *) &sumOfVectorSizes, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + bcastComm.Allreduce(&localVectorSize, &sumOfVectorSizes, (int) 1, RawValue_MPI_SUM, "GslVector::mpiBcast()", "failed MPI.Allreduce() for vectorSize"); @@ -710,7 +698,7 @@ GslVector::mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm& opComm, GslV for (unsigned int i = 0; i < size; ++i) { double srcValue = (*this)[i]; double resultValue = 0.; - opComm.Allreduce((void *) &srcValue, (void *) &resultValue, (int) 1, RawValue_MPI_DOUBLE, mpiOperation, + opComm.Allreduce(&srcValue, &resultValue, (int) 1, mpiOperation, "GslVector::mpiAllReduce()", "failed MPI.Allreduce()"); resultVec[i] = resultValue; @@ -733,7 +721,7 @@ GslVector::mpiAllQuantile(double probability, const MpiComm& opComm, GslVector& for (unsigned int i = 0; i < size; ++i) { double auxDouble = (int) (*this)[i]; std::vector vecOfDoubles(opComm.NumProc(),0.); - opComm.Gather((void *) &auxDouble, 1, RawValue_MPI_DOUBLE, (void *) &vecOfDoubles[0], (int) 1, RawValue_MPI_DOUBLE, 0, + opComm.Gather(&auxDouble, 1, &vecOfDoubles[0], (int) 1, 0, "GslVector::mpiAllQuantile()", "failed MPI.Gather()"); diff --git a/src/core/src/InfiniteDimensionalGaussian.C b/src/core/src/InfiniteDimensionalGaussian.C index 3a3e46539..0da8b4be9 100644 --- a/src/core/src/InfiniteDimensionalGaussian.C +++ b/src/core/src/InfiniteDimensionalGaussian.C @@ -63,6 +63,8 @@ boost::shared_ptr InfiniteDimensionalGaussian::draw() (this->coeffs)[i] = env.rngObject()->gaussianSample(this->beta); } +#warning We never use the mean? + boost::shared_ptr f(this->precision.inverse_kl_transform(this->coeffs, this->alpha)); return f; } diff --git a/src/core/src/MpiComm.C b/src/core/src/MpiComm.C index 44e4b7ec6..5e5210e3a 100644 --- a/src/core/src/MpiComm.C +++ b/src/core/src/MpiComm.C @@ -23,6 +23,7 @@ //-----------------------------------------------------------------------el- #include +#include #include #include @@ -40,6 +41,7 @@ MpiComm::MpiComm(const BaseEnvironment& env, RawType_MPI_Comm inputRawComm) m_myPid (-1), m_numProc (-1) { +#ifdef QUESO_HAS_MPI int mpiRC = MPI_Comm_rank(inputRawComm,&m_worldRank); queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_rank() on full rank"); @@ -48,6 +50,24 @@ MpiComm::MpiComm(const BaseEnvironment& env, RawType_MPI_Comm inputRawComm) mpiRC = MPI_Comm_size(inputRawComm,&m_numProc); queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_size() on inputRawComm"); +#else + m_worldRank = 0; + m_myPid = 0; + m_numProc = 1; +#endif +} + +MpiComm::MpiComm(const BaseEnvironment& env) + : + m_env (env), +#ifdef QUESO_HAS_TRILINOS + m_epetraMpiComm( new Epetra_MpiComm(MPI_COMM_SELF) ), +#endif + m_rawComm (RawValue_MPI_COMM_SELF), + m_worldRank (0), + m_myPid (0), + m_numProc (1) +{ } // Copy constructor --------------------------------- @@ -112,10 +132,32 @@ MpiComm::NumProc() const void MpiComm::Allreduce(void* sendbuf, void* recvbuf, int count, RawType_MPI_Datatype datatype, RawType_MPI_Op op, const char* whereMsg, const char* whatMsg) const { - int mpiRC = MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, m_rawComm); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); + queso_deprecated(); + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + int mpiRC = MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } +} - return; +template +void +MpiComm::Allreduce(const T* sendbuf, T* recvbuf, int count, RawType_MPI_Op op, + const char* whereMsg, const char* whatMsg) const +{ + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + T * sendbuf_noconst = const_cast(sendbuf); + int mpiRC = MPI_Allreduce(sendbuf_noconst, recvbuf, count, StandardType(sendbuf), op, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } + else { + size_t dataTypeSize = sizeof(T); + size_t dataTotal = dataTypeSize*count; + std::memcpy(recvbuf, sendbuf, dataTotal); + } } //-------------------------------------------------- void @@ -124,17 +166,26 @@ MpiComm::Barrier() const // const char* whereMsg, const char* whatMsg) const #ifdef QUESO_HAS_TRILINOS return m_epetraMpiComm->Barrier(); #endif - int mpiRC = MPI_Barrier(m_rawComm); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "mpiRC indicates failure"); // whatMsg); + + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + int mpiRC = MPI_Barrier(m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "mpiRC indicates failure"); // whatMsg); +#endif + } + return; } //-------------------------------------------------- void MpiComm::Bcast(void* buffer, int count, RawType_MPI_Datatype datatype, int root, const char* whereMsg, const char* whatMsg) const { - int mpiRC = MPI_Bcast(buffer, count, datatype, root, m_rawComm); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); - return; + if (NumProc() > 1) { // Necesarrily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + int mpiRC = MPI_Bcast(buffer, count, datatype, root, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } } //-------------------------------------------------- void @@ -144,14 +195,49 @@ MpiComm::Gather( int root, const char* whereMsg, const char* whatMsg) const { - //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype, - // void *recvbuf, int recvcount, MPI_Datatype recvtype, - // int root, MPI_Comm comm ) - int mpiRC = MPI_Gather(sendbuf, sendcnt, sendtype, - recvbuf, recvcount, recvtype, - root, m_rawComm); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); - return; + queso_deprecated(); + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype, + // void *recvbuf, int recvcount, MPI_Datatype recvtype, + // int root, MPI_Comm comm ) + int mpiRC = MPI_Gather(sendbuf, sendcnt, sendtype, + recvbuf, recvcount, recvtype, + root, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } +} + +template +void +MpiComm::Gather(const T * sendbuf, int sendcnt, T * recvbuf, int recvcount, + int root, const char* whereMsg, const char* whatMsg) const +{ + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype, + // void *recvbuf, int recvcount, MPI_Datatype recvtype, + // int root, MPI_Comm comm ) + T * sendbuf_noconst = const_cast(sendbuf); + int mpiRC = MPI_Gather(sendbuf_noconst, sendcnt, StandardType(sendbuf), + recvbuf, recvcount, StandardType(sendbuf), + root, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } + else { + size_t dataTypeSize = sizeof(T); + size_t sendTotal = dataTypeSize*sendcnt; + size_t recvTotal = dataTypeSize*recvcount; + if (sendTotal != recvTotal) { + std::cerr << "MpiCommClass::Gather()" + << ": sendTotal != recvTotal" + << std::endl; + } + queso_require_equal_to_msg(sendTotal, recvTotal, whatMsg); + std::memcpy(recvbuf, sendbuf, sendTotal); + } } //-------------------------------------------------- void @@ -161,14 +247,50 @@ MpiComm::Gatherv( int root, const char* whereMsg, const char* whatMsg) const { - //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, - // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype, - // int root, MPI_Comm comm ) - int mpiRC = MPI_Gatherv(sendbuf, sendcnt, sendtype, - recvbuf, recvcnts, displs, recvtype, - root, m_rawComm); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); - return; + queso_deprecated(); + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype, + // int root, MPI_Comm comm ) + int mpiRC = MPI_Gatherv(sendbuf, sendcnt, sendtype, + recvbuf, recvcnts, displs, recvtype, + root, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } +} + +template +void +MpiComm::Gatherv(const T * sendbuf, int sendcnt, T * recvbuf, int * recvcnts, + int * displs, int root, const char * whereMsg, + const char * whatMsg) const +{ + if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype, + // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype, + // int root, MPI_Comm comm ) + T * sendbuf_noconst = const_cast(sendbuf); + int mpiRC = MPI_Gatherv(sendbuf_noconst, sendcnt, StandardType(sendbuf), + recvbuf, recvcnts, displs, + StandardType(recvbuf), root, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } + else { + size_t dataTypeSize = sizeof(T); + size_t sendTotal = dataTypeSize*sendcnt; + size_t recvTotal = dataTypeSize*recvcnts[0]; + if (sendTotal != recvTotal) { + std::cerr << "MpiCommClass::Gatherv()" + << ": sendTotal != recvTotal" + << std::endl; + } + queso_require_equal_to_msg(sendTotal, recvTotal, whatMsg); + std::memcpy(recvbuf, sendbuf, sendTotal); + } } //-------------------------------------------------- void @@ -176,9 +298,12 @@ MpiComm::Recv( void* buf, int count, RawType_MPI_Datatype datatype, int source, int tag, RawType_MPI_Status* status, const char* whereMsg, const char* whatMsg) const { - int mpiRC = MPI_Recv(buf, count, datatype, source, tag, m_rawComm, status); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); - return; + if (NumProc() > 1) { // Necesarrily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + int mpiRC = MPI_Recv(buf, count, datatype, source, tag, m_rawComm, status); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } } //-------------------------------------------------- void @@ -186,9 +311,12 @@ MpiComm::Send( void* buf, int count, RawType_MPI_Datatype datatype, int dest, int tag, const char* whereMsg, const char* whatMsg) const { - int mpiRC = MPI_Send(buf, count, datatype, dest, tag, m_rawComm); - queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); - return; + if (NumProc() > 1) { // Necesarrily true if QUESO_HAS_MPI +#ifdef QUESO_HAS_MPI + int mpiRC = MPI_Send(buf, count, datatype, dest, tag, m_rawComm); + queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg); +#endif + } } // Misc methods ------------------------------------ void @@ -242,4 +370,98 @@ MpiComm::copy(const MpiComm& src) } // ------------------------------------------------- +// Explicit template function instantiations +template void MpiComm::Allreduce(const int *, + int *, + int, + RawType_MPI_Op, + const char *, + const char*) const; +template void MpiComm::Allreduce(const char *, + char *, + int, + RawType_MPI_Op, + const char *, + const char*) const; +template void MpiComm::Allreduce(const unsigned int *, + unsigned int *, + int, + RawType_MPI_Op, + const char *, + const char *) const; +template void MpiComm::Allreduce(const double *, + double *, + int, + RawType_MPI_Op, + const char *, + const char *) const; + +template void MpiComm::Gather(const int * sendbuf, + int sendcnt, + int * recvbuf, + int recvcount, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gather(const char * sendbuf, + int sendcnt, + char * recvbuf, + int recvcount, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gather(const unsigned int * sendbuf, + int sendcnt, + unsigned int * recvbuf, + int recvcount, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gather(const double * sendbuf, + int sendcnt, + double * recvbuf, + int recvcount, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gatherv(const int * sendbuf, + int sendcnt, + int * recvbuf, + int * recvcnts, + int * displs, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gatherv(const char * sendbuf, + int sendcnt, + char * recvbuf, + int * recvcnts, + int * displs, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gatherv(const unsigned int * sendbuf, + int sendcnt, + unsigned int * recvbuf, + int * recvcnts, + int * displs, + int root, + const char * whereMsg, + const char * whatMsg) const; + +template void MpiComm::Gatherv(const double * sendbuf, + int sendcnt, + double * recvbuf, + int * recvcnts, + int * displs, + int root, + const char * whereMsg, + const char * whatMsg) const; + } // End namespace QUESO diff --git a/src/core/src/RngBase.C b/src/core/src/RngBase.C index 76ff96e73..f88dbc980 100644 --- a/src/core/src/RngBase.C +++ b/src/core/src/RngBase.C @@ -23,7 +23,6 @@ //-----------------------------------------------------------------------el- #include -#include namespace QUESO { diff --git a/src/core/src/RngBoost.C b/src/core/src/RngBoost.C index d7fdd0135..7a9a56f8d 100644 --- a/src/core/src/RngBoost.C +++ b/src/core/src/RngBoost.C @@ -23,7 +23,6 @@ //-----------------------------------------------------------------------el- #include -#include namespace QUESO { diff --git a/src/core/src/RngGsl.C b/src/core/src/RngGsl.C index bdfc74eb0..3b2a07b60 100644 --- a/src/core/src/RngGsl.C +++ b/src/core/src/RngGsl.C @@ -22,9 +22,9 @@ // //-----------------------------------------------------------------------el- +#include #include #include -#include namespace QUESO { diff --git a/src/core/src/TeuchosMatrix.C b/src/core/src/TeuchosMatrix.C index ec38a8bf6..76c39d734 100644 --- a/src/core/src/TeuchosMatrix.C +++ b/src/core/src/TeuchosMatrix.C @@ -1673,7 +1673,7 @@ TeuchosMatrix::mpiSum( const MpiComm& comm, TeuchosMatrix& M_global ) const } } - comm.Allreduce((void*) &local[0], (void*) &global[0], size, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + comm.Allreduce(&local[0], &global[0], size, RawValue_MPI_SUM, "TeuchosMatrix::mpiSum()", "failed MPI.Allreduce()"); diff --git a/src/core/src/TeuchosVector.C b/src/core/src/TeuchosVector.C index f3ffcbeba..d34eb5c29 100644 --- a/src/core/src/TeuchosVector.C +++ b/src/core/src/TeuchosVector.C @@ -737,7 +737,7 @@ TeuchosVector::mpiBcast(int srcRank, const MpiComm& bcastComm) // Check number of participant nodes double localNumNodes = 1.; double totalNumNodes = 0.; - bcastComm.Allreduce((void *) &localNumNodes, (void *) &totalNumNodes, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + bcastComm.Allreduce(&localNumNodes, &totalNumNodes, (int) 1, RawValue_MPI_SUM, "TeuchosVector::mpiBcast()", "failed MPI.Allreduce() for numNodes"); queso_require_equal_to_msg(((int) totalNumNodes), bcastComm.NumProc(), "inconsistent numNodes"); @@ -745,7 +745,7 @@ TeuchosVector::mpiBcast(int srcRank, const MpiComm& bcastComm) // Check that all participant nodes have the same vector size double localVectorSize = this->sizeLocal(); double sumOfVectorSizes = 0.; - bcastComm.Allreduce((void *) &localVectorSize, (void *) &sumOfVectorSizes, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + bcastComm.Allreduce(&localVectorSize, &sumOfVectorSizes, (int) 1, RawValue_MPI_SUM, "TeuchosVector::mpiBcast()", "failed MPI.Allreduce() for vectorSize"); @@ -794,7 +794,7 @@ TeuchosVector::mpiAllReduce(RawType_MPI_Op mpiOperation, const MpiComm& opComm, for (unsigned int i = 0; i < size; ++i) { double srcValue = (*this)[i]; double resultValue = 0.; - opComm.Allreduce((void *) &srcValue, (void *) &resultValue, (int) 1, RawValue_MPI_DOUBLE, mpiOperation, + opComm.Allreduce(&srcValue, &resultValue, (int) 1, mpiOperation, "TeuchosVector::mpiAllReduce()", "failed MPI.Allreduce()"); resultVec[i] = resultValue; @@ -819,7 +819,7 @@ TeuchosVector::mpiAllQuantile(double probability, const MpiComm& opComm, Teuchos for (unsigned int i = 0; i < size; ++i) { double auxDouble = (int) (*this)[i]; std::vector vecOfDoubles(opComm.NumProc(),0.); - opComm.Gather((void *) &auxDouble, 1, RawValue_MPI_DOUBLE, (void *) &vecOfDoubles[0], (int) 1, RawValue_MPI_DOUBLE, 0, + opComm.Gather(&auxDouble, 1, &vecOfDoubles[0], (int) 1, 0, "TeuchosVector::mpiAllQuantile()", "failed MPI.Gather()"); diff --git a/src/misc/src/Miscellaneous.C b/src/misc/src/Miscellaneous.C index 2a243ca1d..166b80f89 100644 --- a/src/misc/src/Miscellaneous.C +++ b/src/misc/src/Miscellaneous.C @@ -486,7 +486,7 @@ MiscCheckForSameValueInAllNodes(T& inputValue, // Yes, 'not' double localValue = (double) inputValue; double sumValue = 0.; - comm.Allreduce((void *) &localValue, (void *) &sumValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + comm.Allreduce(&localValue, &sumValue, (int) 1, RawValue_MPI_SUM, whereString, "failed MPI on 'sumValue' inside MiscCheckForSameValueInAllNodes()"); @@ -496,7 +496,7 @@ MiscCheckForSameValueInAllNodes(T& inputValue, // Yes, 'not' #if 1 unsigned int boolResult = 0; if (testValue > acceptableTreshold) boolResult = 1; - comm.Allreduce((void *) &boolResult, (void *) &boolSum, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + comm.Allreduce(&boolResult, &boolSum, (int) 1, RawValue_MPI_SUM, whereString, "failed MPI on 'boolSum' inside MiscCheckForSameValueInAllNodes()"); diff --git a/src/stats/inc/BetaVectorRV.h b/src/stats/inc/BetaVectorRV.h index 23b73273b..1a81fa0da 100644 --- a/src/stats/inc/BetaVectorRV.h +++ b/src/stats/inc/BetaVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/ConcatenatedVectorRV.h b/src/stats/inc/ConcatenatedVectorRV.h index 57373ed8d..b517fa10f 100644 --- a/src/stats/inc/ConcatenatedVectorRV.h +++ b/src/stats/inc/ConcatenatedVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/GammaVectorRV.h b/src/stats/inc/GammaVectorRV.h index 113587a81..af419b74a 100644 --- a/src/stats/inc/GammaVectorRV.h +++ b/src/stats/inc/GammaVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/GaussianVectorRV.h b/src/stats/inc/GaussianVectorRV.h index 5c267247c..2c06245a7 100644 --- a/src/stats/inc/GaussianVectorRV.h +++ b/src/stats/inc/GaussianVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/GenericVectorRV.h b/src/stats/inc/GenericVectorRV.h index ad5123d19..3db8ee1bb 100644 --- a/src/stats/inc/GenericVectorRV.h +++ b/src/stats/inc/GenericVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/InfoTheory.h b/src/stats/inc/InfoTheory.h index c3daebf5b..f84027fb3 100644 --- a/src/stats/inc/InfoTheory.h +++ b/src/stats/inc/InfoTheory.h @@ -30,7 +30,6 @@ #include #include -#include // TODO: create InfoTheoryOptions #define UQ_INFTH_ANN_NO_SMP 10000 diff --git a/src/stats/inc/InverseGammaVectorRV.h b/src/stats/inc/InverseGammaVectorRV.h index 63fa175d7..572b3ed81 100644 --- a/src/stats/inc/InverseGammaVectorRV.h +++ b/src/stats/inc/InverseGammaVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/JeffreysVectorRV.h b/src/stats/inc/JeffreysVectorRV.h index a0714f40c..2f8a7509c 100644 --- a/src/stats/inc/JeffreysVectorRV.h +++ b/src/stats/inc/JeffreysVectorRV.h @@ -31,7 +31,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/LogNormalVectorRV.h b/src/stats/inc/LogNormalVectorRV.h index 7dcf3287a..d98e924f3 100644 --- a/src/stats/inc/LogNormalVectorRV.h +++ b/src/stats/inc/LogNormalVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/MLSamplingLevelOptions.h b/src/stats/inc/MLSamplingLevelOptions.h index 575d71290..eab27d8b9 100644 --- a/src/stats/inc/MLSamplingLevelOptions.h +++ b/src/stats/inc/MLSamplingLevelOptions.h @@ -247,6 +247,9 @@ class MLSamplingLevelOptions std::string m_rawChainDataOutputFileName; //! Type of output file for raw chain. + /*! + * See MhOptionsValues::m_rawChainDataOutputFileType + */ std::string m_rawChainDataOutputFileType; //! Whether or not subEnvs will write to output file for raw chain. @@ -393,7 +396,10 @@ class MLSamplingLevelOptions std::string m_option_rawChain_measureRunTimes; std::string m_option_rawChain_dataOutputPeriod; std::string m_option_rawChain_dataOutputFileName; + + //! Option name for MLSamplingLevelOptions::m_rawChainDataOutputFileType. Option name is m_prefix + "ml_rawChain_dataOutputFileType" std::string m_option_rawChain_dataOutputFileType; + std::string m_option_rawChain_dataOutputAllowAll; std::string m_option_rawChain_dataOutputAllowedSet; #ifdef QUESO_USES_SEQUENCE_STATISTICAL_OPTIONS diff --git a/src/stats/inc/MetropolisHastingsSG.h b/src/stats/inc/MetropolisHastingsSG.h index a65c2c4ee..a8985aa5e 100644 --- a/src/stats/inc/MetropolisHastingsSG.h +++ b/src/stats/inc/MetropolisHastingsSG.h @@ -87,7 +87,7 @@ struct MHRawChainInfoStruct void reset (); //! Calculates the MPI sum of \c this. - void mpiSum(const MpiComm& comm, MHRawChainInfoStruct& sumInfo) const; + void mpiSum(const MpiComm& comm, MHRawChainInfoStruct& sumInfo); //@} double runTime; diff --git a/src/stats/inc/MetropolisHastingsSGOptions.h b/src/stats/inc/MetropolisHastingsSGOptions.h index 027a604f0..87ea78ad8 100644 --- a/src/stats/inc/MetropolisHastingsSGOptions.h +++ b/src/stats/inc/MetropolisHastingsSGOptions.h @@ -290,7 +290,24 @@ class MhOptionsValues */ std::string m_rawChainDataOutputFileName; - //! The filetype of m_rawChainDataOutputFileName. Only "m" (matlab) is currently supported. Default is "m" + //! The filetype of m_rawChainDataOutputFileName + /*! + * Only "m" (matlab) and "txt" are currently supported. + * + * If "m", the raw chain data that is written will be matlab-friendly. I.e., + * arrays will be set up with the correct dimensions. The first dimension + * is the sample dimension and the second dimension (for high-dimensional + * statistical inverse problems) is the parameter dimension. + * + * If "txt", none of the matlab-specific information is written to the file. + * Instead, space-delimited column data is written. The first line + * specifies the dimensions of the saved array data. The first dimension + * is the sample dimension and the second dimension is the parameter + * dimension. For example, if the first line written is "12 34" then the + * following 12 lines are samples that live in a 34-dimensional space. + * + * Default is "m" + */ std::string m_rawChainDataOutputFileType; //! Toggle for whether or not to allow all processes to write Markov chain output to a file diff --git a/src/stats/inc/StatisticalInverseProblemOptions.h b/src/stats/inc/StatisticalInverseProblemOptions.h index 846dcabff..a48827ebd 100644 --- a/src/stats/inc/StatisticalInverseProblemOptions.h +++ b/src/stats/inc/StatisticalInverseProblemOptions.h @@ -41,6 +41,9 @@ #define UQ_SIP_SOLVER_ODV "bayes_mc" // Bayesian formula + Metropolis-Hastings #endif +#define UQ_SIP_SEEDWITHMAPESTIMATOR 0 +#define UQ_SIP_USEOPTIMIZERMONITOR 1 + namespace boost { namespace program_options { class options_description; @@ -99,7 +102,8 @@ class SipOptionsValues std::string m_solverString; #endif - //MhOptionsValues m_mhOptionsValues; + bool m_seedWithMAPEstimator; + bool m_useOptimizerMonitor; private: BoostInputOptionsParser * m_parser; @@ -112,6 +116,8 @@ class SipOptionsValues #ifdef UQ_SIP_READS_SOLVER_OPTION std::string m_option_solver; #endif + std::string m_option_seedWithMAPEstimator; + std::string m_option_useOptimizerMonitor; //! Copies the option values from \c src to \c this. void copy(const SipOptionsValues& src); @@ -122,10 +128,6 @@ class SipOptionsValues const SipOptionsValues & obj); }; -// -------------------------------------------------- -// -------------------------------------------------- -// -------------------------------------------------- - /*! \class StatisticalInverseProblemOptions * \brief This class reads option values for a Statistical Inverse Problem from an input file. * @@ -168,7 +170,6 @@ class StatisticalInverseProblemOptions private: //! Define my SIP options as the default options. void defineMyOptions (boost::program_options::options_description& optionsDesc) const; - //! Gets the option values of the SIP. void getMyOptionValues(boost::program_options::options_description& optionsDesc); @@ -182,6 +183,8 @@ class StatisticalInverseProblemOptions #ifdef UQ_SIP_READS_SOLVER_OPTION std::string m_option_solver; #endif + std::string m_option_seedWithMAPEstimator; + std::string m_option_useOptimizerMonitor; }; //! Prints the object \c obj, overloading an operator. diff --git a/src/stats/inc/UniformVectorRV.h b/src/stats/inc/UniformVectorRV.h index ed640cf2c..5a1237a2a 100644 --- a/src/stats/inc/UniformVectorRV.h +++ b/src/stats/inc/UniformVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/inc/WignerVectorRV.h b/src/stats/inc/WignerVectorRV.h index a8b4fd4dc..45aac722f 100644 --- a/src/stats/inc/WignerVectorRV.h +++ b/src/stats/inc/WignerVectorRV.h @@ -33,7 +33,6 @@ #include #include #include -#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) namespace QUESO { diff --git a/src/stats/src/InfoTheory.C b/src/stats/src/InfoTheory.C index 2bc6df60f..070d71834 100644 --- a/src/stats/src/InfoTheory.C +++ b/src/stats/src/InfoTheory.C @@ -24,6 +24,9 @@ #include +#include +#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) + #ifdef QUESO_HAS_ANN namespace QUESO { diff --git a/src/stats/src/MLSampling.C b/src/stats/src/MLSampling.C index 7f267eebd..c64f3b860 100644 --- a/src/stats/src/MLSampling.C +++ b/src/stats/src/MLSampling.C @@ -172,7 +172,7 @@ MLSampling::decideOnBalancedChains_all( // Gather information at proc 0: number of chains and positions per node ////////////////////////////////////////////////////////////////////////// unsigned int auxUInt = indexOfFirstWeight; - m_env.inter0Comm().Gather((void *) &auxUInt, 1, RawValue_MPI_UNSIGNED, (void *) &allFirstIndexes[0], (int) 1, RawValue_MPI_UNSIGNED, 0, // LOAD BALANCE + m_env.inter0Comm().template Gather(&auxUInt, 1, &allFirstIndexes[0], (int) 1, 0, // LOAD BALANCE "MLSampling::decideOnBalancedChains_all()", "failed MPI.Gather() for first indexes"); @@ -181,7 +181,7 @@ MLSampling::decideOnBalancedChains_all( } auxUInt = indexOfLastWeight; - m_env.inter0Comm().Gather((void *) &auxUInt, 1, RawValue_MPI_UNSIGNED, (void *) &allLastIndexes[0], (int) 1, RawValue_MPI_UNSIGNED, 0, // LOAD BALANCE + m_env.inter0Comm().template Gather(&auxUInt, 1, &allLastIndexes[0], (int) 1, 0, // LOAD BALANCE "MLSampling::decideOnBalancedChains_all()", "failed MPI.Gather() for last indexes"); @@ -416,7 +416,7 @@ MLSampling::prepareBalLinkedChains_inter0( // EXTRA FOR LOAD BALANCE std::vector auxBuf(1,0.); double minRatio = 0.; auxBuf[0] = finalRatioOfPosPerNode; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &minRatio, (int) auxBuf.size(), RawValue_MPI_DOUBLE, RawValue_MPI_MIN, // LOAD BALANCE + m_env.inter0Comm().template Allreduce(&auxBuf[0], &minRatio, (int) auxBuf.size(), RawValue_MPI_MIN, // LOAD BALANCE "MLSampling::prepareBalLinkedChains_inter0()", "failed MPI.Allreduce() for min"); //std::cout << m_env.worldRank() << ", minRatio = " << minRatio << std::endl; @@ -424,7 +424,7 @@ MLSampling::prepareBalLinkedChains_inter0( // EXTRA FOR LOAD BALANCE double maxRatio = 0.; auxBuf[0] = finalRatioOfPosPerNode; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &maxRatio, (int) auxBuf.size(), RawValue_MPI_DOUBLE, RawValue_MPI_MAX, // LOAD BALANCE + m_env.inter0Comm().template Allreduce(&auxBuf[0], &maxRatio, (int) auxBuf.size(), RawValue_MPI_MAX, // LOAD BALANCE "MLSampling::prepareBalLinkedChains_inter0()", "failed MPI.Allreduce() for max"); //std::cout << m_env.worldRank() << ", maxRatio = " << maxRatio << std::endl; @@ -526,19 +526,19 @@ MLSampling::prepareUnbLinkedChains_inter0( unsigned int minModifiedSubNumSamples = 0; auxBuf[0] = subNumSamples; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &minModifiedSubNumSamples, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_MIN, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &minModifiedSubNumSamples, (int) auxBuf.size(), RawValue_MPI_MIN, "MLSampling::prepareUnbLinkedChains_inter0()", "failed MPI.Allreduce() for min"); unsigned int maxModifiedSubNumSamples = 0; auxBuf[0] = subNumSamples; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &maxModifiedSubNumSamples, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_MAX, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &maxModifiedSubNumSamples, (int) auxBuf.size(), RawValue_MPI_MAX, "MLSampling::prepareUnbLinkedChains_inter0()", "failed MPI.Allreduce() for max"); unsigned int sumModifiedSubNumSamples = 0; auxBuf[0] = subNumSamples; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &sumModifiedSubNumSamples, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &sumModifiedSubNumSamples, (int) auxBuf.size(), RawValue_MPI_SUM, "MLSampling::prepareUnbLinkedChains_inter0()", "failed MPI.Allreduce() for sum"); @@ -672,19 +672,19 @@ MLSampling::generateBalLinkedChains_all( // EXTRA FOR LOAD BALANCE unsigned int minNumberOfPositions = 0; auxBuf[0] = numberOfPositions; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &minNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_MIN, // LOAD BALANCE + m_env.inter0Comm().template Allreduce(&auxBuf[0], &minNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_MIN, // LOAD BALANCE "MLSampling::generateBalLinkedChains_all()", "failed MPI.Allreduce() for min"); unsigned int maxNumberOfPositions = 0; auxBuf[0] = numberOfPositions; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &maxNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_MAX, // LOAD BALANCE + m_env.inter0Comm().template Allreduce(&auxBuf[0], &maxNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_MAX, // LOAD BALANCE "MLSampling::generateBalLinkedChains_all()", "failed MPI.Allreduce() for max"); unsigned int sumNumberOfPositions = 0; auxBuf[0] = numberOfPositions; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &sumNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, // LOAD BALANCE + m_env.inter0Comm().template Allreduce(&auxBuf[0], &sumNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_SUM, // LOAD BALANCE "MLSampling::generateBalLinkedChains_all()", "failed MPI.Allreduce() for sum"); @@ -937,19 +937,19 @@ MLSampling::generateUnbLinkedChains_all( unsigned int minNumberOfPositions = 0; auxBuf[0] = numberOfPositions; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &minNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_MIN, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &minNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_MIN, "MLSampling::generateUnbLinkedChains_all()", "failed MPI.Allreduce() for min"); unsigned int maxNumberOfPositions = 0; auxBuf[0] = numberOfPositions; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &maxNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_MAX, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &maxNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_MAX, "MLSampling::generateUnbLinkedChains_all()", "failed MPI.Allreduce() for max"); unsigned int sumNumberOfPositions = 0; auxBuf[0] = numberOfPositions; - m_env.inter0Comm().Allreduce((void *) &auxBuf[0], (void *) &sumNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&auxBuf[0], &sumNumberOfPositions, (int) auxBuf.size(), RawValue_MPI_SUM, "MLSampling::generateUnbLinkedChains_all()", "failed MPI.Allreduce() for sum"); @@ -1940,9 +1940,11 @@ MLSampling::mpiExchangePositions_inter0( // EXTRA FOR LOAD BALANCE "failed MPI.Gatherv()"); } #else - m_env.inter0Comm().Gatherv((void *) &sendbuf[0], (int) sendcnt, RawValue_MPI_DOUBLE, (void *) &recvbuf[0], (int *) &recvcnts[0], (int *) &displs[0], RawValue_MPI_DOUBLE, r, // LOAD BALANCE - "MLSampling::mpiExchangePositions_inter0()", - "failed MPI.Gatherv()"); + m_env.inter0Comm().template Gatherv(&sendbuf[0], (int) sendcnt, + &recvbuf[0], (int *) &recvcnts[0], (int *) &displs[0], + r, // LOAD BALANCE + "MLSampling::mpiExchangePositions_inter0()", + "failed MPI.Gatherv()"); #endif ////////////////////////////////////////////////////////////////////////// @@ -2309,7 +2311,7 @@ MLSampling::generateSequence_Level0_all( if (m_env.inter0Rank() >= 0) { unsigned int tmpSize = currOptions.m_rawChainSize; - m_env.inter0Comm().Allreduce((void *) &tmpSize, (void *) &unifiedRequestedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&tmpSize, &unifiedRequestedNumSamples, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for requested num samples in level 0"); } @@ -2455,7 +2457,7 @@ MLSampling::generateSequence_Step01_inter0( unsigned int tmpSize = currOptions->m_rawChainSize; // This computed 'unifiedRequestedNumSamples' needs to be recomputed only at the last // level, when 'currOptions' is replaced by 'lastLevelOptions' (see step 3 of 11) - m_env.inter0Comm().Allreduce((void *) &tmpSize, (void *) &unifiedRequestedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&tmpSize, &unifiedRequestedNumSamples, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for requested num samples in step 1"); @@ -2717,7 +2719,7 @@ MLSampling::generateSequence_Step03_inter0( } #endif } - m_env.inter0Comm().Allreduce((void *) &subWeightRatioSum, (void *) &unifiedWeightRatioSum, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&subWeightRatioSum, &unifiedWeightRatioSum, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for weight ratio sum"); @@ -2775,7 +2777,7 @@ MLSampling::generateSequence_Step03_inter0( double subQuantity = effectiveSampleSize; effectiveSampleSize = 0.; - m_env.inter0Comm().Allreduce((void *) &subQuantity, (void *) &effectiveSampleSize, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&subQuantity, &effectiveSampleSize, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for effective sample size"); @@ -2964,7 +2966,7 @@ MLSampling::generateSequence_Step04_inter0( double localValue = subCovMatrix(i,j); double sumValue = 0.; if (m_env.inter0Rank() >= 0) { - m_env.inter0Comm().Allreduce((void *) &localValue, (void *) &sumValue, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&localValue, &sumValue, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for cov matrix"); } @@ -3573,7 +3575,7 @@ MLSampling::generateSequence_Step09_all( if (m_env.inter0Rank() >= 0) { // KAUST // If only one cov matrix is used, then the rejection should be assessed among all inter0Comm nodes // KAUST3 unsigned int nowUnifiedRejections = 0; - m_env.inter0Comm().Allreduce((void *) &nowRejections, (void *) &nowUnifiedRejections, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&nowRejections, &nowUnifiedRejections, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence_Step09_all()", "failed MPI.Allreduce() for now rejections"); @@ -3947,7 +3949,7 @@ MLSampling::generateSequence_Step11_inter0( // Check if unified size of generated chain matches the unified requested size // KAUST unsigned int tmpSize = currChain.subSequenceSize(); unsigned int unifiedGeneratedNumSamples = 0; - m_env.inter0Comm().Allreduce((void *) &tmpSize, (void *) &unifiedGeneratedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&tmpSize, &unifiedGeneratedNumSamples, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for generated num samples in step 11"); //std::cout << "unifiedGeneratedNumSamples = " << unifiedGeneratedNumSamples @@ -3957,7 +3959,7 @@ MLSampling::generateSequence_Step11_inter0( } // Compute unified number of rejections - m_env.inter0Comm().Allreduce((void *) &cumulativeRawChainRejections, (void *) &unifiedNumberOfRejections, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&cumulativeRawChainRejections, &unifiedNumberOfRejections, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for number of rejections"); @@ -4376,7 +4378,7 @@ MLSampling::generateSequence( // It is necessary to recompute 'currUnifiedRequestedNumSamples' because // 'currOptions' has just been replaced by 'lastLevelOptions' unsigned int tmpSize = currOptions->m_rawChainSize; - m_env.inter0Comm().Allreduce((void *) &tmpSize, (void *) &currUnifiedRequestedNumSamples, (int) 1, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&tmpSize, &currUnifiedRequestedNumSamples, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for requested num samples in step 3"); } @@ -4668,33 +4670,33 @@ MLSampling::generateSequence( if (m_env.inter0Rank() >= 0) { double minCumulativeRawChainRunTime = 0.; - m_env.inter0Comm().Allreduce((void *) &cumulativeRawChainRunTime, (void *) &minCumulativeRawChainRunTime, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_MIN, + m_env.inter0Comm().template Allreduce(&cumulativeRawChainRunTime, &minCumulativeRawChainRunTime, (int) 1, RawValue_MPI_MIN, "MLSampling::generateSequence()", "failed MPI.Allreduce() for min cumulative raw chain run time"); double maxCumulativeRawChainRunTime = 0.; - m_env.inter0Comm().Allreduce((void *) &cumulativeRawChainRunTime, (void *) &maxCumulativeRawChainRunTime, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_MAX, + m_env.inter0Comm().template Allreduce(&cumulativeRawChainRunTime, &maxCumulativeRawChainRunTime, (int) 1, RawValue_MPI_MAX, "MLSampling::generateSequence()", "failed MPI.Allreduce() for max cumulative raw chain run time"); double avgCumulativeRawChainRunTime = 0.; - m_env.inter0Comm().Allreduce((void *) &cumulativeRawChainRunTime, (void *) &avgCumulativeRawChainRunTime, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&cumulativeRawChainRunTime, &avgCumulativeRawChainRunTime, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for sum cumulative raw chain run time"); avgCumulativeRawChainRunTime /= ((double) m_env.inter0Comm().NumProc()); double minLevelRunTime = 0.; - m_env.inter0Comm().Allreduce((void *) &levelRunTime, (void *) &minLevelRunTime, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_MIN, + m_env.inter0Comm().template Allreduce(&levelRunTime, &minLevelRunTime, (int) 1, RawValue_MPI_MIN, "MLSampling::generateSequence()", "failed MPI.Allreduce() for min level run time"); double maxLevelRunTime = 0.; - m_env.inter0Comm().Allreduce((void *) &levelRunTime, (void *) &maxLevelRunTime, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_MAX, + m_env.inter0Comm().template Allreduce(&levelRunTime, &maxLevelRunTime, (int) 1, RawValue_MPI_MAX, "MLSampling::generateSequence()", "failed MPI.Allreduce() for max level run time"); double avgLevelRunTime = 0.; - m_env.inter0Comm().Allreduce((void *) &levelRunTime, (void *) &avgLevelRunTime, (int) 1, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + m_env.inter0Comm().template Allreduce(&levelRunTime, &avgLevelRunTime, (int) 1, RawValue_MPI_SUM, "MLSampling::generateSequence()", "failed MPI.Allreduce() for sum level run time"); avgLevelRunTime /= ((double) m_env.inter0Comm().NumProc()); diff --git a/src/stats/src/MetropolisHastingsSG.C b/src/stats/src/MetropolisHastingsSG.C index ba9e1b72e..001de3b95 100644 --- a/src/stats/src/MetropolisHastingsSG.C +++ b/src/stats/src/MetropolisHastingsSG.C @@ -118,13 +118,13 @@ MHRawChainInfoStruct::copy(const MHRawChainInfoStruct& rhs) } //--------------------------------------------------- void -MHRawChainInfoStruct::mpiSum(const MpiComm& comm, MHRawChainInfoStruct& sumInfo) const +MHRawChainInfoStruct::mpiSum(const MpiComm& comm, MHRawChainInfoStruct& sumInfo) { - comm.Allreduce((void *) &runTime, (void *) &sumInfo.runTime, (int) 7, RawValue_MPI_DOUBLE, RawValue_MPI_SUM, + comm.Allreduce(&runTime, &sumInfo.runTime, (int) 7, RawValue_MPI_SUM, "MHRawChainInfoStruct::mpiSum()", "failed MPI.Allreduce() for sum of doubles"); - comm.Allreduce((void *) &numTargetCalls, (void *) &sumInfo.numTargetCalls, (int) 5, RawValue_MPI_UNSIGNED, RawValue_MPI_SUM, + comm.Allreduce(&numTargetCalls, &sumInfo.numTargetCalls, (int) 5, RawValue_MPI_SUM, "MHRawChainInfoStruct::mpiSum()", "failed MPI.Allreduce() for sum of unsigned ints"); diff --git a/src/stats/src/StatisticalInverseProblem.C b/src/stats/src/StatisticalInverseProblem.C index 4a4ce2450..e76ece811 100644 --- a/src/stats/src/StatisticalInverseProblem.C +++ b/src/stats/src/StatisticalInverseProblem.C @@ -27,6 +27,7 @@ #include #include #include +#include namespace QUESO { @@ -257,11 +258,25 @@ StatisticalInverseProblem::solveWithBayesMetropolisHastings( // user-provided initial seed, or use the user-provided seed for a // deterministic optimisation instead and seed the chain with the result of // the optimisation - if (this->m_seedWithMAPEstimator) { + if (this->m_seedWithMAPEstimator || + m_optionsObj->m_seedWithMAPEstimator) { + // Unfortunately, I didn't have the foresight to make this an input file + // option from the beginning, hence needing to check two flags + // Do optimisation before sampling GslOptimizer optimizer(*m_solutionPdf); optimizer.setInitialPoint(dynamic_cast(initialValues)); - optimizer.minimize(); + + OptimizerMonitor monitor(m_env); + monitor.set_display_output(true, true); + + // If the input file option is set, then use the monitor, otherwise don't + if (m_optionsObj->m_useOptimizerMonitor) { + optimizer.minimize(&monitor); + } + else { + optimizer.minimize(); + } // Compute output realizer: Metropolis-Hastings approach m_mhSeqGenerator = new MetropolisHastingsSG( diff --git a/src/stats/src/StatisticalInverseProblemOptions.C b/src/stats/src/StatisticalInverseProblemOptions.C index 58899770c..b56c20cd5 100644 --- a/src/stats/src/StatisticalInverseProblemOptions.C +++ b/src/stats/src/StatisticalInverseProblemOptions.C @@ -41,16 +41,20 @@ SipOptionsValues::SipOptionsValues() m_help(UQ_SIP_HELP), m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ), m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV), + m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR), + m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR), //m_dataOutputAllowedSet(), m_parser(NULL), m_option_help (m_prefix + "help" ), m_option_computeSolution (m_prefix + "computeSolution" ), m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ), - m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet") + m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"), #ifdef UQ_SIP_READS_SOLVER_OPTION m_option_solver (m_prefix + "solver" ), m_solverString (UQ_SIP_SOLVER_ODV) #endif + m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"), + m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor") { } @@ -61,16 +65,20 @@ SipOptionsValues::SipOptionsValues(const BaseEnvironment * env, const char * m_help(UQ_SIP_HELP), m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ), m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV), + m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR), + m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR), //m_dataOutputAllowedSet(), m_parser(new BoostInputOptionsParser(env->optionsInputFileName())), m_option_help (m_prefix + "help" ), m_option_computeSolution (m_prefix + "computeSolution" ), m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ), - m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet") + m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"), #ifdef UQ_SIP_READS_SOLVER_OPTION m_option_solver (m_prefix + "solver" ), m_solverString (UQ_SIP_SOLVER_ODV) #endif + m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"), + m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor") { m_parser->registerOption(m_option_help, UQ_SIP_HELP, "produce help message for statistical inverse problem"); m_parser->registerOption(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV , "compute solution process" ); @@ -79,6 +87,8 @@ SipOptionsValues::SipOptionsValues(const BaseEnvironment * env, const char * #ifdef UQ_SIP_READS_SOLVER_OPTION m_parser->registerOption(m_option_solver, UQ_SIP_SOLVER_ODV , "algorithm for calibration" ); #endif + m_parser->registerOption(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR , "toggle for seeding chain at MAP" ); + m_parser->registerOption(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR , "toggle for using optimizer monitor (prints diagnostics"); m_parser->scanInputFile(); @@ -89,6 +99,8 @@ SipOptionsValues::SipOptionsValues(const BaseEnvironment * env, const char * #ifdef UQ_SIP_READS_SOLVER_OPTION m_parser->getOption(m_option_solver, m_solver); #endif + m_parser->getOption(m_option_seedWithMAPEstimator, m_seedWithMAPEstimator); + m_parser->getOption(m_option_useOptimizerMonitor, m_useOptimizerMonitor); checkOptions(); } @@ -125,9 +137,8 @@ SipOptionsValues::copy(const SipOptionsValues& src) #ifdef UQ_SIP_READS_SOLVER_OPTION m_solverString = src.m_solverString; #endif -//m_mhOptionsValues = src.m_mhOptionsValues; - - return; + m_seedWithMAPEstimator = src.m_seedWithMAPEstimator; + m_useOptimizerMonitor = src.m_useOptimizerMonitor; } std::ostream & @@ -162,10 +173,12 @@ StatisticalInverseProblemOptions::StatisticalInverseProblemOptions( m_option_help (m_prefix + "help" ), m_option_computeSolution (m_prefix + "computeSolution" ), m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ), - m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet") + m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"), #ifdef UQ_SIP_READS_SOLVER_OPTION m_option_solver (m_prefix + "solver" ) #endif + m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"), + m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor") { queso_deprecated(); queso_require_not_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the absence of an options input file"); @@ -184,10 +197,12 @@ StatisticalInverseProblemOptions::StatisticalInverseProblemOptions( m_option_help (m_prefix + "help" ), m_option_computeSolution (m_prefix + "computeSolution" ), m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ), - m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet") + m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"), #ifdef UQ_SIP_READS_SOLVER_OPTION m_option_solver (m_prefix + "solver" ) #endif + m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"), + m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor") { queso_deprecated(); @@ -216,11 +231,7 @@ StatisticalInverseProblemOptions::scanOptionsValues() defineMyOptions (*m_optionsDesc); m_env.scanInputFileForMyOptions(*m_optionsDesc); - //std::cout << "scan 000\n" - // << std::endl; getMyOptionValues (*m_optionsDesc); - //std::cout << "scan 001\n" - // << std::endl; if (m_env.subDisplayFile() != NULL) { *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::scanOptionsValues()" @@ -248,11 +259,13 @@ StatisticalInverseProblemOptions::print(std::ostream& os) const #ifdef UQ_SIP_READS_SOLVER_OPTION << "\n" << m_option_solver << " = " << m_ov.m_solverString #endif + os << "\n" << m_option_seedWithMAPEstimator << " = " << m_ov.m_seedWithMAPEstimator + << "\n" << m_option_useOptimizerMonitor << " = " << m_ov.m_useOptimizerMonitor; os << std::endl; return; } -// Private methods --------------------------------- + void StatisticalInverseProblemOptions::defineMyOptions(boost::program_options::options_description& optionsDesc) const { @@ -266,9 +279,9 @@ StatisticalInverseProblemOptions::defineMyOptions(boost::program_options::option #ifdef UQ_SIP_READS_SOLVER_OPTION (m_option_solver.c_str(), boost::program_options::value()->default_value(UQ_SIP_SOLVER_ODV ), "algorithm for calibration" ) #endif + (m_option_seedWithMAPEstimator.c_str(), boost::program_options::value()->default_value(UQ_SIP_SEEDWITHMAPESTIMATOR), "toggle optimisation of posterior pdf before sampling") + (m_option_useOptimizerMonitor.c_str(), boost::program_options::value()->default_value(UQ_SIP_USEOPTIMIZERMONITOR), "toggle printing of optimisation progress when seed with MAP estimator") ; - - return; } //-------------------------------------------------- void @@ -310,7 +323,13 @@ StatisticalInverseProblemOptions::getMyOptionValues(boost::program_options::opti } #endif - return; + if (m_env.allOptionsMap().count(m_option_seedWithMAPEstimator)) { + m_ov.m_seedWithMAPEstimator = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_seedWithMAPEstimator]).as(); + } + + if (m_env.allOptionsMap().count(m_option_useOptimizerMonitor)) { + m_ov.m_useOptimizerMonitor = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_useOptimizerMonitor]).as(); + } } // -------------------------------------------------- diff --git a/src/stats/src/TKGroup.C b/src/stats/src/TKGroup.C index 15f4e0ae2..376ec9664 100644 --- a/src/stats/src/TKGroup.C +++ b/src/stats/src/TKGroup.C @@ -36,9 +36,9 @@ BaseTKGroup::BaseTKGroup() m_env (*m_emptyEnv), m_prefix (""), m_vectorSpace (NULL), - m_scales (0), - m_preComputingPositions(NULL), - m_rvs (0) + m_scales (), + m_preComputingPositions(), + m_rvs () { } // Constructor with values--------------------------- diff --git a/src/stats/src/VectorCdf.C b/src/stats/src/VectorCdf.C index d0a6bd40b..56505ae16 100644 --- a/src/stats/src/VectorCdf.C +++ b/src/stats/src/VectorCdf.C @@ -64,18 +64,13 @@ BaseVectorCdf::pdfSupport() const template void BaseVectorCdf::subWriteContents( - const std::string& varNamePrefix, - const std::string& fileName, - const std::string& fileType, - const std::set& allowedSubEnvIds) const + const std::string& /* varNamePrefix */, + const std::string& /* fileName */, + const std::string& /* fileType */, + const std::set& /* allowedSubEnvIds */) const { std::cerr << "WARNING: BaseVectorCdf::subWriteContents() being used..." << std::endl; - - if (&varNamePrefix) {}; // just to remove compiler warning - if (&fileName) {}; // just to remove compiler warning - if (&fileType) {}; // just to remove compiler warning - if (&allowedSubEnvIds) {}; // just to remove compiler warning return; } diff --git a/src/stats/src/VectorRV.C b/src/stats/src/VectorRV.C index c3f2d5b4e..5a3f7a969 100644 --- a/src/stats/src/VectorRV.C +++ b/src/stats/src/VectorRV.C @@ -26,6 +26,9 @@ #include #include +#include +#include // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc) + namespace QUESO { // Default constructor ----------------------------- @@ -203,8 +206,6 @@ ComputeCovCorrMatricesBetweenVectorRvs( P_M& pqCorrMatrix) { // Check input data consistency - const BaseEnvironment& env = paramRv.env(); - bool useOnlyInter0Comm = (paramRv.imageSet().vectorSpace().numOfProcsForStorage() == 1) && (qoiRv.imageSet().vectorSpace().numOfProcsForStorage() == 1); diff --git a/src/surrogates/src/InterpolationSurrogateBuilder.C b/src/surrogates/src/InterpolationSurrogateBuilder.C index 5e7a81085..a4a8d7d6f 100644 --- a/src/surrogates/src/InterpolationSurrogateBuilder.C +++ b/src/surrogates/src/InterpolationSurrogateBuilder.C @@ -26,6 +26,7 @@ #include // QUESO +#include #include #include #include @@ -156,17 +157,15 @@ namespace QUESO /*! \todo Would be more efficient to pack local_n and local_values togethers and do Gatherv only once. */ - inter0comm.Gatherv( &local_n[0], local_n.size(), MPI_UNSIGNED, - &all_indices[0], &m_njobs[0], &strides[0], MPI_UNSIGNED, - 0 /*root*/, - "InterpolationSurrogateBuilder::sync_data()", - "MpiComm::gatherv() failed!" ); - - inter0comm.Gatherv( &local_values[0], local_values.size(), MPI_DOUBLE, - &all_values[0], &m_njobs[0], &strides[0], MPI_DOUBLE, - 0 /*root*/, - "InterpolationSurrogateBuilder::sync_data()", - "MpiComm::gatherv() failed!" ); + inter0comm.template Gatherv(&local_n[0], local_n.size(), + &all_indices[0], &m_njobs[0], &strides[0], + 0 /*root*/, "InterpolationSurrogateBuilder::sync_data()", + "MpiComm::gatherv() failed!"); + + inter0comm.template Gatherv(&local_values[0], + local_values.size(), &all_values[0], &m_njobs[0], &strides[0], + 0 /*root*/, "InterpolationSurrogateBuilder::sync_data()", + "MpiComm::gatherv() failed!"); // Now set the values. /* PB: Although we are guaranteed per-rank ordering of the data we gathered, diff --git a/src/surrogates/src/InterpolationSurrogateData.C b/src/surrogates/src/InterpolationSurrogateData.C index 04dd912b2..e0126d4ce 100644 --- a/src/surrogates/src/InterpolationSurrogateData.C +++ b/src/surrogates/src/InterpolationSurrogateData.C @@ -26,6 +26,7 @@ #include // QUESO +#include #include #include @@ -120,7 +121,7 @@ namespace QUESO MpiComm full_comm = this->m_domain.env().fullComm(); full_comm.Bcast( &this->m_values[0], this->n_values(), - MPI_DOUBLE, root, + RawValue_MPI_DOUBLE, root, "InterpolationSurrogateData::sync_values()", "MpiComm::Bcast() failed!" ); } diff --git a/src/surrogates/src/InterpolationSurrogateIOASCII.C b/src/surrogates/src/InterpolationSurrogateIOASCII.C index 03c97a3e8..577eb839e 100644 --- a/src/surrogates/src/InterpolationSurrogateIOASCII.C +++ b/src/surrogates/src/InterpolationSurrogateIOASCII.C @@ -26,6 +26,7 @@ #include // QUESO +#include #include #include #include @@ -48,7 +49,7 @@ namespace QUESO int reading_rank ) { // Root processor - int root = reading_rank; + unsigned int root = reading_rank; MpiComm full_comm = env.fullComm(); @@ -70,7 +71,7 @@ namespace QUESO } // Broadcast the parsed dimension - full_comm.Bcast( &dim, 1, MPI_UNSIGNED, root, + full_comm.Bcast( &dim, 1, RawValue_MPI_UNSIGNED, root, "InterpolationSurrogateIOASCII::read()", "MpiComm::Bcast() failed!" ); @@ -99,7 +100,7 @@ namespace QUESO } // Broadcast m_n_points - full_comm.Bcast( &this->m_n_points[0], dim, MPI_UNSIGNED, root, + full_comm.Bcast( &this->m_n_points[0], dim, RawValue_MPI_UNSIGNED, root, "InterpolationSurrogateIOASCII::read()", "MpiComm::Bcast() failed!" ); @@ -123,11 +124,11 @@ namespace QUESO } // Broadcast the bounds - full_comm.Bcast( ¶m_mins[0], dim, MPI_DOUBLE, root, + full_comm.Bcast( ¶m_mins[0], dim, RawValue_MPI_DOUBLE, root, "InterpolationSurrogateIOASCII::read()", "MpiComm::Bcast() failed!" ); - full_comm.Bcast( ¶m_maxs[0], dim, MPI_DOUBLE, root, + full_comm.Bcast( ¶m_maxs[0], dim, RawValue_MPI_DOUBLE, root, "InterpolationSurrogateIOASCII::read()", "MpiComm::Bcast() failed!" ); diff --git a/test/Makefile.am b/test/Makefile.am index 79f7e9f3a..7d99d95f8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -51,6 +51,9 @@ check_PROGRAMS += test_InterpolationSurrogateHelper check_PROGRAMS += test_build_InterpolationSurrogateBuilder check_PROGRAMS += test_BoostInputOptionsParser check_PROGRAMS += test_NoInputFile +check_PROGRAMS += test_optimizer_options +check_PROGRAMS += test_SharedPtr +check_PROGRAMS += test_serialEnv LDADD = $(top_builddir)/src/libqueso.la @@ -127,6 +130,9 @@ test_InterpolationSurrogateHelper_SOURCES = test_InterpolationSurrogate/test_Int test_build_InterpolationSurrogateBuilder_SOURCES = test_InterpolationSurrogate/test_build_InterpolationSurrogateBuilder.C test_BoostInputOptionsParser_SOURCES = test_InputOptionsParser/test_BoostInputOptionsParser.C test_NoInputFile_SOURCES = test_StatisticalInverseProblem/test_NoInputFile.C +test_optimizer_options_SOURCES = test_optimizer/test_optimizer_options.C +test_SharedPtr_SOURCES = pointers/test_SharedPtr.C +test_serialEnv_SOURCES = test_Environment/test_serialEnv.C # Files to freedom stamp srcstamp = @@ -175,6 +181,9 @@ srcstamp += $(test_InterpolationSurrogateHelper_SOURCES) srcstamp += $(test_build_InterpolationSurrogateBuilder_SOURCES) srcstamp += $(test_BoostInputOptionsParser_SOURCES) srcstamp += $(test_NoInputFile_SOURCES) +srcstamp += $(test_optimizer_options_SOURCES) +srcstamp += $(test_SharedPtr_SOURCES) +srcstamp += $(test_serialEnv_SOURCES) TESTS = TESTS += $(top_builddir)/test/test_uqEnvironmentNonFatal @@ -223,8 +232,15 @@ TESTS += $(top_builddir)/test/test_InterpolationSurrogateHelper TESTS += $(top_builddir)/test/test_build_InterpolationSurrogateBuilder TESTS += $(top_builddir)/test/test_BoostInputOptionsParser TESTS += $(top_builddir)/test/test_NoInputFile +TESTS += $(top_builddir)/test/test_optimizer_options +TESTS += $(top_builddir)/test/test_SharedPtr +TESTS += $(top_builddir)/test/test_serialEnv XFAIL_TESTS = $(top_builddir)/test/test_SequenceOfVectorsErase +if ! MPI_ENABLED +XFAIL_TESTS += $(top_builddir)/test/test_SequenceOfVectors/test_unifiedPositionsOfMaximum.sh +endif + EXTRA_DIST = EXTRA_DIST += common/compare.pl @@ -251,6 +267,8 @@ EXTRA_DIST += test_SequenceOfVectors/test_unifiedPositionsOfMaximum.sh.in EXTRA_DIST += test_InputOptionsParser/test_options_good.txt.in EXTRA_DIST += test_InputOptionsParser/test_options_bad.txt.in EXTRA_DIST += test_InputOptionsParser/test_options_default.txt.in +EXTRA_DIST += test_optimizer/input_test_optimizer_options.in +EXTRA_DIST += test_Environment/input_test_serialEnv.in CLEANFILES = CLEANFILES += test_Environment/debug_output_sub0.txt @@ -266,6 +284,8 @@ clean-local: rm -rf $(top_builddir)/test/test_adaptedcov_output rm -rf $(top_builddir)/test/test_outputNoInputFile rm -rf $(top_builddir)/test/test_output_interp_surrogates + rm -rf $(top_builddir)/test/output_test_optimizer_options + rm -rf $(top_builddir)/test/output_test_serialEnv if CODE_COVERAGE_ENABLED CLEANFILES += *.gcda *.gcno diff --git a/test/gsl_tests/get_min_max_vec.C b/test/gsl_tests/get_min_max_vec.C index 5eb62c6a1..1e663f19e 100644 --- a/test/gsl_tests/get_min_max_vec.C +++ b/test/gsl_tests/get_min_max_vec.C @@ -31,14 +31,20 @@ int main(int argc, char* argv[]) int return_flag = 0; // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"input","",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment("input","",NULL); +#endif return_flag = actualChecking(env); // Deallocate pointers we created. delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif // Fin. return return_flag; diff --git a/test/gsl_tests/get_set_row_column.C b/test/gsl_tests/get_set_row_column.C index e2592a00d..7633bf15b 100644 --- a/test/gsl_tests/get_set_row_column.C +++ b/test/gsl_tests/get_set_row_column.C @@ -31,13 +31,19 @@ int main(int argc, char* argv[]) int return_flag = 0; // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"input","",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment("input","",NULL); +#endif return_flag = actualChecking(env); delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif // Fin. return return_flag; diff --git a/test/gsl_tests/inverse_power_method.C b/test/gsl_tests/inverse_power_method.C index 26a7eb735..6c146d7e6 100644 --- a/test/gsl_tests/inverse_power_method.C +++ b/test/gsl_tests/inverse_power_method.C @@ -35,14 +35,19 @@ int main(int argc, char* argv[]) int return_flag = 0; // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); - QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"input","",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment("input","",NULL); +#endif return_flag = actualChecking(env); delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif // Fin. return return_flag; diff --git a/test/gsl_tests/multiple_rhs_matrix_solve.C b/test/gsl_tests/multiple_rhs_matrix_solve.C index 18649a74f..56000d667 100644 --- a/test/gsl_tests/multiple_rhs_matrix_solve.C +++ b/test/gsl_tests/multiple_rhs_matrix_solve.C @@ -31,14 +31,19 @@ int main(int argc, char* argv[]) int return_flag = 0; // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); - QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"input","",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment("input","",NULL); +#endif return_flag = actualChecking(env); delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif // Fin. return return_flag; diff --git a/test/gsl_tests/power_method.C b/test/gsl_tests/power_method.C index ea5c3df75..d0799c93f 100644 --- a/test/gsl_tests/power_method.C +++ b/test/gsl_tests/power_method.C @@ -35,14 +35,19 @@ int main(int argc, char* argv[]) int return_flag = 0; // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); - QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"input","",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment("input","",NULL); +#endif return_flag = actualChecking(env); delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif // Fin. return return_flag; } diff --git a/test/pointers/test_SharedPtr.C b/test/pointers/test_SharedPtr.C new file mode 100644 index 000000000..c3ae039e2 --- /dev/null +++ b/test/pointers/test_SharedPtr.C @@ -0,0 +1,39 @@ +//-----------------------------------------------------------------------bl- +//-------------------------------------------------------------------------- +// +// QUESO - a library to support the Quantification of Uncertainty +// for Estimation, Simulation and Optimization +// +// Copyright (C) 2008-2015 The PECOS Development Team +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Version 2.1 GNU Lesser General +// Public License as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc. 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301 USA +// +//-----------------------------------------------------------------------el- + +#include +#include + +int main(int argc, char* argv[]) +{ + QUESO::SharedPtr::Type int_ptr1(new int(1)); + + QUESO::SharedPtr::Type int_ptr2(int_ptr1); + + *int_ptr2 = 2; + + queso_require_equal_to_msg(*int_ptr1, 2, "pointed-to values are not equal!"); + + return 0; +} diff --git a/test/t01_valid_cycle/TgaValidationCycle_gsl.C b/test/t01_valid_cycle/TgaValidationCycle_gsl.C index d0a2860ed..50415c8c8 100644 --- a/test/t01_valid_cycle/TgaValidationCycle_gsl.C +++ b/test/t01_valid_cycle/TgaValidationCycle_gsl.C @@ -39,12 +39,16 @@ int main(int argc, char* argv[]) //************************************************ // Initialize environment //************************************************ +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); UQ_FATAL_TEST_MACRO(argc != 2, QUESO::UQ_UNAVAILABLE_RANK, "main()", "input file must be specified in command line as argv[1], just after executable argv[0]"); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",NULL); +#endif //************************************************ // Run application @@ -59,6 +63,8 @@ int main(int argc, char* argv[]) // Finalize environment //************************************************ delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/t02_sip_sfp/example_main.C b/test/t02_sip_sfp/example_main.C index c33d87059..bc379f48a 100644 --- a/test/t02_sip_sfp/example_main.C +++ b/test/t02_sip_sfp/example_main.C @@ -27,6 +27,7 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); UQ_FATAL_TEST_MACRO(argc != 2, QUESO::UQ_UNAVAILABLE_RANK, @@ -34,11 +35,17 @@ int main(int argc, char* argv[]) "input file must be specified in command line as argv[1], just after executable argv[0]"); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = + new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute compute(*env); // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/t03_sequence/example_main.C b/test/t03_sequence/example_main.C index 4a8377100..5fe404ca5 100644 --- a/test/t03_sequence/example_main.C +++ b/test/t03_sequence/example_main.C @@ -39,14 +39,20 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute compute(*env); // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/t04_bimodal/example_main.C b/test/t04_bimodal/example_main.C index 1c98d1163..b6f64dc78 100644 --- a/test/t04_bimodal/example_main.C +++ b/test/t04_bimodal/example_main.C @@ -27,14 +27,20 @@ int main(int argc, char* argv[]) { // Initialize environment +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,argv[1],"",NULL); +#else + QUESO::FullEnvironment* env = new QUESO::FullEnvironment(argv[1],"",NULL); +#endif // Compute compute(*env); // Finalize environment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_DistArray/test_DistArrayCopy.C b/test/test_DistArray/test_DistArrayCopy.C index 64a7c64e7..7cee0c813 100644 --- a/test/test_DistArray/test_DistArrayCopy.C +++ b/test/test_DistArray/test_DistArrayCopy.C @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,13 +5,20 @@ #include int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = + new QUESO::FullEnvironment("", "", &options); +#endif const QUESO::MpiComm & comm = env->fullComm(); @@ -28,6 +34,8 @@ int main(int argc, char **argv) { return 0; } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 1; } diff --git a/test/test_DistArray/test_DistArrayEquals.C b/test/test_DistArray/test_DistArrayEquals.C index c9cfec1aa..51e3a5e25 100644 --- a/test/test_DistArray/test_DistArrayEquals.C +++ b/test/test_DistArray/test_DistArrayEquals.C @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,13 +5,20 @@ #include int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = + new QUESO::FullEnvironment("", "", &options); +#endif const QUESO::MpiComm & comm = env->fullComm(); @@ -29,6 +35,8 @@ int main(int argc, char **argv) { return 0; } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 1; } diff --git a/test/test_DistArray/test_DistArrayMisc.C b/test/test_DistArray/test_DistArrayMisc.C index d36e9f137..85984f73e 100644 --- a/test/test_DistArray/test_DistArrayMisc.C +++ b/test/test_DistArray/test_DistArrayMisc.C @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,13 +5,20 @@ #include int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = + new QUESO::FullEnvironment("", "", &options); +#endif const QUESO::MpiComm & comm = env->fullComm(); @@ -34,6 +40,8 @@ int main(int argc, char **argv) { std::cerr << "d is: " << std::endl; std::cerr << d << std::endl; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_Environment/input_test_serialEnv.in b/test/test_Environment/input_test_serialEnv.in new file mode 100644 index 000000000..0e42c025e --- /dev/null +++ b/test/test_Environment/input_test_serialEnv.in @@ -0,0 +1,51 @@ +############################################### +# UQ Environment +############################################### +#env_help = anything +env_numSubEnvironments = 1 +env_subDisplayFileName = output_test_serialEnv/display +env_subDisplayAllowAll = 0 +env_subDisplayAllowedSet = 0 +env_displayVerbosity = 2 +env_syncVerbosity = 0 +env_seed = 0 + +############################################### +# Statistical inverse problem (ip) +############################################### +#ip_help = anything +ip_computeSolution = 1 +ip_dataOutputFileName = output_test_serialEnv/sipOutput +ip_dataOutputAllowedSet = 0 + +############################################### +# 'ip_': information for Metropolis-Hastings algorithm +############################################### +#ip_mh_help = anything +ip_mh_dataOutputFileName = output_test_serialEnv/sipOutput +ip_mh_dataOutputAllowedSet = 0 1 + +ip_mh_rawChain_dataInputFileName = . +ip_mh_rawChain_size = 10 +ip_mh_rawChain_generateExtra = 0 +ip_mh_rawChain_displayPeriod = 50000 +ip_mh_rawChain_measureRunTimes = 1 +ip_mh_rawChain_dataOutputFileName = output_test_serialEnv/ip_raw_chain +ip_mh_rawChain_dataOutputAllowedSet = 0 1 +ip_mh_rawChain_computeStats = 1 + +ip_mh_displayCandidates = 0 +ip_mh_putOutOfBoundsInChain = 0 +ip_mh_tk_useLocalHessian = 0 +ip_mh_tk_useNewtonComponent = 1 +ip_mh_dr_maxNumExtraStages = 1 +ip_mh_dr_listOfScalesForExtraStages = 5. +ip_mh_am_initialNonAdaptInterval = 0 +ip_mh_am_adaptInterval = 100 +ip_mh_am_eta = 1.92 +ip_mh_am_epsilon = 1.e-5 + +ip_mh_filteredChain_generate = 0 + +ip_mh_outputLogLikelihood = 0 +ip_mh_outputLogTarget = 0 diff --git a/test/test_Environment/test_serialEnv.C b/test/test_Environment/test_serialEnv.C new file mode 100644 index 000000000..d6af4f83c --- /dev/null +++ b/test/test_Environment/test_serialEnv.C @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include +#include + +template +class Likelihood : public QUESO::BaseScalarFunction +{ +public: + + Likelihood(const char * prefix, const QUESO::VectorSet & domain) + : QUESO::BaseScalarFunction(prefix, domain) {} + + virtual ~Likelihood() {} + + virtual double lnValue(const V & domainVector, const V * domainDirection, + V * gradVector, M * hessianMatrix, V * hessianEffect) const + { + double misfit = 1.0; + + return -0.5 * misfit; + } + + virtual double actualValue(const V & domainVector, const V * domainDirection, + V * gradVector, M * hessianMatrix, V * hessianEffect) const + { + return std::exp(this->lnValue(domainVector, domainDirection, gradVector, + hessianMatrix, hessianEffect)); + } +}; + +int main(int argc, char ** argv) { + QUESO::FullEnvironment env("test_Environment/input_test_serialEnv", "", + NULL); + + QUESO::VectorSpace<> paramSpace(env, "param_", 1, NULL); + + QUESO::GslVector paramMins(paramSpace.zeroVector()); + QUESO::GslVector paramMaxs(paramSpace.zeroVector()); + + double min_val = 0.0; + double max_val = 1.0; + paramMins.cwSet(min_val); + paramMaxs.cwSet(max_val); + + QUESO::BoxSubset<> paramDomain("param_", paramSpace, paramMins, paramMaxs); + + QUESO::UniformVectorRV<> priorRv("prior_", paramDomain); + + Likelihood<> lhood("llhd_", paramDomain); + + QUESO::GenericVectorRV<> postRv("post_", paramSpace); + + QUESO::StatisticalInverseProblem<> ip("", NULL, priorRv, lhood, postRv); + + QUESO::GslVector paramInitials(paramSpace.zeroVector()); + paramInitials[0] = 0.0; + + QUESO::GslMatrix proposalCovMatrix(paramSpace.zeroVector()); + proposalCovMatrix(0, 0) = 0.1; + + ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); + + return 0; +} diff --git a/test/test_Environment/test_uqEnvironmentNonFatal.C b/test/test_Environment/test_uqEnvironmentNonFatal.C index aab7ad0d6..4cb3fc564 100644 --- a/test/test_Environment/test_uqEnvironmentNonFatal.C +++ b/test/test_Environment/test_uqEnvironmentNonFatal.C @@ -3,12 +3,12 @@ #include #include -#include - using namespace std; int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; @@ -24,7 +24,11 @@ int main(int argc, char **argv) { /* options.m_subDisplayAllowedSet = subDisplayAllowed; */ /* options.m_subDisplayAllowAll = 0; */ +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = new QUESO::FullEnvironment("", "", &options); +#endif if (!env->fullEnvIsReady()) { std::cerr << "Full env ready test failed" << std::endl; @@ -102,7 +106,9 @@ int main(int argc, char **argv) { } delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif /* * This code should never get here. If it does, the bash script that wraps diff --git a/test/test_GaussianVectorRVClass/test_VectorPdf_gsl.C b/test/test_GaussianVectorRVClass/test_VectorPdf_gsl.C index 3e2e89180..5dae78ae7 100644 --- a/test/test_GaussianVectorRVClass/test_VectorPdf_gsl.C +++ b/test/test_GaussianVectorRVClass/test_VectorPdf_gsl.C @@ -25,10 +25,16 @@ int require_close(double a, double b, double tol) { int main(int argc, char ** argv) { // Initialize +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif EnvOptionsValues envOptionsValues; +#ifdef QUESO_HAS_MPI FullEnvironment env(MPI_COMM_WORLD, "", "", &envOptionsValues); +#else + FullEnvironment env("", "", &envOptionsValues); +#endif VectorSpace domainSpace(env, "test_space", 2, NULL); Map eMap(2, 0, env.fullComm()); @@ -272,7 +278,9 @@ int main(int argc, char ** argv) { delete gaussianPdf; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_GaussianVectorRVClass/test_VectorRV_gsl.C b/test/test_GaussianVectorRVClass/test_VectorRV_gsl.C index fe3a3f5f2..ce463caeb 100644 --- a/test/test_GaussianVectorRVClass/test_VectorRV_gsl.C +++ b/test/test_GaussianVectorRVClass/test_VectorRV_gsl.C @@ -24,10 +24,16 @@ int require_close(double a, double b, double tol) { } int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif EnvOptionsValues envOptionsValues; +#ifdef QUESO_HAS_MPI FullEnvironment env(MPI_COMM_WORLD, "", "", &envOptionsValues); +#else + FullEnvironment env("", "", &envOptionsValues); +#endif VectorSpace imageSpace(env, "test_space", 2, NULL); Map eMap(2, 0, env.fullComm()); @@ -73,7 +79,9 @@ int main(int argc, char ** argv) { std::cout << myRealization; // finalize +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_GaussianVectorRVClass/test_VectorRealizer_gsl.C b/test/test_GaussianVectorRVClass/test_VectorRealizer_gsl.C index 808cdf86e..cf5072d39 100644 --- a/test/test_GaussianVectorRVClass/test_VectorRealizer_gsl.C +++ b/test/test_GaussianVectorRVClass/test_VectorRealizer_gsl.C @@ -30,10 +30,16 @@ int require_close(double a, double b, double tol) { } int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif EnvOptionsValues envOptionsValues; +#ifdef QUESO_HAS_MPI FullEnvironment env(MPI_COMM_WORLD, "", "", &envOptionsValues); +#else + FullEnvironment env("", "", &envOptionsValues); +#endif VectorSpace imageSpace(env, "test_space", 2, NULL); Map eMap(2, 0, env.fullComm()); @@ -94,7 +100,9 @@ int main(int argc, char ** argv) { delete gaussianRealizer; // Clean up +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_GaussianVectorRVClass/test_uqGaussianVectorRVClass.C b/test/test_GaussianVectorRVClass/test_uqGaussianVectorRVClass.C index e330a3abe..b0265ed3c 100644 --- a/test/test_GaussianVectorRVClass/test_uqGaussianVectorRVClass.C +++ b/test/test_GaussianVectorRVClass/test_uqGaussianVectorRVClass.C @@ -26,8 +26,12 @@ int main(int argc, char **argv) { QUESO::EnvOptionsValues *opts = new QUESO::EnvOptionsValues(); opts->m_seed = seed; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", opts); +#else + QUESO::FullEnvironment *env = new QUESO::FullEnvironment("", "", opts); +#endif QUESO::VectorSpace *param_space; param_space = new QUESO::VectorSpace( @@ -108,6 +112,8 @@ int main(int argc, char **argv) { delete param_space; delete param_domain; delete prior; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return return_val; } diff --git a/test/test_GslBlockMatrix/test_GslBlockMatrixInvertMultiply.C b/test/test_GslBlockMatrix/test_GslBlockMatrixInvertMultiply.C index 014da04de..0ba8d9c41 100644 --- a/test/test_GslBlockMatrix/test_GslBlockMatrixInvertMultiply.C +++ b/test/test_GslBlockMatrix/test_GslBlockMatrixInvertMultiply.C @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -10,12 +8,18 @@ #define TOL 1e-10 int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment env("", "", &options); +#endif QUESO::VectorSpace paramSpace(env, "param_", 3, NULL); @@ -64,6 +68,8 @@ int main(int argc, char **argv) { queso_error_msg("TEST: GslBlockMatrix::invertMultiply failed."); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_GslMatrix/test_uqGslMatrix.C b/test/test_GslMatrix/test_uqGslMatrix.C index 218c6288a..58a802b70 100644 --- a/test/test_GslMatrix/test_uqGslMatrix.C +++ b/test/test_GslMatrix/test_uqGslMatrix.C @@ -4,7 +4,6 @@ #include #include -#include #define TOL 1e-10 using namespace std; @@ -44,12 +43,19 @@ int main(int argc, char **argv) { unsigned int i, j; double diagValue = 1.5; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = + new QUESO::FullEnvironment("", "", &options); +#endif QUESO::VectorSpace *param_space = new QUESO::VectorSpace(*env, "param_", 3, NULL); @@ -237,6 +243,8 @@ int main(int argc, char **argv) { return 1; } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_GslVector/test_uqGslVector.C b/test/test_GslVector/test_uqGslVector.C index c26e10d52..b79ebfdc3 100644 --- a/test/test_GslVector/test_uqGslVector.C +++ b/test/test_GslVector/test_uqGslVector.C @@ -6,8 +6,6 @@ #include #include -#include - #define TOL 1e-10 int checkLinearSpacing(const QUESO::GslVector &v, double d1, double d2) { @@ -29,12 +27,18 @@ int main(int argc, char **argv) { double d1 = 0.0; double d2 = 1.0; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = new QUESO::FullEnvironment("", "", &options); +#endif QUESO::VectorSpace *param_space = new QUESO::VectorSpace(*env, "param_", 3, NULL); @@ -75,9 +79,9 @@ int main(int argc, char **argv) { } // Testing concatenate so we need a bigger param space - QUESO::VectorSpace big_param_space(*env, - "", 6, NULL); - QUESO::GslVector v4(big_param_space.zeroVector()); + QUESO::VectorSpace *big_param_space = + new QUESO::VectorSpace(*env, "", 6, NULL); + QUESO::GslVector v4(big_param_space->zeroVector()); v4.cwSetConcatenated(v1, v3); for (i = 0; i < v1.sizeLocal(); i++) { @@ -95,7 +99,7 @@ int main(int argc, char **argv) { std::vector vecs; vecs.push_back(&v1); vecs.push_back(&v3); - QUESO::GslVector v5(big_param_space.zeroVector()); + QUESO::GslVector v5(big_param_space->zeroVector()); v5.cwSetConcatenated(vecs); for (i = 0; i < v5.sizeLocal(); i++) { if (std::abs(v5[i] - v4[i]) > TOL) { @@ -222,8 +226,12 @@ int main(int argc, char **argv) { std::cerr << "division test failed" << std::endl; return 1; } + delete big_param_space; + delete param_space; delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_GslVectorSpace/test_GslVectorSpaceMisc.C b/test/test_GslVectorSpace/test_GslVectorSpaceMisc.C index 57310984f..f1977b4f2 100644 --- a/test/test_GslVectorSpace/test_GslVectorSpaceMisc.C +++ b/test/test_GslVectorSpace/test_GslVectorSpaceMisc.C @@ -9,7 +9,9 @@ #include int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; @@ -20,8 +22,13 @@ int main(int argc, char **argv) { options.m_checkingLevel = 1; options.m_displayVerbosity = 20; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = new QUESO::FullEnvironment("", + "", &options); +#endif std::vector names(1); names[0] = "my_name"; @@ -76,7 +83,9 @@ int main(int argc, char **argv) { std::cout << std::endl; delete diag_matrix; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_InterpolationSurrogate/test_1D_LinearLagrangeInterpolationSurrogate.C b/test/test_InterpolationSurrogate/test_1D_LinearLagrangeInterpolationSurrogate.C index c113ac0aa..1e08efdbb 100644 --- a/test/test_InterpolationSurrogate/test_1D_LinearLagrangeInterpolationSurrogate.C +++ b/test/test_InterpolationSurrogate/test_1D_LinearLagrangeInterpolationSurrogate.C @@ -33,8 +33,12 @@ double one_d_fn( double x ); int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_InterpolationSurrogate/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_InterpolationSurrogate/queso_input.txt", "", NULL); +#endif int return_flag = 0; @@ -95,6 +99,9 @@ int main(int argc, char ** argv) return_flag = 1; } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif return return_flag; } diff --git a/test/test_InterpolationSurrogate/test_2D_LinearLagrangeInterpolationSurrogate.C b/test/test_InterpolationSurrogate/test_2D_LinearLagrangeInterpolationSurrogate.C index 0c6afd0a0..330cd96bd 100644 --- a/test/test_InterpolationSurrogate/test_2D_LinearLagrangeInterpolationSurrogate.C +++ b/test/test_InterpolationSurrogate/test_2D_LinearLagrangeInterpolationSurrogate.C @@ -33,8 +33,12 @@ double two_d_fn( double x, double y ); int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_InterpolationSurrogate/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_InterpolationSurrogate/queso_input.txt", "", NULL); +#endif int return_flag = 0; @@ -106,6 +110,9 @@ int main(int argc, char ** argv) return_flag = 1; } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif return return_flag; } diff --git a/test/test_InterpolationSurrogate/test_3D_LinearLagrangeInterpolationSurrogate.C b/test/test_InterpolationSurrogate/test_3D_LinearLagrangeInterpolationSurrogate.C index cb6e97d38..f3e373958 100644 --- a/test/test_InterpolationSurrogate/test_3D_LinearLagrangeInterpolationSurrogate.C +++ b/test/test_InterpolationSurrogate/test_3D_LinearLagrangeInterpolationSurrogate.C @@ -33,8 +33,12 @@ double three_d_fn( double x, double y, double z ); int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_InterpolationSurrogate/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_InterpolationSurrogate/queso_input.txt", "", NULL); +#endif int return_flag = 0; @@ -115,6 +119,9 @@ int main(int argc, char ** argv) return_flag = 1; } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif return return_flag; } diff --git a/test/test_InterpolationSurrogate/test_4D_LinearLagrangeInterpolationSurrogate.C b/test/test_InterpolationSurrogate/test_4D_LinearLagrangeInterpolationSurrogate.C index 1d6ee0301..5dce5e6a6 100644 --- a/test/test_InterpolationSurrogate/test_4D_LinearLagrangeInterpolationSurrogate.C +++ b/test/test_InterpolationSurrogate/test_4D_LinearLagrangeInterpolationSurrogate.C @@ -33,8 +33,12 @@ double four_d_fn( double x, double y, double z, double a ); int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_InterpolationSurrogate/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_InterpolationSurrogate/queso_input.txt", "", NULL); +#endif int return_flag = 0; @@ -121,6 +125,9 @@ int main(int argc, char ** argv) return_flag = 1; } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif return return_flag; } diff --git a/test/test_InterpolationSurrogate/test_build_InterpolationSurrogateBuilder.C b/test/test_InterpolationSurrogate/test_build_InterpolationSurrogateBuilder.C index 4551167e7..536a26760 100644 --- a/test/test_InterpolationSurrogate/test_build_InterpolationSurrogateBuilder.C +++ b/test/test_InterpolationSurrogate/test_build_InterpolationSurrogateBuilder.C @@ -56,8 +56,12 @@ public: int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_InterpolationSurrogate/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_InterpolationSurrogate/queso_input.txt", "", NULL); +#endif int return_flag = 0; @@ -161,6 +165,9 @@ int main(int argc, char ** argv) test_val( test_val_2, exact_val_2, tol, "test_read_2" ); } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif return return_flag; } diff --git a/test/test_IntersectionSubset/test_IntersectionSubsetContains.C b/test/test_IntersectionSubset/test_IntersectionSubsetContains.C index d93d8d0b0..5f6119ff6 100644 --- a/test/test_IntersectionSubset/test_IntersectionSubsetContains.C +++ b/test/test_IntersectionSubset/test_IntersectionSubsetContains.C @@ -11,7 +11,9 @@ #include int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; @@ -22,8 +24,13 @@ int main(int argc, char **argv) { options.m_checkingLevel = 1; options.m_displayVerbosity = 55; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment *env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment *env = new QUESO::FullEnvironment("", + "", &options); +#endif std::vector names(1); names[0] = "my_name"; @@ -75,7 +82,9 @@ int main(int argc, char **argv) { // Print out some info intersection.print(std::cout); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_Regression/test_GaussianMean1DRegression.C b/test/test_Regression/test_GaussianMean1DRegression.C index d68e51ec5..3a0104800 100644 --- a/test/test_Regression/test_GaussianMean1DRegression.C +++ b/test/test_Regression/test_GaussianMean1DRegression.C @@ -57,7 +57,7 @@ struct likelihoodData { double samplingVar; // input std::vector dataSet; // input }; -unsigned long likelihoodCalls = 0; // output +unsigned int likelihoodCalls = 0; // output // evaluate log likelihood template @@ -159,17 +159,14 @@ void GaussianMean1DRegressionCompute(const QUESO::BaseEnvironment& env, std::vector unifiedNs(env.inter0Comm().NumProc()); std::vector unifiedMeans(env.inter0Comm().NumProc()); std::vector unifiedM2s(env.inter0Comm().NumProc()); - MPI_Gather(&N, 1, MPI_INT, &(unifiedNs[0]), 1, MPI_INT, 0, - env.inter0Comm().Comm()); - MPI_Gather(&subMean, 1, MPI_DOUBLE, &(unifiedMeans[0]), 1, MPI_DOUBLE, 0, - env.inter0Comm().Comm()); - MPI_Gather(&subM2, 1, MPI_DOUBLE, &(unifiedM2s[0]), 1, MPI_DOUBLE, 0, - env.inter0Comm().Comm()); + env.inter0Comm().Gather(&N, 1, &(unifiedNs[0]), 1, 0, "", ""); + env.inter0Comm().Gather(&subMean, 1, &(unifiedMeans[0]), 1, 0, "", ""); + env.inter0Comm().Gather(&subM2, 1, &(unifiedM2s[0]), 1, 0, "", ""); // get the total number of likelihood calls at proc 0 - unsigned long totalLikelihoodCalls = 0; - MPI_Reduce(&likelihoodCalls, &totalLikelihoodCalls, 1, MPI_UNSIGNED_LONG, - MPI_SUM, 0, env.inter0Comm().Comm()); + unsigned int totalLikelihoodCalls = 0; + env.inter0Comm().Allreduce(&likelihoodCalls, &totalLikelihoodCalls, 1, + RawValue_MPI_SUM, "", ""); // compute global posterior mean and std via Chan algorithm, output results on proc 0 if (env.inter0Rank() == 0) { @@ -210,9 +207,13 @@ int main(int argc, char* argv[]) { //************************************************ // Initialize environments //************************************************ +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); +#else + int rank = 0; +#endif // variables to be filled by command line and/or input file values std::string inputFile; @@ -251,7 +252,11 @@ int main(int argc, char* argv[]) { } catch (std::exception& e) { if(rank == 0) std::cout<<"Caught exception: "<" << std::endl; std::cout << visible << std::endl; } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 1; } @@ -273,7 +280,11 @@ int main(int argc, char* argv[]) { } catch (std::exception& e) { if(rank == 0) std::cout << "Caught exception: " << e.what() << std::endl; +#ifdef QUESO_HAS_MPI MPI_Abort(MPI_COMM_WORLD, -1); +#else + exit(1); +#endif } boost::program_options::notify(vm); config_stream.close(); @@ -298,10 +309,17 @@ int main(int argc, char* argv[]) { } // initilize environment +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment env(MPI_COMM_WORLD, // MPI communicator inputFile.c_str(), // input file name "", // name prefix NULL ); // alt options +#else + QUESO::FullEnvironment env( // No MPI communicator + inputFile.c_str(), // input file name + "", // name prefix + NULL ); // alt options +#endif // reset seed to value in input file + fullRank env.resetSeed(env.seed() + env.fullRank()); @@ -310,7 +328,9 @@ int main(int argc, char* argv[]) { GaussianMean1DRegressionCompute(env, priorMean, priorVar, dat); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_Regression/test_gpmsa_cobra.C b/test/test_Regression/test_gpmsa_cobra.C index e96d82f9b..11f608d16 100644 --- a/test/test_Regression/test_gpmsa_cobra.C +++ b/test/test_Regression/test_gpmsa_cobra.C @@ -88,11 +88,16 @@ int main(int argc, char ** argv) { unsigned int numEta = 1; // Number of responses the model is returning unsigned int experimentSize = 1; // Size of each experiment +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); // Step 1: Set up QUESO environment QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_Regression/gpmsa_cobra_input.txt", "", NULL); +#else + QUESO::FullEnvironment env( + "test_Regression/gpmsa_cobra_input.txt", "", NULL); +#endif // Step 2: Set up prior for calibration parameters QUESO::VectorSpace paramSpace(env, @@ -274,7 +279,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_Regression/test_jeffreys.C b/test/test_Regression/test_jeffreys.C index 99413ed5b..07c1142da 100644 --- a/test/test_Regression/test_jeffreys.C +++ b/test/test_Regression/test_jeffreys.C @@ -107,17 +107,24 @@ void compute(const QUESO::FullEnvironment& env) { int main(int argc, char ** argv) { //init env +#ifdef QUESO_HAS_MPI MPI_Init(&argc,&argv); // Step 1: Set up QUESO environment QUESO::FullEnvironment* env = new QUESO::FullEnvironment(MPI_COMM_WORLD,"test_Regression/jeffreys_input.txt","",NULL); +#else + QUESO::FullEnvironment* env = + new QUESO::FullEnvironment("test_Regression/jeffreys_input.txt","",NULL); +#endif //compute compute(*env); //finalize enviroment delete env; +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_Regression/test_logitadaptedcov.C b/test/test_Regression/test_logitadaptedcov.C index a921d2475..6128b4d81 100644 --- a/test/test_Regression/test_logitadaptedcov.C +++ b/test/test_Regression/test_logitadaptedcov.C @@ -45,10 +45,14 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_Regression/adaptedcov_input.txt", "", NULL); +#else + QUESO::FullEnvironment env( + "test_Regression/adaptedcov_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 2, NULL); @@ -127,7 +131,9 @@ int main(int argc, char ** argv) { result = 0; } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return result; } diff --git a/test/test_SequenceOfVectors/test_SequenceOfVectorsErase.C b/test/test_SequenceOfVectors/test_SequenceOfVectorsErase.C index 55ae554fb..449c1880f 100644 --- a/test/test_SequenceOfVectors/test_SequenceOfVectorsErase.C +++ b/test/test_SequenceOfVectors/test_SequenceOfVectorsErase.C @@ -10,7 +10,9 @@ #include int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues options; options.m_numSubEnvironments = 1; @@ -21,7 +23,11 @@ int main(int argc, char **argv) { options.m_checkingLevel = 1; options.m_displayVerbosity = 55; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", &options); +#else + QUESO::FullEnvironment env("", "", &options); +#endif // Create a vector space std::vector names(1); @@ -53,6 +59,8 @@ int main(int argc, char **argv) { return 0; } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 1; } diff --git a/test/test_SequenceOfVectors/test_unifiedPositionsOfMaximum.C b/test/test_SequenceOfVectors/test_unifiedPositionsOfMaximum.C index f4a2c2c9e..3c6463c12 100644 --- a/test/test_SequenceOfVectors/test_unifiedPositionsOfMaximum.C +++ b/test/test_SequenceOfVectors/test_unifiedPositionsOfMaximum.C @@ -9,6 +9,9 @@ #include int main(int argc, char **argv) { +#ifndef QUESO_HAS_MPI + return 77; +#else MPI_Init(&argc, &argv); QUESO::EnvOptionsValues options; @@ -69,4 +72,5 @@ int main(int argc, char **argv) { MPI_Finalize(); return 0; +#endif } diff --git a/test/test_StatisticalInverseProblem/test_LlhdTargetOutput.C b/test/test_StatisticalInverseProblem/test_LlhdTargetOutput.C index 2c4dc5d88..39a07dfd1 100644 --- a/test/test_StatisticalInverseProblem/test_LlhdTargetOutput.C +++ b/test/test_StatisticalInverseProblem/test_LlhdTargetOutput.C @@ -37,9 +37,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, argv[1], "", NULL); +#else + QUESO::FullEnvironment env(argv[1], "", NULL); +#endif QUESO::VectorSpace<> paramSpace(env, "param_", 1, NULL); @@ -69,7 +72,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(NULL, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_StatisticalInverseProblem/test_NoInputFile.C b/test/test_StatisticalInverseProblem/test_NoInputFile.C index 5d1b362e7..f67eed32d 100644 --- a/test/test_StatisticalInverseProblem/test_NoInputFile.C +++ b/test/test_StatisticalInverseProblem/test_NoInputFile.C @@ -41,7 +41,9 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif QUESO::EnvOptionsValues envOptions; envOptions.m_numSubEnvironments = 1; @@ -51,7 +53,11 @@ int main(int argc, char ** argv) { envOptions.m_syncVerbosity = 0; envOptions.m_seed = 0; +#ifdef QUESO_HAS_MPI QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", &envOptions); +#else + QUESO::FullEnvironment env("", "", &envOptions); +#endif unsigned int dim = 2; QUESO::VectorSpace<> paramSpace(env, "param_", dim, NULL); @@ -118,7 +124,9 @@ int main(int argc, char ** argv) { ip.solveWithBayesMetropolisHastings(&mhOptions, paramInitials, &proposalCovMatrix); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_exception/test_exception.C b/test/test_exception/test_exception.C index 186d097fd..abd932b94 100644 --- a/test/test_exception/test_exception.C +++ b/test/test_exception/test_exception.C @@ -18,7 +18,9 @@ using namespace std; int main(int argc, char **argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif // hit with exception try @@ -28,7 +30,9 @@ int main(int argc, char **argv) catch(...) { printf("Caught QUESO exception!\n"); +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_blockDiagonalCovariance.C b/test/test_gaussian_likelihoods/test_blockDiagonalCovariance.C index 0838d9b12..3ab4fb475 100644 --- a/test/test_gaussian_likelihoods/test_blockDiagonalCovariance.C +++ b/test/test_gaussian_likelihoods/test_blockDiagonalCovariance.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_gaussian_likelihoods/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_gaussian_likelihoods/queso_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -136,7 +139,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceChain.C b/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceChain.C index d8937e149..58257a3db 100644 --- a/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceChain.C +++ b/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceChain.C @@ -110,8 +110,13 @@ class BayesianInverseProblem public: BayesianInverseProblem(unsigned int likelihoodFlag) { +#ifdef QUESO_HAS_MPI this->env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#else + this->env = new QUESO::FullEnvironment( + "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#endif this->paramSpace = new QUESO::VectorSpace(*env, @@ -227,7 +232,9 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif // Instantiate each inverse problem BayesianInverseProblem b1(1); @@ -246,7 +253,9 @@ int main(int argc, char ** argv) { } } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceRandomCoefficients.C b/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceRandomCoefficients.C index 44b434058..deadbed34 100644 --- a/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceRandomCoefficients.C +++ b/test/test_gaussian_likelihoods/test_blockDiagonalCovarianceRandomCoefficients.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_gaussian_likelihoods/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_gaussian_likelihoods/queso_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 3, NULL); @@ -139,7 +142,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_diagonalCovariance.C b/test/test_gaussian_likelihoods/test_diagonalCovariance.C index 68d347af1..57039d862 100644 --- a/test/test_gaussian_likelihoods/test_diagonalCovariance.C +++ b/test/test_gaussian_likelihoods/test_diagonalCovariance.C @@ -60,9 +60,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_gaussian_likelihoods/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_gaussian_likelihoods/queso_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -121,7 +124,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_diagonalCovarianceChain.C b/test/test_gaussian_likelihoods/test_diagonalCovarianceChain.C index 93d3fd27b..8904f22f8 100644 --- a/test/test_gaussian_likelihoods/test_diagonalCovarianceChain.C +++ b/test/test_gaussian_likelihoods/test_diagonalCovarianceChain.C @@ -106,8 +106,13 @@ class BayesianInverseProblem public: BayesianInverseProblem(unsigned int likelihoodFlag) { +#ifdef QUESO_HAS_MPI this->env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#else + this->env = new QUESO::FullEnvironment( + "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#endif this->paramSpace = new QUESO::VectorSpace(*env, @@ -209,7 +214,9 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif // Instantiate each inverse problem BayesianInverseProblem b1(1); @@ -228,7 +235,9 @@ int main(int argc, char ** argv) { } } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_fullCovariance.C b/test/test_gaussian_likelihoods/test_fullCovariance.C index 09c054d03..04b7c60a1 100644 --- a/test/test_gaussian_likelihoods/test_fullCovariance.C +++ b/test/test_gaussian_likelihoods/test_fullCovariance.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_gaussian_likelihoods/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_gaussian_likelihoods/queso_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -122,7 +125,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_fullCovarianceChain.C b/test/test_gaussian_likelihoods/test_fullCovarianceChain.C index 2d6912911..a6b7c12d4 100644 --- a/test/test_gaussian_likelihoods/test_fullCovarianceChain.C +++ b/test/test_gaussian_likelihoods/test_fullCovarianceChain.C @@ -106,8 +106,13 @@ class BayesianInverseProblem public: BayesianInverseProblem(unsigned int likelihoodFlag) { +#ifdef QUESO_HAS_MPI this->env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#else + this->env = new QUESO::FullEnvironment( + "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#endif this->paramSpace = new QUESO::VectorSpace(*env, @@ -211,7 +216,9 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif // Instantiate each inverse problem BayesianInverseProblem b1(1); @@ -230,7 +237,9 @@ int main(int argc, char ** argv) { } } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_fullCovarianceRandomCoefficient.C b/test/test_gaussian_likelihoods/test_fullCovarianceRandomCoefficient.C index 14608c262..e0782dcc3 100644 --- a/test/test_gaussian_likelihoods/test_fullCovarianceRandomCoefficient.C +++ b/test/test_gaussian_likelihoods/test_fullCovarianceRandomCoefficient.C @@ -59,9 +59,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_gaussian_likelihoods/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_gaussian_likelihoods/queso_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 2, NULL); @@ -128,7 +131,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_scalarCovariance.C b/test/test_gaussian_likelihoods/test_scalarCovariance.C index c4f0d6f78..8a211dc86 100644 --- a/test/test_gaussian_likelihoods/test_scalarCovariance.C +++ b/test/test_gaussian_likelihoods/test_scalarCovariance.C @@ -58,9 +58,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_gaussian_likelihoods/queso_input.txt", "", NULL); +#else + QUESO::FullEnvironment env("test_gaussian_likelihoods/queso_input.txt", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "param_", 1, NULL); @@ -113,7 +116,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_gaussian_likelihoods/test_scalarCovarianceChain.C b/test/test_gaussian_likelihoods/test_scalarCovarianceChain.C index 8c7a24b2b..cfbbce199 100644 --- a/test/test_gaussian_likelihoods/test_scalarCovarianceChain.C +++ b/test/test_gaussian_likelihoods/test_scalarCovarianceChain.C @@ -102,8 +102,13 @@ class BayesianInverseProblem public: BayesianInverseProblem(unsigned int likelihoodFlag) { +#ifdef QUESO_HAS_MPI this->env = new QUESO::FullEnvironment(MPI_COMM_WORLD, "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#else + this->env = new QUESO::FullEnvironment( + "test_gaussian_likelihoods/gaussian_consistency_input.txt", "", NULL); +#endif this->paramSpace = new QUESO::VectorSpace(*env, @@ -198,7 +203,9 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); +#endif // Instantiate each inverse problem BayesianInverseProblem b1(1); @@ -217,7 +224,9 @@ int main(int argc, char ** argv) { } } +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; } diff --git a/test/test_infinite/test_inf_gaussian.C b/test/test_infinite/test_inf_gaussian.C index 3fc87b346..941089669 100644 --- a/test/test_infinite/test_inf_gaussian.C +++ b/test/test_infinite/test_inf_gaussian.C @@ -6,14 +6,13 @@ #include #include #include +#include #include #include #include #include #endif // QUESO_HAVE_LIBMESH -#include - int main(int argc, char **argv) { #ifdef QUESO_HAVE_LIBMESH @@ -26,9 +25,12 @@ int main(int argc, char **argv) QUESO::EnvOptionsValues opts; opts.m_seed = -1; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", &opts); +#else + QUESO::FullEnvironment env("", "", &opts); +#endif #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION // SLEPc farts with libMesh::Real==float @@ -108,7 +110,9 @@ int main(int argc, char **argv) } #endif // LIBMESH_HAVE_SLEPC +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; #else return 77; diff --git a/test/test_infinite/test_inf_options.C b/test/test_infinite/test_inf_options.C index de46d2f98..4dc85e662 100644 --- a/test/test_infinite/test_inf_options.C +++ b/test/test_infinite/test_inf_options.C @@ -15,8 +15,6 @@ #include #endif // QUESO_HAVE_LIBMESH -#include - #ifdef QUESO_HAVE_LIBMESH class Likelihood : public QUESO::InfiniteDimensionalLikelihoodBase { public: @@ -49,9 +47,12 @@ int main(int argc, char **argv) // EnvOptionsValuesClass opts; // opts.m_seed = -1; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, in_file_name, prefix, NULL); +#else + QUESO::FullEnvironment env(in_file_name, prefix, NULL); +#endif #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION // SLEPc farts with libMesh::Real==float @@ -94,7 +95,9 @@ int main(int argc, char **argv) } #endif // LIBMESH_HAVE_SLEPC +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; #else return 77; diff --git a/test/test_infinite/test_operator.C b/test/test_infinite/test_operator.C index 53d0bbce9..a1e4f5a92 100644 --- a/test/test_infinite/test_operator.C +++ b/test/test_infinite/test_operator.C @@ -15,14 +15,13 @@ #include #include #include +#include #include #include #include #include #endif // QUESO_HAVE_LIBMESH -#include - #define TEST_TOL 1e-8 #define INTEGRATE_TOL 1e-2 @@ -33,8 +32,12 @@ int main(int argc, char **argv) QUESO::EnvOptionsValues opts; opts.m_seed = -1; +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", &opts); +#else + QUESO::FullEnvironment env("", "", &opts); +#endif #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION // SLEPc currently gives us a nasty crash with Real==float @@ -118,7 +121,9 @@ int main(int argc, char **argv) } } #endif // LIBMESH_HAVE_SLEPC +#ifdef QUESO_HAS_MPI MPI_Finalize(); +#endif return 0; #else return 77; diff --git a/test/test_optimizer/input_test_optimizer_options.in b/test/test_optimizer/input_test_optimizer_options.in new file mode 100644 index 000000000..361e7620a --- /dev/null +++ b/test/test_optimizer/input_test_optimizer_options.in @@ -0,0 +1,53 @@ +############################################### +# UQ Environment +############################################### +#env_help = anything +env_numSubEnvironments = 1 +env_subDisplayFileName = output_test_optimizer_options/display +env_subDisplayAllowAll = 0 +env_subDisplayAllowedSet = 0 +env_displayVerbosity = 2 +env_syncVerbosity = 0 +env_seed = 0 + +############################################### +# Statistical inverse problem (ip) +############################################### +#ip_help = anything +ip_computeSolution = 1 +ip_dataOutputFileName = output_test_optimizer_options/sipOutput +ip_dataOutputAllowedSet = 0 +ip_seedWithMAPEstimator = 1 +ip_useOptimizerMonitor = 1 + +############################################### +# 'ip_': information for Metropolis-Hastings algorithm +############################################### +#ip_mh_help = anything +ip_mh_dataOutputFileName = output_test_optimizer_options/sipOutput +ip_mh_dataOutputAllowedSet = 0 1 + +ip_mh_rawChain_dataInputFileName = . +ip_mh_rawChain_size = 10 +ip_mh_rawChain_generateExtra = 0 +ip_mh_rawChain_displayPeriod = 50000 +ip_mh_rawChain_measureRunTimes = 1 +ip_mh_rawChain_dataOutputFileName = output_test_optimizer_options/ip_raw_chain +ip_mh_rawChain_dataOutputAllowedSet = 0 1 +ip_mh_rawChain_computeStats = 1 + +ip_mh_displayCandidates = 0 +ip_mh_putOutOfBoundsInChain = 0 +ip_mh_tk_useLocalHessian = 0 +ip_mh_tk_useNewtonComponent = 1 +ip_mh_dr_maxNumExtraStages = 1 +ip_mh_dr_listOfScalesForExtraStages = 5. +ip_mh_am_initialNonAdaptInterval = 0 +ip_mh_am_adaptInterval = 100 +ip_mh_am_eta = 1.92 +ip_mh_am_epsilon = 1.e-5 + +ip_mh_filteredChain_generate = 0 + +ip_mh_outputLogLikelihood = 0 +ip_mh_outputLogTarget = 0 diff --git a/test/test_optimizer/test_gsloptimizer.C b/test/test_optimizer/test_gsloptimizer.C index 28fbe31cd..9bb7a5505 100644 --- a/test/test_optimizer/test_gsloptimizer.C +++ b/test/test_optimizer/test_gsloptimizer.C @@ -44,9 +44,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", NULL); +#else + QUESO::FullEnvironment env("", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "space_", 3, NULL); @@ -101,5 +104,9 @@ int main(int argc, char ** argv) { monitor.print(std::cout,false); +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif + return 0; } diff --git a/test/test_optimizer/test_optimizer_options.C b/test/test_optimizer/test_optimizer_options.C new file mode 100644 index 000000000..e08ce89e3 --- /dev/null +++ b/test/test_optimizer/test_optimizer_options.C @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +class Likelihood : public QUESO::BaseScalarFunction { +public: + Likelihood(const char * prefix, + const QUESO::VectorSet & domainSet) + : QUESO::BaseScalarFunction(prefix, domainSet) { + // Do nothing + } + + virtual double actualValue(const V & domainVector, const V * domainDirection, + V * gradVector, M * hessianMatrix, V * hessianEffect) const { + return std::exp(this->actualValue(domainVector, domainDirection, + gradVector, hessianMatrix, hessianEffect)); + } + + virtual double lnValue(const V & domainVector, const V * domainDirection, + V * gradVector, M * hessianMatrix, V * hessianEffect) const { + + // Need to check if NULL because QUESO will somtimes call this with a + // NULL pointer + if (gradVector != NULL) { + (*gradVector)[0] = -2.0 * domainVector[0]; + } + + return -(domainVector[0] * domainVector[0]); + } +}; + +int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI + MPI_Init(&argc, &argv); + QUESO::FullEnvironment env(MPI_COMM_WORLD, "test_optimizer/input_test_optimizer_options", "", NULL); +#else + QUESO::FullEnvironment env("test_optimizer/input_test_optimizer_options", "", NULL); +#endif + + QUESO::VectorSpace paramSpace(env, + "space_", 1, NULL); + + QUESO::GslVector minBound(paramSpace.zeroVector()); + minBound[0] = -10.0; + + QUESO::GslVector maxBound(paramSpace.zeroVector()); + maxBound[0] = 10.0; + + QUESO::BoxSubset domain("", paramSpace, + minBound, maxBound); + + QUESO::UniformVectorRV prior("", domain); + + Likelihood likelihood("", domain); + + QUESO::GenericVectorRV posterior("", + domain); + + QUESO::StatisticalInverseProblem ip("", + NULL, prior, likelihood, posterior); + + QUESO::GslVector initialValues(paramSpace.zeroVector()); + initialValues[0] = 9.0; + + QUESO::GslMatrix proposalCovarianceMatrix(paramSpace.zeroVector()); + proposalCovarianceMatrix(0, 0) = 1.0; + + ip.solveWithBayesMetropolisHastings(NULL, initialValues, + &proposalCovarianceMatrix); + + // The first sample should be the seed + QUESO::GslVector first_sample(paramSpace.zeroVector()); + posterior.realizer().realization(first_sample); + + // Tight tolerance for analytical derivative + if (std::abs(first_sample[0]) > 1e-10) { + std::cerr << "seedWithMAPEstimator failed. Seed was: " << first_sample[0] + << std::endl; + std::cerr << "Actual seed should be 0.0" << std::endl; + queso_error(); + } + + return 0; +} diff --git a/test/test_optimizer/test_seedwithmap.C b/test/test_optimizer/test_seedwithmap.C index 9402d8380..a8296b3c6 100644 --- a/test/test_optimizer/test_seedwithmap.C +++ b/test/test_optimizer/test_seedwithmap.C @@ -40,9 +40,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", NULL); +#else + QUESO::FullEnvironment env("", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "space_", 1, NULL); @@ -88,5 +91,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif + return 0; } diff --git a/test/test_optimizer/test_seedwithmap_fd.C b/test/test_optimizer/test_seedwithmap_fd.C index 42a1359e5..465aeb9f7 100644 --- a/test/test_optimizer/test_seedwithmap_fd.C +++ b/test/test_optimizer/test_seedwithmap_fd.C @@ -35,9 +35,12 @@ public: }; int main(int argc, char ** argv) { +#ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); - QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", NULL); +#else + QUESO::FullEnvironment env("", "", NULL); +#endif QUESO::VectorSpace paramSpace(env, "space_", 1, NULL); @@ -84,5 +87,9 @@ int main(int argc, char ** argv) { queso_error(); } +#ifdef QUESO_HAS_MPI + MPI_Finalize(); +#endif + return 0; }