1
PPL 스레드 풀을 미리 초기화하는 표준 방법이 있습니까? 문제는 다음과 같습니다. PPL은 런타임에 스레드 풀을 만듭니다. parallel_for()가 실행 중입니다. 추가 스레드 생성으로 인해 첫 번째 실행 중에 약간의 비용이 소요됩니다.PPL : 스레드 풀의 초기화
#pragma once
#include <vector>
#include <ppl.h>
using namespace std;
using namespace Concurrency;
// Use this define for experiments.
#define PPL_INIT_METHOD 2
int main()
{
#if (PPL_INIT_METHOD == 0) // experiment 1: initialize default scheduler
CurrentScheduler::Create(SchedulerPolicy());
// After this call only one additional thread is created
#elif (PPL_INIT_METHOD == 1) // experiment 2: initialize custom scheduler
SchedulerPolicy my_policy(3,
MinConcurrency, 12,
MaxConcurrency, 12,
ContextPriority, THREAD_PRIORITY_NORMAL);
Scheduler* my_scheduler = Scheduler::Create(my_policy);
// After this call only one additional thread is created
my_scheduler->Attach();
assert(my_scheduler->GetNumberOfVirtualProcessors() == 12);
// Still same number of threads (= 2)
// cleanup stuff ...
#else // experiment 3: execute dummy parallel_for()
std::vector<int> v(1024*1024, 42);
parallel_for(0u, v.size(), [&v](size_t i) { v[i] += 1; }, static_partitioner());
// After this call all 12 threads are created and ready for more work!
#endif
// Do real work now!!!
return 0;
}
아니요, 작동하지 않습니다. 나는 시도했다 : {SchedulerPolicy my_policy (3, MinConcurrency, 12, MaxConcurrency, 12, ContextPriority, THREAD_PRIORITY_NORMAL); 스케줄러 * my_scheduler = 스케줄러 :: 만들기 (my_policy); }. – mem64k
일단 스케쥴러를 만들면 현재 컨텍스트에 Attach()해야합니다. 그렇지 않으면 사용되지 않습니다. –