Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

TBB with C-Code

peterd86
Beginner
812 Views

Hello,

can i use TBB for the parallelization of real unamanged C-Code. or it works only with C++-Code?

Thanks.

Greetings, Peter

0 Kudos
10 Replies
robert-reed
Valued Contributor II
812 Views

Threading Building Blocks is a C++ library, and relies on many features of the language for its implementation. You'll need a C++ program to take advantage of the features of TBB. You might be able to embed chunks of C code into a C++ program using TBB just as you can otherwise, but TBB organization relies on the class and template parameterization features of C++ among many other features and needs a C++ compiler to interpret the TBB header files.

0 Kudos
RafSchietekat
Valued Contributor III
812 Views
Robert, you're scaring away the customers! Is there any reason why applying TBB to an existing C program might be more work than applying it to a program already using C++ features?
0 Kudos
peterd86
Beginner
812 Views

so the result is that TBB can be only use with C++-Code and not with C-Code. right?`

hmmmm, i use TBB and OpenMP. I just want to know some sure information for my thesis. Intel writes that TBB works with C++. They dont write C/C++. So i think that it can have some problem with the paralleization with C++-Code.

If TBB is implemented in C++ and uses C++ stuff than it cant work with C.

Thereofore i want to ask here in the forum if i am right.

0 Kudos
RafSchietekat
Valued Contributor III
812 Views
TBB is very much C++: you will absolutely require a C++ compiler. C is a subset of C++ (except for some details): the C++ compiler will take your C program. You'll be replacing iteration statements with TBB classes (just as you would if you started with a C++ program): the parallelised version of your program will be a C++ program, and you'll need to know how to use C++.

"If TBB is implemented in C++ and uses C++ stuff than it cant work with C." It will work with your C program. It won't work with your C compiler.

It is a toolkit (or framework?), and it will require some work from you to apply it, but C++ is a better C, and TBB is a better OpenMP (or so I hear). If you're happy with OpenMP and it easily gives your program close to 100% efficiency, don't change; otherwise, try TBB.

Is using a C++ compiler a bigger obstacle for you than using a C compiler with OpenMP support (for me it would be the other way around)?

0 Kudos
peterd86
Beginner
812 Views

hi,

thanks for you reply.

okay, now i understand it.

greetings, peter

0 Kudos
RafSchietekat
Valued Contributor III
812 Views
Then you have the advantage: may we know your situation (C++ compiler/knowledge), decision and motivation?

0 Kudos
peterd86
Beginner
812 Views

Hi,

i am computer since student and now i write my thesis. i have to create a migration concept for a software. the migration is from 32-bit singlecore to 64-bit and multicore architectures. i think that openmp and tbb are great tools for the parallelization of C/C++ (TBB only for C++ ;-) ) . so i can use TBB to parallelize C-Code but i have to use a C++-compiler. i have some requirements that in some cases is real ansi c-code required and so i cant use the tbb in this case. anyway, its possible to use tbb and openmp together for C++-Code.

i use the VS 2005 and VS 2008 compiler. as OS i use Windows XP and Vista in the 32-Bit and 64-Bit versions.

greetings, peter

0 Kudos
RafSchietekat
Valued Contributor III
812 Views
So I assume it's not a real-world requirement, to allow OpenMP but not C++? It might be interesting to see a summary of your conclusions after you have compared both approaches (but only if TBB comes out on top, of course).

0 Kudos
peterd86
Beginner
812 Views

its some requirements for the software. like data parallelism, portability, scalability,...

both are very good. and fullfill the requirements. only TBB hast the negative point, that its cant be used with ansi c and a c compiler

openmp can be also used only for c-code because it uses compielr directives.

0 Kudos
robert-reed
Valued Contributor II
812 Views

If were splitting hairs, OpenMP is not really ANSI C either. Its an orthogonal extension graphed into the syntax, hidden in comment statements for those C compilers that cant interpret it. But Peter, if youre using VS 2005 and VS 2008 compilers, its really hard to get C without also getting C++. < Is this restriction to ANSI C a thesis requirement? It seems very limiting, given the scope of the thesis.

You suggest some requirements that is some cases you must use ANSI C. If those requirements are to interface to low level C functions, like an instrument driver or some provided C library, you can still use C++ and just restrict the code at the point of the interface to be pure C. If thats the nature of your requirements, you still may be able to use C++ and TBB.

0 Kudos
Reply