From fd1cbdb27193e0fd988f469d36f868de6cafe30c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 8 Mar 2016 20:08:54 -0600 Subject: [PATCH] Add tests. --- tests/base/task_12.cc | 62 ++++++++++++++++++++++ tests/base/task_12.with_cxx11=true.output | 6 +++ tests/base/task_13.cc | 64 +++++++++++++++++++++++ tests/base/task_13.with_cxx11=true.output | 6 +++ 4 files changed, 138 insertions(+) create mode 100644 tests/base/task_12.cc create mode 100644 tests/base/task_12.with_cxx11=true.output create mode 100644 tests/base/task_13.cc create mode 100644 tests/base/task_13.with_cxx11=true.output diff --git a/tests/base/task_12.cc b/tests/base/task_12.cc new file mode 100644 index 0000000000..37a55b2426 --- /dev/null +++ b/tests/base/task_12.cc @@ -0,0 +1,62 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// verify that we can create tasks both via lambdas and via std::bind +// expressions. this obviously requires C++11 + +#include "../tests.h" +#include +#include +#include + +#include + + +// return a double, to make sure we correctly identify the return type +// of the expressions used in new_task(...) +double test (int i) +{ + deallog << "Task " << i << " starting..." << std::endl; + sleep (1); + deallog << "Task " << i << " finished!" << std::endl; + + return 3.141; +} + + + + +int main() +{ + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + Threads::TaskGroup tg; + tg += Threads::new_task (std::bind (test, 1)); + tg += Threads::new_task ([]() + { + return test(2); + }); + + tg.join_all (); + + deallog << "OK" << std::endl; + + deallog.detach (); + logfile.close (); + sort_file_contents ("output"); +} diff --git a/tests/base/task_12.with_cxx11=true.output b/tests/base/task_12.with_cxx11=true.output new file mode 100644 index 0000000000..d239d4dd83 --- /dev/null +++ b/tests/base/task_12.with_cxx11=true.output @@ -0,0 +1,6 @@ +DEAL::OK +DEAL::Task 1 finished! +DEAL::Task 1 starting... +DEAL::Task 2 finished! +DEAL::Task 2 starting... + diff --git a/tests/base/task_13.cc b/tests/base/task_13.cc new file mode 100644 index 0000000000..e9655e0240 --- /dev/null +++ b/tests/base/task_13.cc @@ -0,0 +1,64 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// verify that we can create tasks both via lambdas and via std::bind +// expressions. this obviously requires C++11 +// +// this is a small variation of the _12 test + + +#include "../tests.h" +#include +#include +#include + +#include + + +// return a double, to make sure we correctly identify the return type +// of the expressions used in new_task(...) +double test (int i) +{ + deallog << "Task " << i << " starting..." << std::endl; + sleep (1); + deallog << "Task " << i << " finished!" << std::endl; + + return 3.141; +} + + + + +int main() +{ + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + Threads::TaskGroup tg; + + // use variations of ways we can declare lambdas + tg += Threads::new_task ([]() -> double { return test(1); }); + tg += Threads::new_task ([]() -> double { return (float)test(2); }); + + tg.join_all (); + + deallog << "OK" << std::endl; + + deallog.detach (); + logfile.close (); + sort_file_contents ("output"); +} diff --git a/tests/base/task_13.with_cxx11=true.output b/tests/base/task_13.with_cxx11=true.output new file mode 100644 index 0000000000..d239d4dd83 --- /dev/null +++ b/tests/base/task_13.with_cxx11=true.output @@ -0,0 +1,6 @@ +DEAL::OK +DEAL::Task 1 finished! +DEAL::Task 1 starting... +DEAL::Task 2 finished! +DEAL::Task 2 starting... + -- 2.39.5