Reinstate multi-threading in zone filler.

This commit is contained in:
Jeff Young 2018-03-03 17:40:57 +00:00
parent 919b449595
commit c77d13292b
2 changed files with 48 additions and 24 deletions

View File

@ -81,6 +81,8 @@ void ZONE_FILLER::SetProgressReporter( PROGRESS_REPORTER* aReporter )
void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
{
int parallelThreadCount = std::max( ( int )std::thread::hardware_concurrency(), 2 );
std::vector<CN_ZONE_ISOLATED_ISLAND_LIST> toFill;
auto connectivity = m_board->GetConnectivity();
@ -115,25 +117,33 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
m_progressReporter->SetMaxProgress( toFill.size() );
}
m_next = 0;
m_count_done = 0;
std::thread fillWorker( [ this, toFill ]()
std::vector<std::thread> fillWorkers;
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
{
for( unsigned i = 0; i < toFill.size(); i++ )
fillWorkers.push_back( std::thread( [ this, toFill ]()
{
SHAPE_POLY_SET rawPolys, finalPolys;
ZONE_SEGMENT_FILL segFill;
fillSingleZone( toFill[i].m_zone, rawPolys, finalPolys );
size_t i = m_next.fetch_add( 1 );
while( i < toFill.size() )
{
SHAPE_POLY_SET rawPolys, finalPolys;
ZONE_SEGMENT_FILL segFill;
fillSingleZone( toFill[i].m_zone, rawPolys, finalPolys );
toFill[i].m_zone->SetRawPolysList( rawPolys );
toFill[i].m_zone->SetFilledPolysList( finalPolys );
toFill[i].m_zone->SetIsFilled( true );
toFill[i].m_zone->SetRawPolysList( rawPolys );
toFill[i].m_zone->SetFilledPolysList( finalPolys );
toFill[i].m_zone->SetIsFilled( true );
if( m_progressReporter )
m_progressReporter->AdvanceProgress();
if( m_progressReporter )
m_progressReporter->AdvanceProgress();
m_count_done.fetch_add( 1 );
}
} );
m_count_done.fetch_add( 1 );
i = m_next.fetch_add( 1 );
}
} ) );
}
while( m_count_done.load() < toFill.size() )
{
@ -143,7 +153,8 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
wxMilliSleep( 20 );
}
fillWorker.join();
for( size_t ii = 0; ii < fillWorkers.size(); ++ii )
fillWorkers[ ii ].join();
// Now remove insulated copper islands
if( m_progressReporter )
@ -176,19 +187,27 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
m_progressReporter->SetMaxProgress( toFill.size() );
}
m_next = 0;
m_count_done = 0;
std::thread triangulationWorker( [ this, toFill ]()
std::vector<std::thread> triangulationWorkers;
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
{
for( unsigned i = 0; i < toFill.size(); i++ )
triangulationWorkers.push_back( std::thread( [ this, toFill ]()
{
if( m_progressReporter )
m_progressReporter->AdvanceProgress();
size_t i = m_next.fetch_add( 1 );
while( i < toFill.size() )
{
if( m_progressReporter )
m_progressReporter->AdvanceProgress();
toFill[i].m_zone->CacheTriangulation();
toFill[i].m_zone->CacheTriangulation();
m_count_done.fetch_add( 1 );
}
} );
m_count_done.fetch_add( 1 );
i = m_next.fetch_add( 1 );
}
} ) );
}
while( m_count_done.load() < toFill.size() )
{
@ -198,7 +217,8 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
wxMilliSleep( 10 );
}
triangulationWorker.join();
for( size_t ii = 0; ii < triangulationWorkers.size(); ++ii )
triangulationWorkers[ ii ].join();
// If some zones must be filled by segments, create the filling segments
// (note, this is a outdated option, but it exists)
@ -219,7 +239,7 @@ void ZONE_FILLER::Fill( std::vector<ZONE_CONTAINER*> aZones )
m_progressReporter->SetMaxProgress( zones_to_fill_count );
}
// TODO: use OPENMP to speedup calculations:
// TODO: use thread pool to speedup calculations:
for( unsigned i = 0; i < toFill.size(); i++ )
{
ZONE_CONTAINER* zone = toFill[i].m_zone;

View File

@ -119,6 +119,10 @@ private:
BOARD* m_board;
COMMIT* m_commit;
PROGRESS_REPORTER* m_progressReporter;
std::atomic_size_t m_next; // An index into the vector of zones to fill.
// Used by the variuos parallel thread sets during
// fill operations.
std::atomic_size_t m_count_done;
};