Vector.BlockInit Method

Overload List

#SignatureDescription
1procedure BlockInit;Initializes block processing.
2procedure BlockInit(const Src: TDenseMtxVec);Initializes block processing.
3procedure BlockInit(const Src: TDenseMtxVec; ABlockSize: Integer);Initializes block processing.
4procedure BlockInit(ABlockSize: Integer);Initializes block processing.

Overload 1: procedure BlockInit;

Initializes block processing.

Result: stored in self (calling object)

Remarks:

Initializes block processing. Because the size of the CPU cache is limited, significant performance gains can be obtained by splitting long vectors in to a series of short ones, which can all fit in the CPU cache entirely. The BlockInit method is to be used together with Vector.BlockNext and methods to initialize a block processing while loop. BlockInit will call to obtain subrange of the data in TVec. The Vector.Length of the subranged vector is determined by the global Math387.MtxVecBlockSize variable declared in unit. Default value of MtxVecBlockSize is preset to 800 vector elements for double precision and 1600 elements for single precision. BlockInit supports nested calls and from witihin a blocked while loop you can call procedures and functions which are also blocked. If you use block processing, typical performance gains will range from 2 to a maximum of 6. Block processing can not be used, or it is difficult to apply, in cases where vector elements are not independent of each other. Block processing is a requirement, if threading is to be implemented. Without block processing, it is possible that multi-threading will not result in performance improvement regardless of core count, because the performance would be memory bandwidth limited.

The block processing while loop must be written like this:

a.BlockInit;
while not A.BlockEnd do
begin
  // .... user defined function
a.BlockNext.
end;
Examples
procedure ParetoPDF(const X: TVec; a, b: double; const Res: TVec); overload;
begin
    Res.Size(X);
    Res.Power(X,-(a+1));
    Res.Mul(Power(b,a)*a);;
end;
procedure ParetoPDF(const X: TVec; a, b: double; const Res: TVec); overload;
begin
    Res.Size(X);
    Res.BlockInit;
    X.BlockInit;
    while not X.BlockEnd do
    begin
        Res.Power(X,-(a+1));
        Res.Mul(Power(b,a)*a);
        Res.BlockNext;
        X.BlockNext;
    end;
end;
See Also: Vector.BlockNext, Vector.BlockEnd

Overload 2: procedure BlockInit(const Src: TDenseMtxVec);

Initializes block processing.

#NameTypeDescription
1SrcTDenseMtxVec

Result: stored in self (calling object)

Overload 3: procedure BlockInit(const Src: TDenseMtxVec; ABlockSize: Integer);

Initializes block processing.

#NameTypeDescription
1SrcTDenseMtxVec
2ABlockSizeInteger

Result: stored in self (calling object)

Remarks:

Block processing can be applied on possibly already subranged Src object. Src may not be freed or go out of scope until block processing loop has finished. There would be no error raised other than AV.

Overload 4: procedure BlockInit(ABlockSize: Integer);

Initializes block processing.

#NameTypeDescription
1ABlockSizeInteger

Result: stored in self (calling object)

Examples
a.BlockInit;
while not A.BlockEnd do
begin
    // .... user defined function
    a.BlockNext.
end;