[cig-commits] [commit] master: add PETSc configuration and test support (254172c)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue May 27 08:46:47 PDT 2014


Repository : https://github.com/geodynamics/aspect

On branch  : master
Link       : https://github.com/geodynamics/aspect/compare/ffe5ed2da6ea379c28517ce2e66ae2e0a917eb93...4a5a833f884ceec518244a723f11a86c3b456e70

>---------------------------------------------------------------

commit 254172cc0d07a73844d8f09bfbb88cb486cfb2d9
Author: Timo Heister <timo.heister at gmail.com>
Date:   Mon May 26 12:31:40 2014 -0400

    add PETSc configuration and test support
    
    This is a combination of 9 commits:
    be silent about finding tests
    add configuration parameter to find PETSc
    We need to check if deal.II has PETSc support and add the compile flag
    if we want PETSc.
    write into detailed.log if we have PETSc
    include PETSc string in build info on tester
    add support for PETSc tests
    rename USE_PETSC to ASPECT_USE_PETSC
    update changelog.h


>---------------------------------------------------------------

254172cc0d07a73844d8f09bfbb88cb486cfb2d9
 CMakeLists.txt                  | 37 +++++++++++++++++++++++++++++--------
 doc/modules/changes.h           |  4 ++++
 include/aspect/global.h         |  7 ++-----
 source/main.cc                  |  2 +-
 source/simulator/assembly.cc    |  2 +-
 source/simulator/core.cc        |  8 ++++----
 source/simulator/freesurface.cc | 10 +++++-----
 source/simulator/nullspace.cc   |  2 +-
 source/simulator/solver.cc      |  8 ++++----
 tests/CMakeLists.txt            | 37 ++++++++++++++++++++++++++++++++++---
 tests/composition_names.prm     |  2 ++
 tests/run_testsuite.cmake       | 26 +++++++++++---------------
 write_config.cmake              |  1 +
 13 files changed, 99 insertions(+), 47 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 544c0be..438aeaa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,28 +45,49 @@ ENDIF()
 
 MESSAGE(STATUS "found deal.II version ${DEAL_II_PACKAGE_VERSION} at '${deal.II_DIR}'")
 
-IF(NOT DEAL_II_WITH_TRILINOS OR NOT DEAL_II_WITH_P4EST)
-  IF(NOT DEAL_II_WITH_TRILINOS)
+SET(ASPECT_USE_PETSC OFF CACHE BOOL "Use PETSc instead of Trilinos if set to 'on'.")
+
+MESSAGE(STATUS "using PETSc = '${ASPECT_USE_PETSC}'")
+
+SET(_DEALII_GOOD ON)
+
+IF(ASPECT_USE_PETSC AND NOT DEAL_II_WITH_PETSC)
     MESSAGE(SEND_ERROR
-      "\n-- deal.II was built without support for Trilinos!\n"
+      "\n-- deal.II was built without support for PETSc!\n"
       )
-  ENDIF()
+    SET(_DEALII_GOOD OFF)
+ENDIF()
 
-  IF(NOT DEAL_II_WITH_P4EST)
+IF(NOT DEAL_II_WITH_P4EST)
     MESSAGE(SEND_ERROR
       "\n-- deal.II was built without support for p4est!\n"
       )
-  ENDIF()
+    SET(_DEALII_GOOD OFF)
+ENDIF()
 
+IF(NOT ASPECT_USE_PETSC AND NOT DEAL_II_WITH_TRILINOS)
+    MESSAGE(SEND_ERROR
+      "\n-- deal.II was built without support for Trilinos!\n"
+      )
+    SET(_DEALII_GOOD OFF)
+ENDIF()
+
+IF (NOT _DEALII_GOOD)
   MESSAGE(FATAL_ERROR
-    "\nAspect requires a deal.II installation built with support for Trilinos and p4est but one or both of these appears to be missing!\n"
+    "\nAspect requires a deal.II installation built with support for Trilinos/PETSc and p4est but one or both of these appears to be missing!\n"
     )
