c++ - Parallel STXXL Vector Initialization -
the following minimal example illustrates behaviour of stxxl when initializing containers in parallel (using openmp):
#include <omp.h> #include <stdio.h> #include <stxxl.h> typedef stxxl::vector_generator<float>::result vec_t; int main(int argc, char* argv[]) { const unsigned long num = 8; #pragma omp parallel num_threads(num) { vec_t v; printf("%d\t%p\n", omp_get_thread_num(), &v); } return exit_success; }
running either
[stxxl-error] file large
or
[system-error]segmentation fault
how can allocate stxxl containers in multiple threads ?
the initialization of stxxl containers isn't thread-safe, therefore mutual exclusion thread initializing container needed. using openmp, read follows:
#include <omp.h> #include <stdio.h> #include <stxxl.h> typedef stxxl::vector_generator<float>::result vec_t; int main(int argc, char* argv[]) { const unsigned long num = 8; #pragma omp parallel num_threads(num) { vec_t* v; #pragma omp critical { v = new vec_t(); } printf("%d\t%p\n", omp_get_thread_num(), &v); delete v; } return exit_success; }
Comments
Post a Comment