<Page x:Class="tbbSample0321.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:tbbSample0321" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Button Name="SR" Margin="167,262,0,406" Height="100" Width="300" Content="Press to run Simple Reduction" Click="SR_Click"></Button> <Button Name="DR" Margin="559,262,0,406" Height="100" Width="300" Content="Press to run Determenistic Reduction" Click="DR_Click"></Button> </Grid> </Page>
#pragma once #include "MainPage.gh" namespace tbbSample0321 { public ref class MainPage sealed { public: MainPage(); protected: virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; private: void SR_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void DR_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); };
#include "tbb/tbb.h" void tbbSample0321::MainPage::SR_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { int N=100000000; float fr = 1.0f/(float)N; float sum = tbb::parallel_reduce( tbb::blocked_range<int>(0,N), 0.0f, [=](const tbb::blocked_range<int>& r, float sum)->float { for( int i=r.begin(); i!=r.end(); ++i ) sum += fr; return sum; }, []( float x, float y )->float { return x+y; } ); SR->Content="Press to run Simple ReductionnThe answer is " + sum.ToString(); } void tbbSample0321::MainPage::DR_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { int N=100000000; float fr = 1.0f/(float)N; float sum = tbb::parallel_deterministic_reduce( tbb::blocked_range<int>(0,N), 0.0f, [=](const tbb::blocked_range<int>& r, float sum)->float { for( int i=r.begin(); i!=r.end(); ++i ) sum += fr; return sum; }, []( float x, float y )->float { return x+y; } ); DR->Content="Press to run Deterministic ReductionnThe answer is " + sum.ToString(); }
Source: https://habr.com/ru/post/175121/
All Articles