Problems with parallel_for

Problems with parallel_for

Bild des Benutzers brtaylor92

I'm trying to learn how to use the parallel_for() function described in this link. . To do so, I wrote a simple program that prints "Hello World!" to the terminal 5 times using a loop. It looks like:

#include
#include "tbb/parallel_for.h"
#include "tbb/blocked_range.h"

using namespace tbb;

struct Hello {
void operator() ( const blocked_range& range ) const {
for (int i=range.begin(); i!=range.end(); i++)
std::cout << "Hello World!" << std::endl;
}
};

int main ()
{
int i=0;
Hello hi;
parallel_for( blocked_range(0, i, 5), hi);
return 0;
}


When I compile it with icpc hello.cpp I get:

Undefined symbols for architecture x86_64:
"__ZNK3tbb8internal32allocate_root_with_context_proxy4freeERNS_4taskE", referenced from:
__ZdlPvRKN3tbb8internal32allocate_root_with_context_proxyE in icpcFImXZe.o
"__ZNK3tbb8internal27allocate_continuation_proxy8allocateEm", referenced from:
__ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_ in icpcFImXZe.o
"__ZNK3tbb8internal20allocate_child_proxy8allocateEm", referenced from:
__ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_ in icpcFImXZe.o
"__ZNK3tbb18task_group_context28is_group_execution_cancelledEv", referenced from:
__ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_ in icpcFImXZe.o
"__ZNK3tbb8internal27allocate_continuation_proxy4freeERNS_4taskE", referenced from:
__ZdlPvRKN3tbb8internal27allocate_continuation_proxyE in icpcFImXZe.o
"__ZNK3tbb8internal20allocate_child_proxy4freeERNS_4taskE", referenced from:
__ZdlPvRKN3tbb8internal20allocate_child_proxyE in icpcFImXZe.o
"__ZN3tbb4task13note_affinityEt", referenced from:
__ZTVN3tbb10interface68internal9flag_taskE in icpcFImXZe.o
__ZTVN3tbb10interface68internal11signal_taskE in icpcFImXZe.o
"__ZTIN3tbb4taskE", referenced from:
__ZTIN3tbb10interface68internal9flag_taskE in icpcFImXZe.o
__ZTIN3tbb10interface68internal11signal_taskE in icpcFImXZe.o
__ZTIN3tbb10interface68internal9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEE in icpcFImXZe.o
ld: symbol(s) not found for architecture x86_64
Or, on another system (gentoo rather than OS X),

/tmp/icpcFDqPZs.o: In function `operator delete(void*, tbb::internal::allocate_root_with_context_proxy const&)':
hello.cpp:(.text._ZdlPvRKN3tbb8internal32allocate_root_with_context_proxyE[.text._ZdlPvRKN3tbb8internal32allocate_root_with_context_proxyE]+0xb): undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const'
/tmp/icpcFDqPZs.o: In function `.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_':
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x1be): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x1f0): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x2c1): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x3a8): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x3e3): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x4cb): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x502): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x5ac): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
hello.cpp:(.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_[.text._ZN3tbb10interface68internal19partition_type_baseINS1_19auto_partition_typeEE7executeINS1_9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEES8_EEvRT_RT0_]+0x5e7): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const'
/tmp/icpcFDqPZs.o: In function `operator delete(void*, tbb::internal::allocate_continuation_proxy const&)':
hello.cpp:(.text._ZdlPvRKN3tbb8internal27allocate_continuation_proxyE[.text._ZdlPvRKN3tbb8internal27allocate_continuation_proxyE]+0xb): undefined reference to `tbb::internal::allocate_continuation_proxy::free(tbb::task&) const'
/tmp/icpcFDqPZs.o: In function `operator delete(void*, tbb::internal::allocate_child_proxy const&)':
hello.cpp:(.text._ZdlPvRKN3tbb8internal20allocate_child_proxyE[.text._ZdlPvRKN3tbb8internal20allocate_child_proxyE]+0xb): undefined reference to `tbb::internal::allocate_child_proxy::free(tbb::task&) const'
/tmp/icpcFDqPZs.o:(.data._ZTVN3tbb10interface68internal9flag_taskE[_ZTVN3tbb10interface68internal9flag_taskE]+0x28): undefined reference to `tbb::task::note_affinity(unsigned short)'
/tmp/icpcFDqPZs.o:(.data._ZTIN3tbb10interface68internal9flag_taskE[_ZTIN3tbb10interface68internal9flag_taskE]+0x10): undefined reference to `typeinfo for tbb::task'
/tmp/icpcFDqPZs.o:(.data._ZTVN3tbb10interface68internal11signal_taskE[_ZTVN3tbb10interface68internal11signal_taskE]+0x28): undefined reference to `tbb::task::note_affinity(unsigned short)'
/tmp/icpcFDqPZs.o:(.data._ZTIN3tbb10interface68internal11signal_taskE[_ZTIN3tbb10interface68internal11signal_taskE]+0x10): undefined reference to `typeinfo for tbb::task'
/tmp/icpcFDqPZs.o:(.data._ZTIN3tbb10interface68internal9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEE[_ZTIN3tbb10interface68internal9start_forINS_13blocked_rangeIiEE5HelloNS_16auto_partitionerEEE]+0x10): undefined reference to `typeinfo for tbb::task'
Can someone help me figure out what might be causing this? I've got a much more complex piece of code in which I could really use a parallel_for, but unless I can get it working, it appears I'm out of luck. Thanks, --brtaylor92

3 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Vladimir Polin (Intel)
Best Reply

hibrtaylor92,
did you add -ltbb to compile/link command line?
--Vladimir

Bild des Benutzers brtaylor92

I feel somewhat silly for not thinking of that, but I hadn't. There are no errors now, but the program also doesn't display any output. Assuming I'm reading my own code correctly, shouldn't it print 5 lines worth of "Hello, world" ? Edit: So after re-reading the tutorial, I was mis-using blocked range. Now that I've fixed that, the code works as intended.

Melden Sie sich an, um einen Kommentar zu hinterlassen.