Blaze 3.9
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:

// ... Resizing and initialization
C = serial( A + B );
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812

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:

// ... 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
// ...
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223
#define BLAZE_SERIAL_SECTION
Section to enforce the serial execution of operations.
Definition: SerialSection.h:262
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
constexpr bool columnVector
Transpose flag for column vectors.
Definition: TransposeFlag.h:58

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:

#define BLAZE_USE_SHARED_MEMORY_PARALLELIZATION 1

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