-
 ENDIF()
 
 DEAL_II_INITIALIZE_CACHED_VARIABLES()
 PROJECT(${TARGET})
 
+IF (ASPECT_USE_PETSC)
+FOREACH(_source_file ${TARGET_SRC})
+  SET_PROPERTY(SOURCE ${_source_file}
+    APPEND PROPERTY COMPILE_DEFINITIONS ASPECT_USE_PETSC="1")
+ENDFOREACH()
+ENDIF()
+
 
 # Pass down the source directory to the sources. This can be used
 # to hard-code the location of data files, such as in
diff --git a/doc/modules/changes.h b/doc/modules/changes.h
index 4db22f7..d2f6204 100644
--- a/doc/modules/changes.h
+++ b/doc/modules/changes.h
@@ -5,6 +5,10 @@
  * 1.0. All entries are signed with the names of the author. </p>
  *
  * <ol>
+ * <li> PETSc support can now be enabled using 'cmake -D ASPECT_USE_PETSC=ON'.
+ * <br>
+ * (Timo Heister, 2014/05/27)
+ *
  * <li> Fixed: The GPlates plugin now correctly handles meshes created by 
  * GPlates 1.4 and later. Previous Aspect versions may only read in files
  * created by GPlates 1.3.
diff --git a/include/aspect/global.h b/include/aspect/global.h
index ff1e00a..4af3c50 100644
--- a/include/aspect/global.h
+++ b/include/aspect/global.h
@@ -22,10 +22,7 @@
 #ifndef __aspect__global_h
 #define __aspect__global_h
 
-// uncomment this to use PETSc for linear algebra
-//#define USE_PETSC
-
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
 #include <deal.II/lac/petsc_block_vector.h>
 #include <deal.II/lac/petsc_block_sparse_matrix.h>
 #include <deal.II/lac/petsc_precondition.h>
@@ -79,7 +76,7 @@ namespace aspect
   {
     using namespace dealii;
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     /**
      * Typedef for the vector type used.
      */
diff --git a/source/main.cc b/source/main.cc
index 97f19aa..e87b143 100644
--- a/source/main.cc
+++ b/source/main.cc
@@ -241,7 +241,7 @@ int main (int argc, char *argv[])
           if (n_threads>1)
             std::cout << "--     . using " << n_threads << " threads " << (n_tasks == 1 ? "\n" : "each\n");
 #endif
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
           std::cout << "--     . using PETSc\n";
 #else
           std::cout << "--     . using Trilinos\n";
diff --git a/source/simulator/assembly.cc b/source/simulator/assembly.cc
index 8444fa2..0f32ebf 100644
--- a/source/simulator/assembly.cc
+++ b/source/simulator/assembly.cc
@@ -1021,7 +1021,7 @@ namespace aspect
     Amg_preconditioner.reset (new LinearAlgebra::PreconditionAMG());
 
     LinearAlgebra::PreconditionAMG::AdditionalData Amg_data;
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     Amg_data.symmetric_operator = false;
 #else
     Amg_data.constant_modes = constant_modes;
diff --git a/source/simulator/core.cc b/source/simulator/core.cc
index 47191e2..a35ef76 100644
--- a/source/simulator/core.cc
+++ b/source/simulator/core.cc
@@ -673,7 +673,7 @@ namespace aspect
           = DoFTools::always;
     }
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     LinearAlgebra::CompressedBlockSparsityPattern sp(introspection.index_sets.system_relevant_partitioning);
 
 #else
@@ -687,7 +687,7 @@ namespace aspect
                                      Utilities::MPI::
                                      this_mpi_process(mpi_communicator));
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     SparsityTools::distribute_sparsity_pattern(sp,
                                                dof_handler.locally_owned_dofs_per_processor(),
                                                mpi_communicator, introspection.index_sets.system_relevant_set);
