Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
17060 Discussions

Some bugs in cilkplus-gcc

Niklas_B_
Beginner
788 Views

Hello,

I'm using the cilkplus GCC extensions and ran into a few smallish bugs. All of them are reproducible with the most recent cilkplus-gcc 'gcc version 4.9.0 20130520 (experimental) (GCC)'

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr0/home/nbaumstark/cilkplus-install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/nbaumstark/cilkplus-gcc/configure --prefix=/home/nbaumstark/cilkplus-install --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 4.9.0 20130520 (experimental) (GCC)

1. cilk_for pollutes local namespace in template functions. I think I saw a report of this one somewhere, but can't find it anymore and it's not been fixed:

template <typename T>
void test() {
  int test = 0;
  cilk_for (int i = 0; i < 10; ++i) test += i;
  cilk_for (int i = 0; i < 10; ++i) test += i;
}

int main() {
  test<int>();
}

Output:

$ g++ -lcilkrts -fcilkplus -mcx16 -O2 -Wall loop-var-pollution.cpp
loop-var-pollution.cpp: In instantiation of ‘void test() [with T = int]’:
loop-var-pollution.cpp:9:13:   required from here
loop-var-pollution.cpp:5:17: error: redeclaration of ‘int i’
   cilk_for (int i = 0; i < 10; ++i) test += i;
                 ^
loop-var-pollution.cpp:4:17: error: ‘int i’ previously declared here
   cilk_for (int i = 0; i < 10; ++i) test += i;
                 ^

2. unused variable warnings for variables that are used in a cilk_for header:

// compile with -Wall
void test() {
  int len = 10;
  int test = 0;
  cilk_for (int i = 0; i < len; ++i) test += i;
}

int main() {
  test();
}

Output:

$ g++ -lcilkrts -fcilkplus -mcx16 -O2 -Wall loop-var-unused.cpp
loop-var-unused.cpp: In function ‘void test()’:
loop-var-unused.cpp:3:7: warning: variable ‘len’ set but not used [-Wunused-but-set-variable]
   int len = 10;

3. Type errors with -std=c++11 and cilk_spawn with a method of the current instance:

// compile with -Wall -std=c++11
template <typename T>
struct X {
  int test;
  X() : test(0) {}
  void foo() { test++; }
  void bar() {
    cilk_spawn foo();
    foo();
    cilk_sync;
  }
};

int main() {
  X<int>().bar();
}

Output:

$ g++ -lcilkrts -fcilkplus -mcx16 -O2 -Wall -std=c++11 this-method-spawn.cpp
this-method-spawn.cpp: In instantiation of ‘void X<T>::bar() [with T = int]’:
this-method-spawn.cpp:15:16:   required from here
this-method-spawn.cpp:8:20: error: cannot convert ‘X<T>::foo<int>’ from type ‘void (X<int>::)()’ to type ‘void (X<int>::*)()’
     cilk_spawn foo();
                    ^
this-method-spawn.cpp:8:20: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘_cilk_lmda_fn_var_000000 (...)’, e.g. ‘(... ->* _cilk_lmda_fn_var_000000) (...)’
cc1plus: warning: unused variable ‘sf_02’ [-Wunused-variable]

4. Warning about unused variable "sf_*". See example above. With -std=c++03, the error doesn't occur, but the warning does.

The source code is attached as a tarball.

Best regards,

Niklas Baumstark

0 Kudos
4 Replies
TimP
Honored Contributor III
788 Views

Maybe you should try building the current gcc source e.g. svn co svn://gcc.gnu.org/svn/gcc/trunk

and file any problem reports on gcc bugzilla; you could mention the pr numbers here.

I'll have to confess I have little personal interest in the many lto cases which fail their standard testsuite.

I'll try your cases later, if I can figure out easily how to run.  gcc cilkplus doesn't seem well enough documented to me.

I must deal with the snow now.

0 Kudos
Niklas_B_
Beginner
788 Views

Hi,

okay, problems 3 and 4 seem to be fixed in GCC trunk, nevermind. Actually a workaround for 3 in cilkplus-gcc is to add an explicit this:

cilk_spawn this->foo()

cilkplus-gcc might be badly documented, but GCC trunk seems to only partially implement cilkplus as of this date, if I'm not mistaken. For example, cilk_for seems to be implemented, so I can't try to reproduce problems 1 and 2. Does anyone have any knowledge of the status of GCC trunk w.r.t cilk? In particular, is the performance comparable to other cilk implementations? And is there a trick to work around the absence of the cilk_for keyword to use parallel for loops?

Best, Niklas

0 Kudos
Balaji_I_Intel
Employee
788 Views

Hi Niklas,

     _Cilk_for is not merged into the trunk yet. It is currently under review by the GCC reviewers. It is a different implementation and I am hoping that you problems outlined in 1 and 2 should disappear when it gets into trunk.

 

Thanks,


Balaji V. Iyer.

0 Kudos
Niklas_B_
Beginner
788 Views

Okay, that sounds reasonable. Since there are workarounds for all issues, I'm going to stick with cilkplus-gcc until _Cilk_for is merged into the GCC trunk.

Thanks guys!

0 Kudos
Reply