Math 4997-1 Lecture 13: Futurization of the 1D heat equation - - PowerPoint PPT Presentation

math 4997 1
SMART_READER_LITE
LIVE PREVIEW

Math 4997-1 Lecture 13: Futurization of the 1D heat equation - - PowerPoint PPT Presentation

Math 4997-1 Lecture 13: Futurization of the 1D heat equation Patrick Diehl https://www.cct.lsu.edu/~pdiehl/teaching/2020/4997/ This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0


slide-1
SLIDE 1

Math 4997-1

Lecture 13: Futurization of the 1D heat equation

Patrick Diehl https://www.cct.lsu.edu/~pdiehl/teaching/2020/4997/ This work is licensed under a Creative Commons “Attribution-NonCommercial- NoDerivatives 4.0 International” license.

slide-2
SLIDE 2

Reminder HPX features Scaling results Summary

slide-3
SLIDE 3

Reminder

slide-4
SLIDE 4

Lecture 12

What you should know from last lecture

◮ One-dimensional heat equation ◮ Serial implementation of the one-dimensional heat equation

slide-5
SLIDE 5

HPX features

slide-6
SLIDE 6

A ready future

Some times, we need a future, which is already ready, since there is no computation needed.

hpx::lcos::future<double > f = hpx::make_ready_future(1);

Example

auto f = hpx::make_ready_future(1); /* * Since the future is ready the output will happen * and there will be no barrier. */ std::cout << f.get() << std::endl;

slide-7
SLIDE 7

Data fmow I

std::vector<hpx::lcos::future<int>> futures; futures.push_back(hpx::async(square ,10)); futures.push_back(hpx::async(square ,100)); // When all returns a future containing the vector // of futures hpx::when_all(futures).then([](auto&& f){ // We need to unwrap this future to get // the content of it auto futures = f.get(); int result = 0; for(size_t i = 0; i < futures.size();i++) result += futures[i].get(); std::cout << result << std::endl; });

slide-8
SLIDE 8

Data fmow II

hpx::dataflow(hpx::launch::sync ,[](auto f){ int result = 0; for(size_t i = 0; i < f.size();i++) result += f[i].get(); std::cout << result << std::endl; },futures);

Parameters

  • 1. hpx::launch::async or hpx::launch::sync
  • 2. The function to call
  • 3. Futures to the arguments to the arguments of the

function

slide-9
SLIDE 9

Passing futures

void sum(int first, int second){ std:: cout << first + second << std::endl; } auto f1 = hpx::async(square ,10); auto f2 = hpx::async(square ,100); // We have to call .get() to pass // the values of the future sum(f1.get(),f2.get());

slide-10
SLIDE 10

Unwrapping futures

void sum(int first, int second){ std:: cout << first + second << std::endl; } // We can unwrapp the function auto fp = hpx::util::unwrapping(sum); // After unwrapping , we can pass the future // directly to the function hpx::dataflow(hpx::launch::sync,fp,f1,f2);

slide-11
SLIDE 11

Shared future

hpx::lcos::future

◮ Exclusive ownership model ◮ If the future is out of the scope, it will be not available anymore.

hpx::shared_future

◮ Reference counting

  • wnership model

◮ All references to the

  • bject are counted and

the object is only destroyed if there are zero references. Can be seen to be equal to std::unique_ptr and

std::shared_ptr.

slide-12
SLIDE 12

Scaling results

slide-13
SLIDE 13

Overhead

0.2 0.4 0.6 0.8 1 ·107 20 40 60 80 100 Grid points Execution time 1 CPU Serial Futurization

slide-14
SLIDE 14

Scaling

0.2 0.4 0.6 0.8 1 ·106 20 40 60 80 100 Grid points Execution time Stencil 2 1 CPU 2 CPU 4 CPU 6 CPU

slide-15
SLIDE 15

Summary

slide-16
SLIDE 16

Summary

After this lecture, you should know

◮ hpx::make_ready_future ◮ hpx::dataflow ◮ hpx::util::unwrapping ◮ hpx::shared_future