@@ -725,7 +725,7 @@ namespace aspect
           coupling[c][d] = DoFTools::none;
 
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     LinearAlgebra::CompressedBlockSparsityPattern sp(introspection.index_sets.system_relevant_partitioning);
 
 #else
@@ -737,7 +737,7 @@ namespace aspect
                                      constraints, false,
                                      Utilities::MPI::
                                      this_mpi_process(mpi_communicator));
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     SparsityTools::distribute_sparsity_pattern(sp,
                                                dof_handler.locally_owned_dofs_per_processor(),
                                                mpi_communicator, introspection.index_sets.system_relevant_set);
diff --git a/source/simulator/freesurface.cc b/source/simulator/freesurface.cc
index d05ea74..a1cd5c9 100644
--- a/source/simulator/freesurface.cc
+++ b/source/simulator/freesurface.cc
@@ -221,7 +221,7 @@ namespace aspect
 
     //set up the matrix
     LinearAlgebra::SparseMatrix mass_matrix;
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     CompressedSimpleSparsityPattern sp(mesh_locally_relevant);
 
 #else
@@ -230,7 +230,7 @@ namespace aspect
 #endif
     DoFTools::make_sparsity_pattern (free_surface_dof_handler, sp, mass_matrix_constraints, false,
                                       Utilities::MPI::this_mpi_process(sim.mpi_communicator));
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     SparsityTools::distribute_sparsity_pattern(sp,
                                                free_surface_dof_handler.n_locally_owned_dofs_per_processor(),
                                                sim.mpi_communicator, mesh_locally_relevant);
@@ -365,7 +365,7 @@ namespace aspect
     // TODO: think about keeping object between time steps
     LinearAlgebra::PreconditionAMG preconditioner_stiffness;
     LinearAlgebra::PreconditionAMG::AdditionalData Amg_data;
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
     Amg_data.symmetric_operator = false;
 #else
     Amg_data.constant_modes = constant_modes;
@@ -522,7 +522,7 @@ namespace aspect
       for (unsigned int c=0; c<dim; ++c)
         coupling[c][c] = DoFTools::always;
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
       CompressedSimpleSparsityPattern sp(mesh_locally_relevant);
 
 #else
@@ -536,7 +536,7 @@ namespace aspect
                                        Utilities::MPI::
                                        this_mpi_process(sim.mpi_communicator));
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
       SparsityTools::distribute_sparsity_pattern(sp,
                                                  free_surface_dof_handler.n_locally_owned_dofs_per_processor(),
                                                  sim.mpi_communicator, mesh_locally_relevant);
diff --git a/source/simulator/nullspace.cc b/source/simulator/nullspace.cc
index dbd8151..31e83fa 100644
--- a/source/simulator/nullspace.cc
+++ b/source/simulator/nullspace.cc
@@ -25,7 +25,7 @@
 #include <deal.II/lac/solver_gmres.h>
 #include <deal.II/lac/constraint_matrix.h>
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
 #include <deal.II/lac/solver_cg.h>
 #else
 #include <deal.II/lac/trilinos_solver.h>
diff --git a/source/simulator/solver.cc b/source/simulator/solver.cc
index 820dc7b..b43bd22 100644
--- a/source/simulator/solver.cc
+++ b/source/simulator/solver.cc
@@ -25,7 +25,7 @@
 #include <deal.II/lac/solver_gmres.h>
 #include <deal.II/lac/constraint_matrix.h>
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
 #include <deal.II/lac/solver_cg.h>
 #else
 #include <deal.II/lac/trilinos_solver.h>
