c++ - PPL: Initialization of the thread pool -


is there standard way pre-initialize ppl thread pool? problem is: ppl creates thread pool @ runtime when e.g. parallel_for() executing. costs little performance during first run, due creation of additional threads.

for clarification of problem, here example:

#pragma once  #include <vector> #include <ppl.h>  using namespace std; using namespace concurrency;  // use define experiments. #define ppl_init_method 2  int main() { #if (ppl_init_method == 0)    // experiment 1: initialize default scheduler    currentscheduler::create(schedulerpolicy());   // after call 1 additional thread 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 call 1 additional thread 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 call 12 threads created , ready more work!  #endif    // real work now!!!    return 0; } 

you can initialize ppl threadpool calls concurrency::scheduler::create in concrt.h.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -