diff --git a/BaseLib/PETScWallClockTimer.h b/BaseLib/PETScWallClockTimer.h new file mode 100644 index 0000000000000000000000000000000000000000..bca4226acf2fe2ebe2b83dd8609de834dcd57b0b --- /dev/null +++ b/BaseLib/PETScWallClockTimer.h @@ -0,0 +1,57 @@ +/*! + \file PETScWallClockTimer.h + \author Wenqing Wang + \date 2014.08 + \brief Declare a class to record wall clock time in computation with PETSc. + + \copyright + Copyright (c) 2014, OpenGeoSys Community (http://www.opengeosys.org) + Distributed under a Modified BSD License. + See accompanying file LICENSE.txt or + http://www.opengeosys.org/project/license + +*/ + +#ifndef PETSC_WALL_CLOCK_TIMER_H +#define PETSC_WALL_CLOCK_TIMER_H + +#include <petsctime.h> + +namespace BaseLib +{ + +/// Record wall clock time for computations with PETSc. +class PETScWallClockTimer +{ + public: + /// Record the start time. + void start() + { +#if (PETSC_VERSION_NUMBER > 3020) + PetscTime(&_start_time); +#else + PetscGetTime(&_start_time); +#endif + } + + /// Return the elapsed time when this function is called. + PetscLogDouble elapsed() const + { + PetscLogDouble current_time; +#if (PETSC_VERSION_NUMBER > 3020) + PetscTime(¤t_time); +#else + PetscGetTime(¤t_time); +#endif + return current_time - _start_time; + } + + private: + /// Start time. + PetscLogDouble _start_time = 0.; +}; + +} // end namespace BaseLib + +#endif + diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c29e6ef67afe19404f82d8c6686328df71ad838..9e02a35902842fb80f55733881a1aa0e492913e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ OPTION(OGS_NO_EXTERNAL_LIBS "Builds OGS without any external dependencies." OFF) # Linear solvers OPTION(OGS_USE_LIS "Use Lis" OFF) + +# Parallel computing OPTION(OGS_USE_PETSC "Use PETSc routines" OFF) # Paralleization diff --git a/MathLib/LinAlg/PETSc/PETScLinearSolver.h b/MathLib/LinAlg/PETSc/PETScLinearSolver.h index 59e86838ba11485147fab23229648fc96771527b..b3d9660d101f006a23fa25c5cc5a4f0d074d03e3 100644 --- a/MathLib/LinAlg/PETSc/PETScLinearSolver.h +++ b/MathLib/LinAlg/PETSc/PETScLinearSolver.h @@ -23,6 +23,7 @@ #include "PETScMatrix.h" #include "PETScVector.h" +#include "BaseLib/PETScWallClockTimer.h" namespace MathLib { diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake index 9f7665a58e481a84fc16f56cd0698685e58f9be8..0046bf0d92b010f43b112a5d7dac9366f4505f15 100644 --- a/scripts/cmake/Find.cmake +++ b/scripts/cmake/Find.cmake @@ -134,6 +134,14 @@ IF(OGS_USE_PETSC) include_directories( ${PETSC_INCLUDES} ) + FIND_PACKAGE(MPI REQUIRED) + + IF(WIN32) + ADD_DEFINITIONS(/DPETSC_VERSION_NUMBER=PETSC_VERSION_MAJOR*1000+PETSC_VERSION_MINOR*10) + ELSE() + ADD_DEFINITIONS(-DPETSC_VERSION_NUMBER=PETSC_VERSION_MAJOR*1000+PETSC_VERSION_MINOR*10) + ENDIF() + ENDIF() IF(OGS_USE_MPI)