@@ -245,7 +245,7 @@ namespace aspect
       {
         SolverControl solver_control(5000, 1e-6 * src.block(1).l2_norm());
 
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
         SolverCG<LinearAlgebra::Vector> solver(solver_control);
 #else
         TrilinosWrappers::SolverCG solver(solver_control);
@@ -273,7 +273,7 @@ namespace aspect
       if (do_solve_A == true)
         {
           SolverControl solver_control(5000, utmp.l2_norm()*1e-2);
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
           SolverCG<LinearAlgebra::Vector> solver(solver_control);
 #else
           TrilinosWrappers::SolverCG solver(solver_control);
@@ -389,7 +389,7 @@ namespace aspect
 
         SolverControl cn;
         // TODO: can we re-use the direct solver?
-#ifdef USE_PETSC
+#ifdef ASPECT_USE_PETSC
         PETScWrappers::SparseDirectMUMPS solver(cn, mpi_communicator);
 #else
         TrilinosWrappers::SolverDirect solver(cn);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 201963e..5877796 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -29,6 +29,33 @@ FUNCTION(get_mpi_count _filename)
   endif()
 ENDFUNCTION()
 
+# extract from the prm if the test should be run with trilinos or
+# petsc. This is encoded in the .prm in form of line
+# '# LINEAR ALGEBRA: PETSC'
+# '# LINEAR ALGEBRA: PETSC TRILINOS'
+# If no line is there, Trilinos is assumed. 
+FUNCTION(check_linear_algebra _filename)
+  FILE(STRINGS ${_filename} _input_lines
+       REGEX "LINEAR ALGEBRA:")
+  IF("${_input_lines}" STREQUAL "")
+    IF(ASPECT_USE_PETSC)
+      SET(_use_test 0 PARENT_SCOPE)
+    ELSE()
+      SET(_use_test 1 PARENT_SCOPE)
+    ENDIF()
+  ELSE()
+    SET(_use_test 0 PARENT_SCOPE)
+    FOREACH(_input_line ${_input_lines})
+      IF (${_input_line} MATCHES "PETSC" AND ASPECT_USE_PETSC)
+        SET(_use_test 1 PARENT_SCOPE)
+      ENDIF()
+      IF (${_input_line} MATCHES "TRILINOS" AND NOT ASPECT_USE_PETSC)
+        SET(_use_test 1 PARENT_SCOPE)
+      ENDIF()
+    ENDFOREACH()
+  ENDIF()
+ENDFUNCTION()
+
 
 # set a time limit of 10 minutes per test. this should be long
 # enough even for long-running tests, and short enough to not
@@ -77,12 +104,15 @@ IF("${TEST_DIFF}" STREQUAL "")
   ENDIF()
 ENDIF()
 
-
 FILE(GLOB _tests *.prm)
+
 LIST(SORT _tests)
 FOREACH(_test ${_tests})
   GET_FILENAME_COMPONENT(_test ${_test} NAME_WE)
-  MESSAGE(STATUS "Adding test ${_test}")
+
+  CHECK_LINEAR_ALGEBRA(${CMAKE_CURRENT_SOURCE_DIR}/${_test}.prm)
+
+  IF("${_use_test}" STREQUAL "1")
 
   IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_test}.cc)
     ADD_LIBRARY(${_test} SHARED EXCLUDE_FROM_ALL ${_test}.cc)
@@ -148,7 +178,6 @@ FOREACH(_test ${_tests})
       DEPENDS aspect ${CMAKE_CURRENT_BINARY_DIR}/${_test}.x.prm ${_testdepends}
       )
   ELSE()
