]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Nov 2022 23:11:31 +0000 (16:11 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Nov 2022 23:13:46 +0000 (16:13 -0700)
tests/multithreading/task_14.cc [new file with mode: 0644]
tests/multithreading/task_14.output [new file with mode: 0644]

diff --git a/tests/multithreading/task_14.cc b/tests/multithreading/task_14.cc
new file mode 100644 (file)
index 0000000..0ca699e
--- /dev/null
@@ -0,0 +1,50 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2020 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Check TaskGroup::return_values()
+
+
+#include <deal.II/base/thread_management.h>
+
+#include "../tests.h"
+
+
+// return a double, to make sure we correctly identify the return type
+// of the expressions used in new_task(...)
+int
+test(int i)
+{
+  return 2 * i;
+}
+
+
+
+int
+main()
+{
+  initlog();
+
+  // Create a bunch of tasks, and put them into a TaskGroup
+  Threads::TaskGroup<int> tg;
+  for (unsigned int i = 0; i < 10; ++i)
+    tg += Threads::new_task(&test, i);
+
+  // Then wait for them all to finish and output their respective
+  // return values. They should be ordered the same way the tasks were
+  // created, and should be twice the input argument:
+  for (const int r : tg.return_values())
+    deallog << r << std::endl;
+}
diff --git a/tests/multithreading/task_14.output b/tests/multithreading/task_14.output
new file mode 100644 (file)
index 0000000..0859f86
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL::0
+DEAL::2
+DEAL::4
+DEAL::6
+DEAL::8
+DEAL::10
+DEAL::12
+DEAL::14
+DEAL::16
+DEAL::18

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.