Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]Problem with parallel for #31

Closed
cdelv opened this issue Jan 18, 2022 · 3 comments
Closed

[BUG]Problem with parallel for #31

cdelv opened this issue Jan 18, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@cdelv
Copy link

cdelv commented Jan 18, 2022

Describe the bug

I found about this library and I think it's great. I was reading the article and trying out the examples and the example with the parallel loop failed to compile.

Minimal working example

first I tried this code

thread_pool pool(10);
size_t squares[100];
double a=1;
pool.parallelize_loop(0, 99, [&squares, &a](size_t i) { squares[i] = i * i* a; });

and got the compiler error

In file included from pool.cpp:1:
thread-pool/thread_pool.hpp: In instantiation of ‘void thread_pool::parallelize_loop(const T1&, const T2&, const F&, thread_pool::ui32) [with T1 = int; T2 = int; F = main()::<lambda(size_t)>; thread_pool::ui32 = long unsigned int]’:
pool.cpp:7:24:   required from here
thread-pool/thread_pool.hpp:155:31: error: no match for call to ‘(const main()::<lambda(size_t)>) (const T&, const T&)’
  155 |                           loop(start, end);
      |                           ~~~~^~~~~~~~~~~~
pool.cpp:7:32: note: candidate: ‘main()::<lambda(size_t)>’
    7 |   pool.parallelize_loop(0, 99, [&squares, &a](size_t i) { squares[i] = i * i* a; });
      |                                ^
pool.cpp:7:32: note:   candidate expects 1 argument, 2 provided

Then, I tried the example on the paper

#include "thread_pool.hpp"
int main()
{
  thread_pool pool(10);
  size_t squares[100];
  pool.parallelize_loop(0, 99, [&squares](size_t i) { squares[i] = i * i; });
  std::cout << "16ˆ2 = " << squares[16] << '\n';
  std::cout << "32ˆ2 = " << squares[32] << '\n';
}

And got a similar error

In file included from pool.cpp:1:
thread-pool/thread_pool.hpp: In instantiation of ‘void thread_pool::parallelize_loop(const T1&, const T2&, const F&, thread_pool::ui32) [with T1 = int; T2 = int; F = main()::<lambda(size_t)>; thread_pool::ui32 = long unsigned int]’:
pool.cpp:6:24:   required from here
thread-pool/thread_pool.hpp:155:31: error: no match for call to ‘(const main()::<lambda(size_t)>) (const T&, const T&)’
  155 |                           loop(start, end);
      |                           ~~~~^~~~~~~~~~~~
pool.cpp:6:32: note: candidate: ‘main()::<lambda(size_t)>’
    6 |   pool.parallelize_loop(0, 99, [&squares](size_t i) { squares[i] = i * i; });
      |                                ^
pool.cpp:6:32: note:   candidate expects 1 argument, 2 provided

I compiled with the command

g++ -pthread -std=c++17 pool.cpp

System information

  • CPU model, architecture, # of cores and threads: intel core i5 11th gen, 8 cores.
  • Operating system: Pop os 20.10
  • Name and version of C++ compiler: GCC 11.2.0
  • Full command used for compiling, including all compiler flags: -pthread -std=c++17 pool.cpp
  • Thread pool library version: cloned from mater branch on January 18.
@cdelv cdelv added the bug Something isn't working label Jan 18, 2022
@bshoshany
Copy link
Owner

Starting with v2.0.0, parallelize_loop() takes a function with two arguments, the start and end indices of the block. Please see the documentation for more information. The arXiv paper is old, the documentation on GitHub is the one you should go by (I'll probably update the arXiv paper in the next release).

@cdelv
Copy link
Author

cdelv commented Jan 18, 2022

Ok, thanks. You should put a warning on the Readme. Keep up the good work.

@bshoshany
Copy link
Owner

Update: v3.0.0 will be released in the next few days. With this release, the arXiv paper will be updated as well. I have also included a warning in README.md that the paper is updated less frequently than the documentation on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants