コードサンプル

以下の単純なサンプルプログラムは、インテル® MKL 関数の実行で一貫性のある結果を得る方法を示します。ほかのサンプルは、『インテル® MKL リファレンス・マニュアル』を参照してください。

CBWR の C サンプルプログラム

#include <mkl.h>
int main(void) {
    int my_cbwr_branch;
    /* Align all input/output data on 128-byte boundaries to get reproducible results of Intel MKL function calls */
    void *darray;
    int darray_size=1000;
    /* Set alignment value in bytes */
    int alignment=128;
    /* Allocate aligned array */
    darray = mkl_malloc (sizeof(double)*darray_size, alignment);
    /* Find the available MKL_CBWR_BRANCH automatically */
    my_cbwr_branch = mkl_cbwr_get_auto_branch();
    /* User code without Intel MKL calls */
    /* Piece of the code where CBWR of Intel MKL is needed */
    /* The performance of Intel MKL functions might be reduced for CBWR mode */
    if (mkl_cbwr_set(my_cbwr_branch)) {
        printf(“Error in setting MKL_CBWR_BRANCH! Aborting…\n”);
        return;
    }
    /* CBWR calls to Intel MKL + any other code with aligned input\output data */
    /* Free the allocated aligned array */
    mkl_free(darray);
}

CBWR の Fortran サンプルプログラム

    PROGRAM MAIN
    INCLUDE 'mkl.fi'
    INTEGER*4 MY_CBWR_BRANCH
! Align all input/output data on 128-byte boundaries to get reproducible results of Intel MKL function calls
! Declare Intel MKL memory allocation routine
#ifdef _IA32
    INTEGER MKL_MALLOC
#else
    INTEGER*8 MKL_MALLOC
#endif
    EXTERNAL MKL_MALLOC, MKL_FREE
    DOUBLE PRECISION DARRAY
    POINTER (P_DARRAY,DARRAY(1))
    INTEGER DARRAY_SIZE
    PARAMETER (DARRAY_SIZE=1000)
! Set alignment value in bytes
    INTEGER ALIGNMENT
    PARAMETER (ALIGNMENT=128)
! Allocate aligned array
    P_DARRAY = MKL_MALLOC (%VAL(8*DARRAY_SIZE), %VAL(ALIGNMENT));
! Find the available MKL_CBWR_BRANCH automatically
    MY_CBWR_BRANCH = MKL_CBWR_GET_AUTO_BRANCH()
! User code without Intel MKL calls
! Piece of the code where CBWR of Intel MKL is needed
! The performance of Intel MKL functions may be reduced for CBWR mode
    IF (MKL_CBWR_SET (MY_CBWR_BRANCH) .NE. MKL_CBWR_SUCCESS) THEN
        PRINT *, 'Error in setting MKL_CBWR_BRANCH! Aborting…'
        RETURN
    ENDIF
! CBWR calls to Intel MKL + any other code
! Free the allocated aligned array
    CALL MKL_FREE(P_DARRAY)

    END

このヘルプトピックについてのフィードバックを送信