Skip to content

Commit

Permalink
Fix for issue #3 (Enable OpenMP support on Linux.)
Browse files Browse the repository at this point in the history
OpenMP is no the default setting for cmake based builds
  • Loading branch information
Ingo Berg committed Jun 2, 2020
1 parent 8d4b126 commit cf738a7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@
*.opendb
*.db-wal
*.ipch
.vs/CMake Overview
.vs/ProjectSettings.json
.vs/slnx.sqlite
.vs/*
build/*
out/*
CMakeSettings.json
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -15,12 +15,12 @@ project(muParserProject)
# Bump versions on release
set(MUPARSER_VERSION_MAJOR 2)
set(MUPARSER_VERSION_MINOR 2)
set(MUPARSER_VERSION_PATCH 6)
set(MUPARSER_VERSION_PATCH 7)
set(MUPARSER_VERSION ${MUPARSER_VERSION_MAJOR}.${MUPARSER_VERSION_MINOR}.${MUPARSER_VERSION_PATCH})

# Build options
option(ENABLE_SAMPLES "Build the samples" ON)
option(ENABLE_OPENMP "Enable OpenMP for multithreading" OFF)
option(ENABLE_OPENMP "Enable OpenMP for multithreading" ON)
option(BUILD_SHARED_LIBS "Build shared/static libs" ON)

if(ENABLE_OPENMP)
Expand Down
4 changes: 4 additions & 0 deletions include/muParserDef.h
Expand Up @@ -57,6 +57,10 @@
/** \brief Activate this option in order to compile with OpenMP support.
OpenMP is used only in the bulk mode it may increase the performance a bit.
!!! DO NOT ACTIVATE THIS MACRO HERE IS YOU USE CMAKE FOR BUILDING !!!
use the cmake option instead!
*/
//#define MUP_USE_OPENMP

Expand Down
2 changes: 1 addition & 1 deletion src/muParserBase.cpp
Expand Up @@ -1750,7 +1750,7 @@ namespace mu
int nThreadID = 0, ct = 0;
omp_set_num_threads(nMaxThreads);

#pragma omp parallel for schedule(static, nBulkSize/nMaxThreads) private(nThreadID)
#pragma omp parallel for schedule(static, std::max(nBulkSize/nMaxThreads, 1)) private(nThreadID)
for (i = 0; i < nBulkSize; ++i)
{
nThreadID = omp_get_thread_num();
Expand Down
30 changes: 16 additions & 14 deletions src/muParserTest.cpp
Expand Up @@ -162,33 +162,35 @@ namespace mu
//---------------------------------------------------------------------------------------------
int ParserTester::TestBulkMode()
{
// return 0;

int iStat = 0;
mu::console() << _T("testing bulkmode...");

#define EQN_TEST_BULK(EXPR, R1, R2, R3, R4, PASS) \
{ \
double res[] = { R1, R2, R3, R4 }; \
iStat += EqnTestBulk(_T(EXPR), res, (PASS)); \
}
{ \
double res[] = { R1, R2, R3, R4 }; \
iStat += EqnTestBulk(_T(EXPR), res, (PASS)); \
}

// Bulk Variables for the test:
// a: 1,2,3,4
// b: 2,2,2,2
// c: 3,3,3,3
// d: 5,4,3,2
EQN_TEST_BULK("a", 1, 1, 1, 1, false)
EQN_TEST_BULK("a", 1, 2, 3, 4, true)
EQN_TEST_BULK("b=a", 1, 2, 3, 4, true)
EQN_TEST_BULK("b=a, b*10", 10, 20, 30, 40, true)
EQN_TEST_BULK("b=a, b*10, a", 1, 2, 3, 4, true)
EQN_TEST_BULK("a+b", 3, 4, 5, 6, true)
EQN_TEST_BULK("c*(a+b)", 9, 12, 15, 18, true)
EQN_TEST_BULK("a", 1, 2, 3, 4, true)
EQN_TEST_BULK("b=a", 1, 2, 3, 4, true)
EQN_TEST_BULK("b=a, b*10", 10, 20, 30, 40, true)
EQN_TEST_BULK("b=a, b*10, a", 1, 2, 3, 4, true)
EQN_TEST_BULK("a+b", 3, 4, 5, 6, true)
EQN_TEST_BULK("c*(a+b)", 9, 12, 15, 18, true)
#undef EQN_TEST_BULK

if (iStat == 0)
mu::console() << _T("passed") << endl;
else
mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl;
if (iStat == 0)
mu::console() << _T("passed") << endl;
else
mu::console() << _T("\n failed with ") << iStat << _T(" errors") << endl;

return iStat;
}
Expand Down

0 comments on commit cf738a7

Please sign in to comment.