부스트 : 장벽에 성능 문제가 있습니다. 대기 메서드 호출의 시간을 측정합니다. 단일 스레드 상황에서는 대기 호출이 약 100,000 반복 될 때 약 0.5 초가 걸립니다. 불행히도이 스레드를 시나리오에 대한이 시간을 3 초로 확장하고 모든 스레드 (나는 8 코어 프로세서)가 더 악화되고있다.부스트 :: 배리어의 낮은 성능, 대기 동작
나는 동일한 기능을 제공하는 책임이있는 사용자 지정 방법을 구현했으며 훨씬 더 빠릅니다.
이 방법에서는 너무 느리게 작동합니다. 부스트에서 스레드를 동기화하는 더 빠른 방법이 있습니까 (모든 스레드가 모든 스레드에 의해 현재 작업이 완료 될 때까지 기다린 후 다음 작업으로 넘어 가고, 동기화 만하면 데이터 전송이 필요하지 않습니다).
현재 코드를 요청 받았습니다. 내가 달성하고자하는 것. 루프에서 함수를 실행하면이 함수를 많은 스레드로 나눌 수 있지만 모든 스레드는 다른 루프가 실행되기 전에 실행되는 현재 루프를 완료해야합니다.
내 현재 솔루션
volatile int barrierCounter1 =0; //it will store number of threads which completed current loop run
volatile bool barrierThread1[NumberOfThreads]; //it will store go signal for all threads with id > 0. All values are set to false at the beginning
boost::mutex mutexSetBarrierCounter; //mutex for barrierCounter1 modification
void ProcessT(int threadId)
{
do
{
DoWork(); //function which should be executed by every thread
mutexSetBarrierCounter.lock();
barrierCounter1++; //every thread notifies that it finish execution of function
mutexSetBarrierCounter.unlock();
if(threadId == 0)
{
//main thread (0) awaits for completion of all threads
while(barrierCounter1!=NumberOfThreads)
{
//I assume that the number of threads is lower than the number of processor cores
//so this loop should not have an impact of overall performance
}
//if all threads completed, notify other thread that they can proceed to the consecutive loop
for(int i = 0; i<NumberOfThreads; i++)
{
barrierThread1[i] = true;
}
//clear counter, no lock is utilized because rest of threads await in else loop
barrierCounter1 = 0;
}
else
{
//rest of threads await for "go" signal
while(barrierThread1[i]==false)
{
}
//if thread is allowed to proceed then it should only clean up its barrier thread array
//no lock is utilized because '0' thread would not modify this value until all threads complete loop run
barrierThread1[i] = false;
}
}
while(!end)
}
"동일한 기능을 제공하는 책임이있는 사용자 지정 메서드를 구현했으며 훨씬 더 빠릅니다"-이 정보를 보여 주면 왜 더 빠릅니까 (올바른지 여부도 설명 할 수 있음) – sehe