Skip to content

Commit

Permalink
Change merged black&scholes benchmark to use tie() for loop fusion
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou committed Mar 26, 2014
1 parent a0694f2 commit 38a9f9b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions demo/blackscholes/nt2_merged/blackandscholes_nt2_merged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <nt2/include/functions/unary_minus.hpp>
#include <nt2/include/functions/plus.hpp>
#include <nt2/include/functions/minus.hpp>
#include <nt2/include/functions/tie.hpp>
#include <nt2/include/constants/half.hpp>
#include <vector>
#include <iostream>
Expand Down Expand Up @@ -82,6 +83,9 @@ template<typename T> struct blackandscholes_nt2_merged
Ta.resize(nt2::of_size(size_));
ra.resize(nt2::of_size(size_));
va.resize(nt2::of_size(size_));
da.resize(nt2::of_size(size_));
d1.resize(nt2::of_size(size_));
d2.resize(nt2::of_size(size_));
R.resize(nt2::of_size(size_));

for(std::size_t i = 1; i <= size_; ++i)
Expand All @@ -90,7 +94,11 @@ template<typename T> struct blackandscholes_nt2_merged

void operator()()
{
R = nt2::blackandscholes(Sa, Xa, Ta, ra, va);
nt2::tie(da,d1,d2,R) = nt2::tie ( nt2::sqrt(Ta)
, nt2::log(Sa/Xa) + (nt2::fma(nt2::sqr(va),T(0.5),ra)*Ta)/(va*da)
, nt2::fnms(va,da,d1)
, nt2::fnms(Xa*nt2::exp(-ra*Ta),nt2::fastnormcdf(d2),Sa*nt2::fastnormcdf(d1))
);
}

friend std::ostream& operator<<(std::ostream& os, blackandscholes_nt2_merged<T> const& p)
Expand All @@ -101,7 +109,7 @@ template<typename T> struct blackandscholes_nt2_merged
std::size_t size() const { return size_; }

private:
nt2::table<T> Sa, Xa, Ta, ra, va, R;
nt2::table<T> Sa, Xa, Ta, ra, va, R, da, d1, d2;
std::size_t size_;
};

Expand Down

0 comments on commit 38a9f9b

Please sign in to comment.