|
I just figured: the problem with using log only occurs when
optimization options are turned on, i.e. when the compiler
vectorizes the loop containing the log statement.
The offending mex-file is reproduced below.
#include "fintrf.h"
subroutine mexfunction(nlhs, plhs, nrhs, prhs)
implicit none
interface
subroutine testmex(y,x)
real(8), dimension(:,:,:), intent(out) :: y
real(8), dimension(:,:,:), intent(in) :: x
end subroutine testmex
end interface
integer(4), intent(in) :: nlhs, nrhs
mwpointer, intent(in), dimension(*) :: prhs
mwpointer, dimension(*) :: plhs
mwpointer :: mxgetdimensions
mwpointer :: mxGetPr
mwpointer :: mxCreateNumericArray
integer(4) :: mxClassIDFromClassName
mwsize, dimension(3) :: dims
real(8), dimension(:,:,:), allocatable :: x,y
! Check for correct no. of input arguments
if(nrhs/=1) then
call mexErrMsgTxt('one input required.')
else if(nlhs/=1) then
call mexErrMsgTxt('one output required.')
endif
call mxcopyptrtointeger4(mxgetdimensions(prhs(1)),dims,3) !
assume, don't check that input is 3-D
if(dims(3)/=3) then
call mexErrMsgTxt('size of xall must be (ipg1 x ipg2 x 3)')
endif
allocate(x(dims(1),dims(2),3))
allocate(y(dims(1),dims(2),3))
! copy pointers (right-hand side arguments) to Fortran arrays
call mxCopyPtrToReal8(mxGetPr(prhs(1)),x,product(dims))
! create pointers to left-han side arguments
plhs(1) =
mxCreateNumericArray(3,dims,mxClassIDFromClassName('double'),0)
! call the computational routine.
call testmex(y,x)
! copy left-hand side argument to Matlab
call mxCopyReal8ToPtr(y,mxGetPr(plhs(1)),product(dims))
! free memory
deallocate(x,y)
end subroutine mexfunction
subroutine testmex(y,x)
implicit none
real(8), dimension(:,:,:), intent(in) :: x
real(8), dimension(:,:,:), intent(out) :: y
integer(4) :: i1,i2,i3
!$omp parallel do
do i1=1,size(x,1)
do i2=1,size(x,2)
do i3=1,size(x,3)
y(i1,i2,i3)=log(x(i1,i2,i3))
enddo
enddo
enddo
!$omp end parallel do
end subroutine testmex
|