mirror of
https://github.com/boostorg/odeint.git
synced 2025-05-11 13:34:09 +00:00
performance test sources
This commit is contained in:
parent
b6ebc0f156
commit
6e41b57ba1
39
performance/Makefile
Normal file
39
performance/Makefile
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright 2011-2014 Mario Mulansky
|
||||
# Copyright 2011-2014 Karsten Ahnert
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or
|
||||
# copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# make sure BOOST_ROOT is pointing to your boost directory
|
||||
# otherwise, set it here:
|
||||
# BOOST_ROOT = /path/to/boost
|
||||
|
||||
INCLUDES += -I../../include/ -I$(BOOST_ROOT)
|
||||
GCCFLAGS = -O3 -ffast-math -DNDEBUG
|
||||
# disabling -ffast-math might give slightly better performance
|
||||
ICCFLAGS = -fast -ip -inline-forceinline -DNDEBUG
|
||||
# Possible options: -fp-model source -no-fma
|
||||
GFORTFLAGS = -Ofast
|
||||
|
||||
bin/gcc:
|
||||
mkdir -p bin/gcc
|
||||
|
||||
bin/intel:
|
||||
mkdir -p bin/intel
|
||||
|
||||
bin/gfort:
|
||||
mkdir -p bin/gfort
|
||||
|
||||
bin/gcc/odeint_rk4_array: odeint_rk4_array.cpp bin/gcc
|
||||
g++ ${GCCFLAGS} ${INCLUDES} -o bin/gcc/odeint_rk4_array odeint_rk4_array.cpp
|
||||
|
||||
|
||||
bin/intel/odeint_rk4_array: odeint_rk4_array.cpp bin/intel
|
||||
icpc ${ICCFLAGS} ${INCLUDES} -o bin/intel/odeint_rk4_array odeint_rk4_array.cpp
|
||||
|
||||
|
||||
bin/gfort/fortran_lorenz: fortran_lorenz.f90 bin/gfort
|
||||
gfortran ${GFORTFLAGS} fortran_lorenz.f90 -o bin/gfort/fortran_lorenz
|
||||
|
||||
all: bin/gcc/odeint_rk4_array bin/intel/odeint_rk4_array bin/gfort/fortran_lorenz
|
57
performance/fortran_lorenz.f90
Normal file
57
performance/fortran_lorenz.f90
Normal file
@ -0,0 +1,57 @@
|
||||
program main
|
||||
implicit none
|
||||
|
||||
integer, parameter :: dp = 8
|
||||
real(dp), dimension(1:3) :: x
|
||||
integer, parameter :: nstep = 20000000
|
||||
real(dp) :: t = 0.0_dp
|
||||
real(dp) :: h = 1.0e-10_dp
|
||||
integer, parameter :: nb_loops = 21
|
||||
integer, parameter :: n = 3
|
||||
integer :: k
|
||||
integer :: time_begin
|
||||
integer :: time_end
|
||||
integer :: count_rate
|
||||
real(dp) :: time
|
||||
|
||||
do k = 1, nb_loops
|
||||
x = [ 8.5_dp, 3.1_dp, 1.2_dp ]
|
||||
call system_clock(time_begin, count_rate)
|
||||
call rk4sys(n, t, x, h, nstep)
|
||||
call system_clock(time_end, count_rate)
|
||||
time = real(time_end - time_begin, dp) / real(count_rate, dp)
|
||||
write (*,*) time, x(1)
|
||||
end do
|
||||
contains
|
||||
subroutine xpsys(x,f)
|
||||
real(dp), dimension(1:3), intent(in) :: x
|
||||
real(dp), dimension(1:3), intent(out) :: f
|
||||
f(1) = 10.0_dp * ( x(2) - x(1) )
|
||||
f(2) = 28.0_dp * x(1) - x(2) - x(1) * x(3)
|
||||
f(3) = x(1) * x(2) - (8.0_dp / 3.0_dp) * x(3)
|
||||
end subroutine xpsys
|
||||
|
||||
subroutine rk4sys(n, t, x, h, nstep)
|
||||
integer, intent(in) :: n
|
||||
real(dp), intent(in) :: t
|
||||
real(dp), dimension(1:n), intent(inout) :: x
|
||||
real(dp), intent(in) :: h
|
||||
integer, intent(in) :: nstep
|
||||
! Local variables
|
||||
real(dp) :: h2
|
||||
real(dp), dimension(1:n) :: y, f1, f2, f3, f4
|
||||
integer :: i, k
|
||||
|
||||
h2 = 0.5_dp * h
|
||||
do k = 1, nstep
|
||||
call xpsys(x, f1)
|
||||
y = x + h2 * f1
|
||||
call xpsys(y, f2)
|
||||
y = x + h2 * f2
|
||||
call xpsys(y, f3)
|
||||
y = x + h * f3
|
||||
call xpsys(y, f4)
|
||||
x = x + h * (f1 + 2.0_dp * (f2 + f3) + f4) / 6.0_dp
|
||||
end do
|
||||
end subroutine rk4sys
|
||||
end program main
|
55
performance/odeint_rk4_array.cpp
Normal file
55
performance/odeint_rk4_array.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* odeint_rk4_lorenz_def_alg.cpp
|
||||
*
|
||||
* Copyright 2011 Mario Mulansky
|
||||
* Copyright 2012 Karsten Ahnert
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or
|
||||
* copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
|
||||
#include <boost/timer.hpp>
|
||||
#include <boost/array.hpp>
|
||||
|
||||
#include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
|
||||
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
|
||||
#include <boost/numeric/odeint/algebra/array_algebra.hpp>
|
||||
|
||||
#include "lorenz.hpp"
|
||||
|
||||
typedef boost::timer timer_type;
|
||||
|
||||
typedef boost::array< double , 3 > state_type;
|
||||
|
||||
using namespace boost::numeric::odeint;
|
||||
//typedef boost::numeric::odeint::runge_kutta4_classic< state_type > rk4_odeint_type;
|
||||
typedef runge_kutta4_classic< state_type , double , state_type , double ,
|
||||
range_algebra, default_operations, never_resizer > rk4_odeint_type;
|
||||
|
||||
|
||||
const int loops = 21;
|
||||
const int num_of_steps = 20000000;
|
||||
const double dt = 1E-10;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
double min_time = 1E6; // something big
|
||||
rk4_odeint_type stepper;
|
||||
for( int n=0; n<loops; n++ )
|
||||
{
|
||||
state_type x = {{ 8.5, 3.1, 1.2 }};
|
||||
double t = 0.0;
|
||||
timer_type timer;
|
||||
for( size_t i = 0 ; i < num_of_steps ; ++i )
|
||||
{
|
||||
stepper.do_step( lorenz(), x, t, dt );
|
||||
t += dt;
|
||||
}
|
||||
min_time = std::min( timer.elapsed() , min_time );
|
||||
std::clog << timer.elapsed() << '\t' << x[0] << std::endl;
|
||||
}
|
||||
std::cout << "Minimal Runtime: " << min_time << std::endl;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user