1
操作系統= Ubuntu。爲什麼CPPUNIT_ASSERT_MESSAGE會導致OpenMP錯誤?
bjam usage = TRUE。
我想借助OpenMP優化我的單元測試系統。
的bjam腳本文件:
lib my_lib
:
[ glob sources/*.cpp ]
:
<link>static
;
...
explicit my_project ;
unit-test my_project
:
[ glob UnitTests/*.cpp ]
my_lib
:
<linkflags>-fopenmp
<cflags>-fopenmp
;
我的代碼的一部分:
for(j = 0; j < AMOUNT; j++)
{
#pragma omp parallel for
for(i = 0; i < 0x10000; ++i)
{
...
try
{
variable1 = func1();
variable2 = func2();
//variable1 and variable 2 must be equal
CPPUNIT_ASSERT_MESSAGE("OLOLO", variable1 == variable2);
}
catch (const std::logic_error& exception)
{
std::cerr << exception.what() << std::endl;
CPPUNIT_ASSERT_MESSAGE("OLOLO", 0);
}
catch (const std::runtime_error & exception)
{
std::cerr << exception.what() << std::endl;
CPPUNIT_ASSERT_MESSAGE("OLOLO", 0);
}
}
}
當我啓動我的測試系統,它退出,出現錯誤:
terminate called without an active exception
Aborted
我註釋行CPPUNIT_ASSERT_MESSAGE :
for(j = 0; j < AMOUNT; j++)
{
#pragma omp parallel for
for(i = 0; i < 0x10000; ++i)
{
...
try
{
variable1 = func1();
variable2 = func2();
//CPPUNIT_ASSERT_MESSAGE("OLOLO", variable1 == variable2);
}
catch (const std::logic_error& exception)
{
std::cerr << exception.what() << std::endl;
//CPPUNIT_ASSERT_MESSAGE("OLOLO", 0);
}
catch (const std::runtime_error & exception)
{
std::cerr << exception.what() << std::endl;
//CPPUNIT_ASSERT_MESSAGE("OLOLO", 0);
}
}
}
它的工作方式就是我所需要的。但是如果結果不正確,我需要CPPUNIT_ASSERT_MESSAGE來輸出信息。 爲什麼CPPUNIT_ASSERT_MESSAGE會導致錯誤,我應該怎麼做才能擺脫這些錯誤。