Skip to content

Commit

Permalink
[arcane,tests] Supprime test spécifique de 'tbb::spin_mutex'.
Browse files Browse the repository at this point in the history
Ce mutex n'est pas utilisé dans Arcane.
  • Loading branch information
grospelliergilles committed Dec 28, 2024
1 parent d17dfd1 commit d6bc1e3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 94 deletions.
4 changes: 0 additions & 4 deletions arcane/src/arcane/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ if(GEOMETRYKERNEL_FOUND)
set(TEST_DIRS ${TEST_DIRS} corefinement)
set(TEST_LIBS ${TEST_LIBS} arcane_corefinement)
endif()
set(PKGS TBB)
arcane_find_package(TBB)

arcane_find_package(Neo QUIET)
if (Neo_FOUND)
Expand Down Expand Up @@ -76,8 +74,6 @@ arcane_add_library(arcane_tests_lib
AXL_FILES ${AXL_FILES}
)

arcane_add_arccon_packages(arcane_tests_lib PRIVATE ${PKGS})

add_executable(arcane_tests_exec ${ARCANE_SRC_PATH}/arcane/tests/ArcaneTestMain.cc)
set(ARCANE_TEST_PATH ${ARCANEBUILDROOT}/src/arcane/tests)

Expand Down
162 changes: 72 additions & 90 deletions arcane/src/arcane/tests/TaskUnitTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,19 @@
#include "arcane/utils/ValueChecker.h"
#include "arcane/utils/TestLogger.h"

#include "arcane/BasicUnitTest.h"
#include "arcane/IMesh.h"
#include "arcane/Concurrency.h"
#include "arcane/ItemFunctor.h"
#include "arcane/ObserverPool.h"
#include "arcane/ItemPrinter.h"

#include "arcane/tests/ArcaneTestGlobal.h"
#include "arcane/tests/TaskUnitTest_axl.h"
#include "arcane/core/BasicUnitTest.h"
#include "arcane/core/IMesh.h"
#include "arcane/core/Concurrency.h"
#include "arcane/core/ItemFunctor.h"
#include "arcane/core/ObserverPool.h"
#include "arcane/core/ItemPrinter.h"

#include "arcane_packages.h"
#include "arcane/tests/TaskUnitTest_axl.h"

#include <thread>

#ifdef ARCANE_HAS_PACKAGE_TBB
#include <tbb/spin_mutex.h>
using namespace tbb;
#endif

