Stefano Tommesani

  • Increase font size
  • Default font size
  • Decrease font size

Multi-thread loops with Intel TBB

E-mail Print PDF

A new article about using Intel TBB is here. It contains examples using C++ lambdas and joining multi-threaded loops with SIMD code

In this article we will transform a plain C loop into a multi-threaded version using Intel Thread Building Blocks library (TBB).

Here is the loop to transform:

unsigned char *SrcImagePtr = (unsigned char *)SrcImage;
unsigned char *DstImagePtr = (unsigned char *)DstBuffer;
for (int i = (OriginalImageWidth * OriginalImageHeight); i > 0; i--)
int YValue = (SrcImagePtr[0] * FirstFactor ) +
(SrcImagePtr[1] * SecondFactor) +
(SrcImagePtr[2] * ThirdFactor );
SrcImagePtr += PixelOffset;
YValue += 1 << (SCALING_LOG - 1);
if (YValue > 255)
YValue = 255;
*DstImagePtr = (unsigned char)YValue;

This loops iterates over a three-channel image named SrcImage (usually a RGB one), and it computes the luma value for each pixel storing it into DstImage. As the computation of every pixel has no dependencies whatsoever on other pixel, it is very simple to separate this computation into multiple threads, each performing it on a different slice of the image.

Even if we could directly use threads for such a task, it is much simpler and faster to use an ad-hoc library such as Intel's Thread Building Blocks.


Last Updated on Wednesday, 01 May 2013 14:11

About Stefano Tommesani

E-mail Print PDF

ProfiloSmall15 years of experience in the CCTV area, including:

  • R&D
  • strategic planning and partnerships
  • pre-sales
  • HW / SW integration
  • QA

Broad software development experience, from flashy GUIs to down-to-the-metal assembly programming, and a performance-minded approach to development allow me to reach outstanding results in software products:

  • Design and implementation of security systems
  • Advanced video analysis for threat detection
  • Advanced image processing
  • Audio and video coding and compression
  • Network multi-protocol programming and remoting
  • System management and monitoring
  • Windows system programming
  • Code optimization, from high-level architectural design to multi-threading, low-level SIMD assembly coding and GPGPU
  • Detailed knowledge of SD best practices: OOD, Agile with Scrum, unit testing, TDD, IoC, AoP.

Programming languages: over 14 years of professional experience with C/C++, C#, Delphi, x86 assembler.





Last Updated on Saturday, 12 March 2016 16:12

Page 10 of 10
View Stefano Tommesani's profile on LinkedIn

Latest Articles

A software to stand out 27 January 2018, 14.35 Web
A software to stand out
Standing out of the pack starts by being visible, and being noticed by the right group of professionals. No matter how good your profile is, it is lost in a sea of similar profiles, so you need to show up and start attracting
Web page scraping, the easy way 07 January 2018, 00.46 Web
Web page scraping, the easy way
There are many ways to extract data elements from web pages, almost all of them prettier and cooler than the method proposed here, but as we are in an hurry, let's get that data quickly, ok? Suppose we have to extract the
Scraping dynamic page content 06 January 2018, 23.57 Web
Scraping dynamic page content
One of the most common roadblocks when scraping the content of web sites is getting the full contents of the page, including JS-generated data elements (probably, the ones you are looking for). So, when using CEFSharp to scrape
Unit-testing file I/O 26 November 2017, 12.09 Testing
Unit-testing file I/O
Two good news: file I/O is unit-testable, and it is surprisingly easy to do. Let's see how it works! A software no-one asked for First, we need a piece of software that deals with files and that has to be unit-tested. The
Fixing Git pull errors in SourceTree 10 April 2017, 01.44 Software
Fixing Git pull errors in SourceTree
If you encounter the following error when pulling a repository in SourceTree: VirtualAlloc pointer is null, Win32 error 487 it is due to to the Cygwin system failing to allocate a 5 MB large chunk of memory for its heap at