Developer Reference

  • 2020.2
  • 07/15/2020
  • Public Content
Contents

Usage Example
s
for the Memory Functions

Usage Example for 1-dimensional Arrays
PROGRAM FOO INCLUDE 'mkl.fi' DOUBLE PRECISION A,B,C POINTER (A_PTR,A(1)), (B_PTR,B(1)), (C_PTR,C(1)) INTEGER N, I REAL*8 ALPHA, BETA INTEGER*8 ALLOCATED_BYTES INTEGER*8 PEAK_MEMORY INTEGER*4 ALLOCATED_BUFFERS #ifdef _SYSTEM_BITS32 INTEGER*4 MKL_MALLOC, MKL_CALLOC, MKL_REALLOC INTEGER*4 ALLOC_SIZE, NUM, SIZE #else INTEGER*8 MKL_MALLOC, MKL_CALLOC, MKL_REALLOC INTEGER*8 ALLOC_SIZE, NUM, SIZE #endif EXTERNAL MKL_MALLOC, MKL_FREE, MKL_CALLOC, MKL_REALLOC ALPHA = 1.1; BETA = -1.2 N = 1000 SIZE = 8 NUM = N*N ALLOC_SIZE = SIZE*NUM PEAK_MEMORY = MKL_PEAK_MEM_USAGE(MKL_PEAK_MEM_ENABLE) A_PTR = MKL_MALLOC(ALLOC_SIZE,64) B_PTR = MKL_MALLOC(ALLOC_SIZE,64) C_PTR = MKL_CALLOC(NUM,SIZE,64) DO I=1,N*N A(I) = I B(I) = -I END DO CALL DGEMM('N','N',N,N,N,ALPHA,A,N,B,N,BETA,C,N); ALLOCATED_BYTES = MKL_MEM_STAT(ALLOCATED_BUFFERS) PRINT *,'DGEMM uses ',ALLOCATED_BYTES,' bytes in ', $ ALLOCATED_BUFFERS,' buffers ' CALL MKL_FREE_BUFFERS CALL MKL_FREE(A_PTR) CALL MKL_FREE(B_PTR) CALL MKL_FREE(C_PTR) ALLOCATED_BYTES = MKL_MEM_STAT(ALLOCATED_BUFFERS) IF (ALLOCATED_BYTES > 0) THEN PRINT *,'MKL MEMORY LEAK!' PRINT *,'AFTER MKL_FREE_BUFFERS there are ', $ ALLOCATED_BYTES,' bytes in ', $ ALLOCATED_BUFFERS,' buffers' END IF PEAK_MEMORY = MKL_PEAK_MEM_USAGE(MKL_PEAK_MEM_RESET) PRINT *,'Peak memory allocated by Intel MKL memory allocator ', $ PEAK_MEMORY,' bytes. ', $ 'Start to count new memory peak' A_PTR = MKL_MALLOC(ALLOC_SIZE,64) A_PTR = MKL_REALLOC(A_PTR,ALLOC_SIZE*SIZE) CALL MKL_FREE(A_PTR) PEAK_MEMORY = MKL_PEAK_MEM_USAGE(MKL_PEAK_MEM) PRINT *,'After reset of peak memory counter', $ 'Peak memory allocated by Intel MKL memory allocator ', $ PEAK_MEMORY,' bytes' STOP END
Usage Example for 2-dimensional Arrays
PROGRAM FOO INTEGER N PARAMETER (N=100) DOUBLE PRECISION A,B,C POINTER (A_PTR,A(N,*)), (B_PTR,B(N,*)), (C_PTR,C(N,*)) INTEGER I,J REAL*8 ALPHA, BETA INTEGER*8 ALLOCATED_BYTES INTEGER*4 ALLOCATED_BUFFERS #ifdef _SYSTEM_BITS32 INTEGER*4 MKL_MALLOC INTEGER*4 ALLOC_SIZE #else INTEGER*8 MKL_MALLOC INTEGER*8 ALLOC_SIZE #endif INTEGER MKL_MEM_STAT EXTERNAL MKL_MALLOC, MKL_FREE, MKL_MEM_STAT ALPHA = 1.1; BETA = -1.2 ALLOC_SIZE = 8*N*N A_PTR = MKL_MALLOC(ALLOC_SIZE,64) B_PTR = MKL_MALLOC(ALLOC_SIZE,64) C_PTR = MKL_MALLOC(ALLOC_SIZE,64) DO I=1,N DO J=1,N A(I,J) = I B(I,J) = -I C(I,J) = 0.0 END DO END DO CALL DGEMM('N','N',N,N,N,ALPHA,A,N,B,N,BETA,C,N); ALLOCATED_BYTES = MKL_MEM_STAT(ALLOCATED_BUFFERS) PRINT *,'DGEMM uses ',ALLOCATED_BYTES,' bytes in ', $ ALLOCATED_BUFFERS,' buffers ' CALL MKL_FREE_BUFFERS CALL MKL_FREE(A_PTR) CALL MKL_FREE(B_PTR) CALL MKL_FREE(C_PTR) ALLOCATED_BYTES = MKL_MEM_STAT(ALLOCATED_BUFFERS) IF (ALLOCATED_BYTES > 0) THEN PRINT *,'MKL MEMORY LEAK!' PRINT *,'AFTER MKL_FREE_BUFFERS there are ', $ ALLOCATED_BYTES,' bytes in ', $ ALLOCATED_BUFFERS,' buffers' END IF STOP END

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804