long SerialFib( long n ) {
long SerialFib(long n)

Check warning on line 32 in arcane/src/arcane/tests/TaskUnitTest.cc

View check run for this annotation

Codecov / codecov/patch

arcane/src/arcane/tests/TaskUnitTest.cc#L32

Added line #L32 was not covered by tests
{
if( n<2 )
return n;
else
Expand Down Expand Up @@ -66,8 +59,14 @@ class Test2
: public TraceAccessor
{
public:
Test2(ITraceMng* tm) : TraceAccessor(tm), m_wanted_nb_task(0) {}

explicit Test2(ITraceMng* tm)
: TraceAccessor(tm)
, m_wanted_nb_task(0)
{}

public:

void exec()
{
m_nb = 0;
Expand Down Expand Up @@ -96,12 +95,13 @@ class Test2
}

private:

void _testCallback()
{
++m_nb;
}
std::atomic<Int32> m_nb;
Integer m_wanted_nb_task;
std::atomic<Int32> m_nb = 0;
Integer m_wanted_nb_task = 0;
};

/*---------------------------------------------------------------------------*/
Expand All @@ -113,6 +113,7 @@ class Test3
: public TraceAccessor
{
public:

Test3(ITraceMng* tm,IMesh* mesh)
: TraceAccessor(tm), m_mesh(mesh), m_node_coord(mesh->nodesCoordinates()),
m_node_nb_access(VariableBuildInfo(mesh,"NodeNbAccess")),
Expand All @@ -122,7 +123,9 @@ class Test3
m_saved_value = 0.0;
m_max_thread_index = (-1);
}

public:

void exec()
{
m_total_value = 0.0;
Expand Down Expand Up @@ -384,10 +387,10 @@ class Test3
}
}

IMesh* m_mesh;
Real m_total_value;
Real m_saved_value;
Integer m_max_thread_index;
IMesh* m_mesh = nullptr;
Real m_total_value = 0.0;
Real m_saved_value = 0.0;
Integer m_max_thread_index = 0;
SpinLock m_reduce_lock;
VariableNodeReal3 m_node_coord;
VariableNodeInteger m_node_nb_access;
Expand All @@ -397,7 +400,6 @@ class Test3
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

Expand All @@ -408,7 +410,8 @@ class Test4
class IAction
{
public:
virtual ~IAction(){}

virtual ~IAction() = default;
virtual Int32 value() =0;
virtual void loop(Integer nb_loop) =0;
};
Expand All @@ -417,8 +420,8 @@ class Test4
{
public:
DoAtomic() { m_nb = 0; }
Int32 value() { return m_nb.load(); }
void loop(Integer nb_loop)
Int32 value() override { return m_nb.load(); }
void loop(Integer nb_loop) override
{
for( int i=0; i<nb_loop; ++i )
++m_nb;
Expand All @@ -429,9 +432,10 @@ class Test4
class DoSpinLock : public IAction
{
public:

DoSpinLock() : m_nb(0) {}
Int32 value() { return m_nb; }
void loop(Integer nb_loop)
Int32 value() override { return m_nb; }
void loop(Integer nb_loop) override
{
for( int i=0; i<nb_loop; ++i ){
SpinLock::ScopedLock sl(m_lock);
Expand All @@ -442,43 +446,32 @@ class Test4
SpinLock m_lock;
};

#ifdef ARCANE_HAS_PACKAGE_TBB
class DoSpinLockTBB : public IAction
{
public:
DoSpinLockTBB() : m_nb(0) {}
Int32 value() { return m_nb; }
void loop(Integer nb_loop)
{
for( int i=0; i<nb_loop; ++i ){
tbb::spin_mutex::scoped_lock sl(m_lock);
++m_nb;
}
}
Int32 m_nb;
tbb::spin_mutex m_lock;
};
#endif

class DoMutex : public IAction
class DoMutex
: public IAction
{
public:
DoMutex() : m_nb(0) {}
Int32 value() { return m_nb; }
void loop(Integer nb_loop)
Int32 value() override { return m_nb; }
void loop(Integer nb_loop) override
{
for( int i=0; i<nb_loop; ++i ){
Mutex::ScopedLock sl(m_lock);
++m_nb;
}
}
Int32 m_nb;
Int32 m_nb = 0;
Mutex m_lock;
};

public:
Test4(ITraceMng* tm) : TraceAccessor(tm), m_action(nullptr) {}

explicit Test4(ITraceMng* tm)
: TraceAccessor(tm)
, m_action(nullptr)
{}

public:

void exec()
{
int n = 100000;
Expand All @@ -491,47 +484,36 @@ class Test4
Real v1 = platform::getRealTime();
ParallelLoopOptions loop_options2;
loop_options2.setGrainSize(n2);
arcaneParallelFor(0,n,loop_options2,[&](Integer a,Integer n){ _DoLoop(a,n); });
arcaneParallelFor(0, n, loop_options2, [&](Integer a, Integer n) { _doLoop(a, n); });
Real v2 = platform::getRealTime();
_print("atomic",m_action->value(),v2-v1,n);
}
{
DoSpinLock spinlock_action;
m_action = &spinlock_action;
Real v1 = platform::getRealTime();
arcaneParallelFor(0,n,loop_options,[&](Integer a,Integer n){ _DoLoop(a,n); });
arcaneParallelFor(0, n, loop_options, [&](Integer a, Integer n) { _doLoop(a, n); });
Real v2 = platform::getRealTime();
_print("spin",m_action->value(),v2-v1,n);
_print("spin", m_action->value(), v2 - v1, n);
}
{
DoMutex mutex_action;
m_action = &mutex_action;
Real v1 = platform::getRealTime();
arcaneParallelFor(0,n,loop_options,[&](Integer a,Integer n){ _DoLoop(a,n); });
Real v2 = platform::getRealTime();
_print("mutex",m_action->value(),v2-v1,n);
}
#ifdef ARCANE_HAS_PACKAGE_TBB
{
DoSpinLockTBB spintbb_action;
m_action = &spintbb_action;
Real v1 = platform::getRealTime();
arcaneParallelFor(0,n,loop_options,[&](Integer a,Integer n){ _DoLoop(a,n); });
arcaneParallelFor(0, n, loop_options, [&](Integer a, Integer n) { _doLoop(a, n); });
Real v2 = platform::getRealTime();
_print("spintbb",m_action->value(),v2-v1,n);
_print("mutex", m_action->value(), v2 - v1, n);
}
#endif
{
// Test Mutex avec syntaxe des lambda fonction du C++0x
DoMutex mutex_action;
m_action = &mutex_action;
Real v1 = platform::getRealTime();
arcaneParallelFor(0,n,loop_options,[this](Integer /*i0*/,Integer size)
{
m_action->loop(size*10);
});
arcaneParallelFor(0, n, loop_options, [this](Integer /*i0*/, Integer size) {
m_action->loop(size * 10);
});
Real v2 = platform::getRealTime();
_print("mutex_c++0x",m_action->value(),v2-v1,n);
_print("mutex_c++0x", m_action->value(), v2 - v1, n);
}
}

Expand All @@ -541,13 +523,14 @@ class Test4
<< " time=" << elapsed_time << " time2=" << elapsed_time / (n*10);
}

void _DoLoop(Integer /*i0*/,Integer size)
void _doLoop(Integer /*i0*/, Integer size)
{
m_action->loop(size*10);
}

private:
IAction* m_action;

IAction* m_action = nullptr;
};

/*---------------------------------------------------------------------------*/
Expand All @@ -560,18 +543,21 @@ class Test5Fibonnaci
{
public:

public:
const long n;
long* const sum;
const long n = 0;
long* const sum = nullptr;

Test5Fibonnaci( long n_, long* sum_ ) : n(n_), sum(sum_)
{}

void execute(const TaskContext& context);

static long SerialFib( long n ) {
if( n<2 )
return n;
else
return SerialFib(n-1)+SerialFib(n-2);
}

static long ParallelFib( long n )
{
long sum = 0;
Expand All @@ -581,6 +567,7 @@ class Test5Fibonnaci
return sum;
}
public:

static std::atomic<Int32> m_nb_exec;
};
std::atomic<Int32> Test5Fibonnaci::m_nb_exec(0);
Expand Down Expand Up @@ -664,9 +651,9 @@ class Test6
}
}
Int64 m_value = 0;
Int32 m_first_value;
Int32 m_nb_value;
Int32 m_step_size;
Int32 m_first_value = 0;
Int32 m_nb_value = 0;
Int32 m_step_size = 0;
SpinLock m_lock;
};

Expand All @@ -680,17 +667,15 @@ class Test6
class TaskUnitTest
: public ArcaneTaskUnitTestObject
{
public:

public:
public:

TaskUnitTest(const ServiceBuildInfo& cb);
~TaskUnitTest();
explicit TaskUnitTest(const ServiceBuildInfo& cb);
~TaskUnitTest() override;

public:

virtual void initializeTest();
virtual void executeTest();
void initializeTest() override;
void executeTest() override;

private:

Expand Down Expand Up @@ -817,9 +802,6 @@ initializeTest()
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

} // End namespace ArcaneTest

/*---------------------------------------------------------------------------*/
Expand Down

0 comments on commit d6bc1e3

Please sign in to comment.