Clone wiki

blaze / Serial Execution

Sometimes it may be necessary to enforce the serial execution of specific operations. For this purpose, the Blaze library offers three possible options: the serialization of a single expression via the serial() function, the serialization of a block of expressions via the BLAZE_SERIAL_SECTION, and the general deactivation of the parallel execution.

Option 1: Serialization of a Single Expression

The first option is the serialization of a specific operation via the serial() function:

blaze::DynamicMatrix<double> A, B, C;
// ... Resizing and initialization
C = serial( A + B );

serial() enforces the serial evaluation of the enclosed expression. It can be used on any kind of dense or sparse vector or matrix expression.

Option 2: Serialization of Multiple Expressions

The second option is the temporary and local enforcement of a serial execution via the BLAZE_SERIAL_SECTION:

using blaze::rowMajor;
using blaze::columnVector;

blaze::DynamicMatrix<double,rowMajor> A;
blaze::DynamicVector<double,columnVector> b, c, d, x, y, z;

// ... Resizing and initialization

// Parallel execution
// If possible and beneficial for performance the following operation is executed in parallel.
x = A * b;

// Serial execution
// All operations executed within the serial section are guaranteed to be executed in
// serial (even if a parallel execution would be possible and/or beneficial).
   y = A * c;
   z = A * d;

// Parallel execution continued
// ...

Within the scope of the BLAZE_SERIAL_SECTION, all operations are guaranteed to run in serial. Outside the scope of the serial section, all operations are run in parallel (if beneficial for the performance).

Note that the BLAZE_SERIAL_SECTION must only be used within a single thread of execution. The use of the serial section within several concurrent threads will result undefined behavior!

Option 3: Deactivation of Parallel Execution

The third option is the general deactivation of the parallel execution (even in case OpenMP is enabled on the command line). This can be achieved via the BLAZE_USE_SHARED_MEMORY_PARALLELIZATION switch in the ./blaze/config/SMP.h configuration file:


In case the BLAZE_USE_SHARED_MEMORY_PARALLELIZATION switch is set to 0, the shared memory parallelization is deactivated altogether.

Previous: OpenMP Parallelization ---- Next: Serialization