|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // Teuchos: Common Tools Package 00006 // Copyright (2004) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // This library is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Lesser General Public License as 00013 // published by the Free Software Foundation; either version 2.1 of the 00014 // License, or (at your option) any later version. 00015 // 00016 // This library is distributed in the hope that it will be useful, but 00017 // WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00024 // USA 00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00026 // 00027 // *********************************************************************** 00028 // @HEADER 00029 */ 00030 00031 #include "Teuchos_TimeMonitor.hpp" 00032 #include "Teuchos_Version.hpp" 00033 00034 #ifdef HAVE_MPI 00035 #include <mpi.h> 00036 #endif 00037 00038 using namespace Teuchos; 00039 00040 // Global Timers 00041 RCP<Time> CompTime = TimeMonitor::getNewTimer("Computational Time"); 00042 RCP<Time> FactTime = TimeMonitor::getNewTimer("Factorial Time"); 00043 00044 // Quadratic function declaration. 00045 double quadFunc( double x ); 00046 00047 // Factorial function declaration. 00048 double factFunc( int x ); 00049 00050 int main(int argc, char* argv[]) 00051 { 00052 std::cout << Teuchos::Teuchos_Version() << std::endl << std::endl; 00053 00054 int i; 00055 double x; 00056 00057 #ifdef HAVE_MPI 00058 MPI_Init(&argc, &argv); 00059 #endif 00060 00061 // Apply the quadratic function. 00062 for( i=-100; i<100; i++ ) { 00063 x = quadFunc( (double) i ); 00064 } 00065 00066 // Apply the factorial function. 00067 for( i=0; i<100; i++ ) { 00068 x = factFunc( i ); 00069 } 00070 00071 // Get a summary from the time monitor. 00072 TimeMonitor::summarize(); 00073 00074 #ifdef HAVE_MPI 00075 MPI_Finalize(); 00076 #endif 00077 00078 return 0; 00079 } 00080 00081 /* Evaluate a quadratic function at point x */ 00082 double quadFunc( double x ) 00083 { 00084 // Construct a local time monitor, this starts the CompTime timer and will stop when leaving scope. 00085 Teuchos::TimeMonitor LocalTimer(*CompTime); 00086 00087 // Evaluate the quadratic function. 00088 return ( x*x - 1.0 ); 00089 } 00090 00091 /* Compute the factorial of x */ 00092 double factFunc( int x ) 00093 { 00094 // Construct a local time monitor, this starts the FactTime timer and will stop when leaving scope. 00095 Teuchos::TimeMonitor LocalTimer(*FactTime); 00096 00097 // Special returns for specific cases. 00098 if( x == 0 ) return 0.0; 00099 if( x == 1 ) return 1.0; 00100 00101 // Evaluate the factorial function. 00102 return ( (double) x * factFunc(x-1) ); 00103 }
1.7.4