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

Reducer in template function does not work (as expected) #175

Closed
ppete opened this issue Jul 3, 2023 · 1 comment
Closed

Reducer in template function does not work (as expected) #175

ppete opened this issue Jul 3, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@ppete
Copy link

ppete commented Jul 3, 2023

Describe the bug

When a reducer is used in templated code, its type seems to be void. Consequently, it is unclear how the reducer can be used (if it is even possible).

Expected behavior

Reducer in templates should behave like as if in non-templated code.

OpenCilk version

System information

  • OS: Ubuntu 22.04
  • CPU: Intel core 7

Steps to reproduce (include relevant output)

  1. install from .sh

  2. Version Info

clang version 14.0.6 (https://github.com/OpenCilk/opencilk-project fc90ded)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64

  1. Code does not compile

Working example code (simple.cc)

// clang version 14.0.6 (https://github.com/OpenCilk/opencilk-project fc90ded)
// Target: x86_64-unknown-linux-gnu
// Thread model: posix
// compile: clang++ -fopencilk -c simple.cc

#include <cilk/cilk.h>

void sum_init(void* sum) { static_cast<int>(sum) = 0.0; }
void sum_plus(void* lhs, void* rhs) { static_cast<int>(lhs) += static_cast<int>(rhs); }

int cilk_reducer(sum_init, sum_plus) reducer(0);

void plus(int oper) { reducer += oper; }

template
auto some_template_function() -> void
{
reducer += X; // fails
// plus(X); // work-around
}

int main()
{
some_template_function<1>();
}

Diagnostic output

warning: ISO C++ does not allow indirection on operand of type 'void *' [-Wvoid-ptr-dereference]
simple.cc:24:3: note: in instantiation of function template specialization 'some_template_function<1>' requested here
some_template_function<1>();
^
simple.cc:18:11: error: invalid operands to binary expression ('void' and 'int')
reducer += X; // fails
^ ~
1 warning and 1 error generated.

@ppete ppete added the bug Something isn't working label Jul 3, 2023
@VoxSciurorum
Copy link
Contributor

Some of the formatting got stripped out due to HTML processing, but I think I recovered your original program. This is a bug we have fixed in development sources but not in any release.

Do you know how to rebuild OpenCilk from source? The latest development code is branch dev/14.x in repository github.com/OpenCilk/opencilk-project.

@ppete ppete closed this as completed Jul 6, 2023
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