Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

parallel_for Missing ')' Before '{'

Tux__the_Linux_Pengu
207 Views

Hello peoples!

So I have what seems (from my point of view) to be a perfectly fine nested group of parallel_fors:

[cpp]parallel_for(primes.begin(), (primes.end()) - 2, 
	{
		if((primes.size()) < 3) return;
		parallel_for(MINEXP, j + 1, [=](int expo)
		{
			i = 3*(primes.front())+3;
			pow((double)i, 1/expo);
			if(!((i%1)<1)) fout << "Sum of " << primes.front() << ":" << (primes.front()) + 3 << " = " << i << "^" << expo << "\n";
		});
	});[/cpp]

Yet, I'm getting all sorts of errors:

[bash]1>------ Build started: Project: primeExp, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\program files\intel\tbb\tbb30_196oss\include\tbb\_tbb_windef.h(60): warning : Recommend using /MD if compiling with TBB_USE_DEBUG==0
1>c:\users\\documents\visual studio 2010\projects\primeexp\primeexp\main.cpp(49): error C2143: syntax error : missing ')' before '{'
1>c:\users\\documents\visual studio 2010\projects\primeexp\primeexp\main.cpp(49): error C2059: syntax error : ')'
1>c:\users\\documents\visual studio 2010\projects\primeexp\primeexp\main.cpp(49): error C2143: syntax error : missing ';' before '{'
1>c:\users\\documents\visual studio 2010\projects\primeexp\primeexp\main.cpp(49): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 [/bash]
I think the first error is causing the rest. Am I doing something wrong?

Thanks!

0 Kudos
1 Solution
ARCH_R_Intel
Employee
207 Views

A C++0x enabled compiler should reject the code. The problem is the third argument to the outer parallel_for is a brace-deliminted block of code. That's not alowed even in C++0x. I'm guessing that you meant to have a lambda expression there.

Also, the three-argument form of parallel_for expects arguments of integral type for the first two arguments. So either use the initial and one-past-last subscript for the first two arguments, or consider using tbb::parallel_for_each, which acts similarly to std::for_each, but with parallel semantics.

View solution in original post

4 Replies
Kirill_R_Intel
Employee
207 Views

This error appears because C++0x support is not enabled in compiler. In Intel compliler this option is"/Qstd=c++0x" in windows or "-std=c++0x" in Linux.
If you use Visual Studio, go to project properties->C++->Language->Intel specific->Enable C++0x support and set "Yes".

Regards,
Kirill

Tux__the_Linux_Pengu
207 Views
Thanks Kirill! I guess my code is OK then.
ARCH_R_Intel
Employee
208 Views

A C++0x enabled compiler should reject the code. The problem is the third argument to the outer parallel_for is a brace-deliminted block of code. That's not alowed even in C++0x. I'm guessing that you meant to have a lambda expression there.

Also, the three-argument form of parallel_for expects arguments of integral type for the first two arguments. So either use the initial and one-past-last subscript for the first two arguments, or consider using tbb::parallel_for_each, which acts similarly to std::for_each, but with parallel semantics.

Tux__the_Linux_Pengu
207 Views
It turned out Idid need a lambda in the outer parallel_for for indexing the vector. Thanks everyone!
Reply