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

What does the Market class stand for?

qi1
Beginner
492 Views

Hi, can anyone tell me what does the market class in tbb30 source code stand for and what's the relation between it and arena?

Thanks a lot!

0 Kudos
4 Replies
Denis_Bolshakov
Beginner
493 Views
Declaration of the 'market' class is situated in ~\src\tbb\market.h
So this file is not in ~\include\tbb and you must not include this file to your sources.
Also this class is located in 'internal' namespace and you must not use this class in your sources.

Please include only public headers(files from ~\include\tbb) and uses only allowed classes(from tbb namespace only).
0 Kudos
qi1
Beginner
493 Views
Thank you for the reply!

Maybe I didn't propose my question clearly and now I clearify it again.

I'm reading the source code of TBB in order to understand the task splitting and task scheduling strategy it uses. So my problem is about the role of market class in TBB rather than how to include the header files in programming.

Thanks very much!
0 Kudos
Andrey_Marochko
New Contributor III
493 Views
Before TBB 3.0 arena was the place used by all threads that entered TBB scheduler's dispatch loop to share the work between them. (A thread enters dispatch loop when it executes one of the TBB parallel algorithms or one of the wait_for_all methods).

In particular when an application had several threads of its own all doing TBB work (such threads are called masters in TBB parlance), all these masters published their tasks (by spawning them) in the same arena. Thus the workload logically belonging to a particular master thread became available for execution not only to the workers from TBB's internal thread pool, but to other masters as well.

Though such total work sharing maximizes the efficiency of the load balancing, with time it became evident that it has several substantial drawbacks. The most serious one affects composability of TBB based solutions (and composability is one of the strong sides of TBB). Sometimes a master thread is expected by the programmer to finish its parallel work inside a limited timeframe (making sure that the workload is not too large). But when another master with much bigger workloads is running concurrently, it may happen that the first one steals a fat piece of the second one's work, and remains busy for substantially longer time processing it. In extreme cases it may happen that a master may gets trapped indefinitely long (e.g. when another master implements server style logic with endless supply of requests to process).

Another shortcoming of having a single arena is the fact the first master thread that initializes TBB scheduler defines the size of TBB thread pool for all master threads that join later. Often it is all right, but sometimes a master thread runs an algorithm that scales well only up to a particular concurrency level (say 4). When such app runs on a 16 core machine poor scalability of this algorithm may result in significant overhead for the whole system (by inefficient usage of all available hardware).

Therefore starting from TBB 3.0 when a master thread initializes TBB scheduler, it gets an arena of its own. Thus masters are now isolated from each other, which solves both issues described above.

And coming back to your original question, market is a new object in TBB scheduler that keeps track of active arenas, and (re)assigns TBB workers to them, trying to maintain fair workers distribution between masters.

0 Kudos
qi1
Beginner
493 Views
Thank you very much for your detailed reply.
0 Kudos
Reply