-    MESSAGE(STATUS "    MPI status: ${_mpi_count} processes")
     ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/output-${_test}/screen-output
       COMMAND
 	for i in ${CMAKE_CURRENT_BINARY_DIR}/output-${_test}/* \; do
@@ -259,5 +288,7 @@ FOREACH(_test ${_tests})
   SET_TESTS_PROPERTIES(${_test} PROPERTIES
 	TIMEOUT ${TEST_TIME_LIMIT}
     )
+
+  ENDIF()
 ENDFOREACH()
 
diff --git a/tests/composition_names.prm b/tests/composition_names.prm
index 4432d14..e75837d 100644
--- a/tests/composition_names.prm
+++ b/tests/composition_names.prm
@@ -1,3 +1,5 @@
+# LINEAR ALGEBRA: TRILINOS PETSC
+
 # Listing of Parameters
 # ---------------------
 # In order to make the problem in the first time step easier to solve, we need
diff --git a/tests/run_testsuite.cmake b/tests/run_testsuite.cmake
index 382315f..89ee211 100644
--- a/tests/run_testsuite.cmake
+++ b/tests/run_testsuite.cmake
@@ -273,20 +273,7 @@ GET_CMAKE_PROPERTY(_variables VARIABLES)
 
 # Append compiler information to CTEST_BUILD_NAME:
 IF(NOT EXISTS ${CTEST_BINARY_DIRECTORY}/detailed.log)
-  # Apparently, ${CTEST_BINARY_DIRECTORY} is not a configured build
-  # directory. In this case we need a trick: set up a dummy project and
-  # query it for the compiler information.
-  FILE(WRITE ${CTEST_BINARY_DIRECTORY}/query_for_compiler/CMakeLists.txt "
-FILE(WRITE ${CTEST_BINARY_DIRECTORY}/detailed.log
-  \"#        CMAKE_CXX_COMPILER:     \${CMAKE_CXX_COMPILER_ID} \${CMAKE_CXX_COMPILER_VERSION} on platform \${CMAKE_SYSTEM_NAME} \${CMAKE_SYSTEM_PROCESSOR}\"
-  )"
-    )
-  EXECUTE_PROCESS(
-    COMMAND ${CMAKE_COMMAND} ${_options} "-G${CTEST_CMAKE_GENERATOR}" .
-    OUTPUT_QUIET ERROR_QUIET
-    WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY}/query_for_compiler
-    )
-  FILE(REMOVE_RECURSE ${CTEST_BINARY_DIRECTORY}/query_for_compiler)
+  MESSAGE(FATAL_ERROR "could not find detailed.log")
 ENDIF()
 
 IF(EXISTS ${CTEST_BINARY_DIRECTORY}/detailed.log)
@@ -304,6 +291,13 @@ IF(EXISTS ${CTEST_BINARY_DIRECTORY}/detailed.log)
       _compiler_id MATCHES "CMAKE_CXX_COMPILER" )
     SET(CTEST_BUILD_NAME "${_compiler_id}")
   ENDIF()
+
+
+  FILE(STRINGS ${CTEST_BINARY_DIRECTORY}/detailed.log _use_petsc_line
+    REGEX "ASPECT_USE_PETSC:"
+    )
+  STRING(REGEX REPLACE "^.*#.*ASPECT_USE_PETSC: *(.*)$" "\\1" USE_PETSC ${_use_petsc_line})
+
 ENDIF()
 
 #
@@ -360,7 +354,9 @@ ELSE()
   SET(_branch "")
 ENDIF()
 
-
+IF(USE_PETSC)
+  SET(CTEST_BUILD_NAME "${CTEST_BUILD_NAME}-PETSc")
+ENDIF()
 
 SET(CTEST_BUILD_NAME "${CTEST_BUILD_NAME}-${_branch}")
 
diff --git a/write_config.cmake b/write_config.cmake
index 9b01499..78f2047 100644
--- a/write_config.cmake
+++ b/write_config.cmake
@@ -31,6 +31,7 @@ _detailed(
 #  ASPECT configuration:
 #        DEAL_II_DIR:            ${deal.II_DIR}
 #        DEAL_II VERSION:        ${DEAL_II_PACKAGE_VERSION}
+#        ASPECT_USE_PETSC:       ${ASPECT_USE_PETSC}
 #        CMAKE_BUILD_TYPE:       ${CMAKE_BUILD_TYPE}
 #        CMAKE_INSTALL_PREFIX:   ${CMAKE_INSTALL_PREFIX}
 #        CMAKE_SOURCE_DIR:       ${CMAKE_SOURCE_DIR} 



More information about the CIG-COMMITS mailing list