From 1490099ddd10dffebcd6d9020b3a4f3c0624b69c Mon Sep 17 00:00:00 2001 From: Carl Poirier Date: Fri, 31 Jan 2014 18:27:06 +0100 Subject: [PATCH] Parallelized the RN_DATA::Recalculate() function. --- CMakeLists.txt | 7 +++++++ pcbnew/CMakeLists.txt | 2 ++ pcbnew/ratsnest_data.cpp | 28 +++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d72d54d6de..c3fc56208b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,13 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" ) endif() + find_package( OpenMP QUIET ) + if( OPENMP_FOUND ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" ) + add_definitions( -DUSE_OPENMP ) + endif() + if( MINGW ) set( CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" ) diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 11663c684f..86e8dd296d 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -1,6 +1,8 @@ set( MAKE_LINK_MAPS false ) +set( CMAKE_CXX_FLAGS "-fopenmp" ) + add_definitions( -DPCBNEW ) add_subdirectory(router) diff --git a/pcbnew/ratsnest_data.cpp b/pcbnew/ratsnest_data.cpp index af5f6932fd..977e3bcc9e 100644 --- a/pcbnew/ratsnest_data.cpp +++ b/pcbnew/ratsnest_data.cpp @@ -27,6 +27,10 @@ * @brief Class that computes missing connections on a PCB. */ +#ifdef USE_OPENMP +#include +#endif /* USE_OPENMP */ + #include #include @@ -829,12 +833,25 @@ void RN_DATA::Recalculate( int aNet ) { if( aNet < 0 ) // Recompute everything { - // Start with net number 1, as 0 stand for not connected - for( unsigned int i = 1; i < m_board->GetNetCount(); ++i ) + unsigned int tid, i, chunk, netCount; + netCount = m_board->GetNetCount(); + chunk = 1; + +#ifdef USE_OPENMP + #pragma omp parallel shared(chunk, netCount) private(i, tid) { - if( m_nets[i].IsDirty() ) - updateNet( i ); - } + tid = omp_get_thread_num(); + #pragma omp for schedule(guided, chunk) +#else /* USE_OPENMP */ + { +#endif + // Start with net number 1, as 0 stand for not connected + for( i = 1; i < netCount; ++i ) + { + if( m_nets[i].IsDirty() ) + updateNet( i ); + } + } /* end of parallel section */ } else if( aNet > 0 ) // Recompute only specific net { @@ -848,3 +865,4 @@ void RN_DATA::ClearSimple() BOOST_FOREACH( RN_NET& net, m_nets ) net.ClearSimple(); } +