function test() result(ierr)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, DECORATE, ALIAS : "test" :: test
implicit none
integer, parameter :: n=5
integer :: ierr
double precision :: a(n,n), b(n,n)
data b/ &
 888876.139,  241042.689, 379026.497, 708055.682,  304098.429, &
 241042.689,  404267.463, 206056.338, 157651.722,  195484.897, &
 379026.497,  206056.338, 1375198.33, 433616.172,  262428.682, &
 708055.682,  157651.722, 433616.172, 978938.998,  355444.468, &
 304098.429,  195484.897, 262428.682, 355444.468,  467836.098 /

a=b
call mkl_disable_fast_mm() 
call dpotrf('U', n, a, n, ierr)
if(ierr /= 0) print*,'Error'
!call dpotri('U', n, a, n, ierr)
!if(ierr /= 0) return
write(*,'(a)') 'OK'
    
end function

integer(DWORD) function DllMain (hInstDLL, fdwReason, lpvReserved)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, DECORATE, ALIAS:"DllMain" :: DllMain
use IFWIN
integer(HANDLE), intent(IN) :: hinstDLL
integer(DWORD), intent(IN) :: fdwReason
integer(LPVOID), intent(IN) :: lpvReserved
!write (*,'(/2(A, G0))') "DllMain: fdwReason=",fdwReason, ', lpvReserved=',lpvReserved
select case (fdwReason)
case (0)
    if (lpvReserved==0) then
        call mkl_thread_free_buffers() 
        call mkl_free_buffers() 
        call MKLFreeTls(fdwReason)
        call mkl_finalize()
    endif
case default
end select
DllMain = 1
return
end

