Skip to content
Snippets Groups Projects
Commit 5e209765 authored by Steffen Müthing's avatar Steffen Müthing
Browse files

[Tests] Add simple test running a TBB program if TBB was found

parent d8fb9a6b
No related branches found
No related tags found
No related merge requests found
......@@ -72,3 +72,4 @@ testdebugallocator_fail5
eigenvaluestest
*.log
*.trs
tbbruntest
......@@ -57,6 +57,12 @@ TESTPROGS = \
tupleutilitytest \
utilitytest
# only run this test if TBB is availabe
if TBB
TESTPROGS+=tbbruntest
endif
# which tests to run
COMPILE_XFAIL=$(DUNE_COMMON_BIN)/xfail-compile-tests
......@@ -209,6 +215,13 @@ singletontest_SOURCES = singletontest.cc
utilitytest_SOURCES = utilitytest.cc
if TBB
tbbruntest_SOURCES = tbbruntest.cc
tbbruntest_CPPFLAGS = $(AM_CPPFLAGS) $(TBB_CPPFLAGS)
tbbruntest_LDADD = $(TBB_LIBS) $(LDADD)
tbbruntest_LDFLAGS = $(AM_LDFLAGS) $(TBB_LDFLAGS)
endif
testdebugallocator_SOURCES = testdebugallocator.cc
testdebugallocator_CPPFLAGS = $(AM_CPPFLAGS)
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tbb/tbb.h>
#include <numeric>
#include <iostream>
#if __cplusplus < 201103L
// provide a fallback for compilers without lambdas
struct add
{
add(int* x)
: _x(x)
{}
int* _x;
void operator()(int i) const
{
_x[i] = i;
}
};
#endif
int main()
{
int x[10] = {0};
#if __cplusplus >= 201103L
tbb::parallel_for(0,10,[&](int i){ x[i] = i; });
#else
tbb::parallel_for(0,10,add(x));
#endif
int result = std::accumulate(x,x+10,0);
int expected = (9*10)/2;
std::cout << result << " == " << expected << (result == expected ? " ok" : " ERROR") << std::endl;
return !(result == expected);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment