Borrar filtros
Borrar filtros

Mex problems on 64bit machine

4 visualizaciones (últimos 30 días)
Adrianna
Adrianna el 10 de Ag. de 2011
Editada: Walter Roberson el 14 de Feb. de 2018
I have a code which creates a mex file fine on a 32 bit machine but it does not work correctly for a 64 bit machine. The code compiles without errors or warnings however when I run the code I get a segmentation fault.
Does anyone have a suggestion of how to fix this?
Here is the output from the crash.
------------------------------------------------------------------------
Segmentation violation detected at Wed Aug 10 15:12:08 2011
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Current Visual : 0x21 (class 4, depth 24)
Default Encoding: UTF-8
GNU C Library : 2.13 stable
MATLAB License : 207107
MATLAB Root : /usr/local/MATLAB/R2011a
MATLAB Version : 7.12.0.635 (R2011a)
Operating System: Linux 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64
Processor ID : x86 Family 6 Model 10 Stepping 7, GenuineIntel
Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11001000), display :0.0
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 30a3d42800007fd6 RBX = 0000000000000000
RCX = 00007fd630a456c0 RDX = 0000000000000000
RSP = 00007fd653276760 RBP = 00007fd653276760
RSI = 00007fd653276f40 RDI = 00007fd653277004
R8 = 00007fd62e970440 R9 = 00007fd663749400
R10 = 00007fd6532765d0 R11 = 00007fd65c61df50
R12 = 0000000000000002 R13 = 00007fd653277000
R14 = 00007fd62c0d4b40 R15 = 00007fd653276990
RIP = 00007fd663795847 EFL = 0000000000010246
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007fd663a48f49 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00474953 fl::sysdep::linux::unwind_stack(void const**, unsigned long, unsigned long, fl::diag::thread_context const&)+000009
[ 1] 0x00007fd6639fedc1 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00171457 fl::diag::stacktrace_base::capture(fl::diag::thread_context const&, unsigned long)+000161
[ 2] 0x00007fd663a080dd /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00209117
[ 3] 0x00007fd663a08364 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwfl.so+00209764 fl::diag::terminate_log(char const*, fl::diag::thread_context const&, bool)+000100
[ 4] 0x00007fd662a74be5 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00420837 fl::diag::terminate_log(char const*, ucontext const*, bool)+000085
[ 5] 0x00007fd662a71b54 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00408404
[ 6] 0x00007fd662a7303d /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00413757
[ 7] 0x00007fd662a73197 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00414103
[ 8] 0x00007fd662a73b1d /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00416541
[ 9] 0x00007fd662a74435 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00418869
[ 10] 0x00007fd6615cac60 /lib/x86_64-linux-gnu/libpthread.so.0+00064608
[ 11] 0x00007fd663795847 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmx.so+00292935 mxgetpr_+000007
[ 12] 0x00007fd625c1f9ea /home/adrianna/Research/mex_lowrank/id_decomp.mexa64+00002538 mexfunction_+000182
[ 13] 0x00007fd65c61dfbc /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmex.so+00049084 mexRunMexFile+000108
[ 14] 0x00007fd65c61af19 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmex.so+00036633
[ 15] 0x00007fd65c61bbbe /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmex.so+00039870
[ 16] 0x00007fd6627e97ef /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_dispatcher.so+00391151 Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)+000511
[ 17] 0x00007fd6620f01f0 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01532400
[ 18] 0x00007fd662091975 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01145205
[ 19] 0x00007fd6620ab96e /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01251694
[ 20] 0x00007fd6620b00ec /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01269996
[ 21] 0x00007fd6620adc7a /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01260666
[ 22] 0x00007fd6620ae741 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01263425
[ 23] 0x00007fd6621077d9 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01628121
[ 24] 0x00007fd6627e97ef /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_dispatcher.so+00391151 Mfh_file::dispatch_fh(int, mxArray_tag**, int, mxArray_tag**)+000511
[ 25] 0x00007fd6620e39b2 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01481138
[ 26] 0x00007fd6620a5e13 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01228307
[ 27] 0x00007fd6620a4eb7 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01224375
[ 28] 0x00007fd6620a5397 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwm_interpreter.so+01225623
[ 29] 0x00007fd662cb38fe /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwbridge.so+00108798
[ 30] 0x00007fd662cb44ae /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwbridge.so+00111790 mnParser+000622
[ 31] 0x00007fd662a5cd39 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00322873 mcrInstance::mnParser_on_interpreter_thread()+000041
[ 32] 0x00007fd662a3fdb2 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00204210
[ 33] 0x00007fd662a3fec0 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00204480
[ 34] 0x00007fd6593e1db6 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwuix.so+00437686
[ 35] 0x00007fd6593eb13d /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libmwuix.so+00475453
[ 36] 0x00007fd659e370bd /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libuij.so+00217277 sysq::during_F<boost::weak_ptr<sysq::ws_ppeHook>, boost::shared_ptr<sysq::ws_ppeHook> > std::for_each<__gnu_cxx::__normal_iterator<boost::weak_ptr<sysq::ws_ppeHook>*, std::vector<boost::weak_ptr<sysq::ws_ppeHook>, std::allocator<boost::weak_ptr<sysq::ws_ppeHook> > > >, sysq::during_F<boost::weak_ptr<sysq::ws_ppeHook>, boost::shared_ptr<sysq::ws_ppeHook> > >(__gnu_cxx::__normal_iterator<boost::weak_ptr<sysq::ws_ppeHook>*, std::vector<boost::weak_ptr<sysq::ws_ppeHook>, std::allocator<boost::weak_ptr<sysq::ws_ppeHook> > > >, __gnu_cxx::__normal_iterator<boost::weak_ptr<sysq::ws_ppeHook>*, std::vector<boost::weak_ptr<sysq::ws_ppeHook>, std::allocator<boost::weak_ptr<sysq::ws_ppeHook> > > >, sysq::during_F<boost::weak_ptr<sysq::ws_ppeHook>, boost::shared_ptr<sysq::ws_ppeHook> >)+000077
[ 37] 0x00007fd659e38989 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libuij.so+00223625
[ 38] 0x00007fd659e354ae /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/../../bin/glnxa64/libuij.so+00210094 svWS_ProcessPendingEvents(int, int, bool)+000494
[ 39] 0x00007fd662a3e1c7 /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00197063
[ 40] 0x00007fd662a3e60a /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00198154
[ 41] 0x00007fd662a3ed6f /usr/local/MATLAB/R2011a/bin/glnxa64/../../bin/glnxa64/libmwmcr.so+00200047
[ 42] 0x00007fd6615c1d8c /lib/x86_64-linux-gnu/libpthread.so.0+00028044
[ 43] 0x00007fd66130d04d /lib/x86_64-linux-gnu/libc.so.6+00942157 clone+000109
  1 comentario
Adrianna
Adrianna el 10 de Ag. de 2011
Editada: Walter Roberson el 14 de Feb. de 2018
Here is the code for the wrapper.
c#include "fintrf.h"
c [T,J,rnorms] = id_decomp(A,INPUT2)
c
c if 0 < INPUT2 < 1
c
c compute to a given accuracy
c
c acc = INPUT2
c
c else
c
c compute a fixed number of columns
c
c k = INPUT2
c
SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
IMPLICIT NONE
INTEGER PLHS(*), PRHS(*)
INTEGER NLHS, NRHS
INTEGER mxCreateDoubleMatrix,mxMalloc
INTEGER mxGetPr,mxGetM,mxGetN,mxIsComplex
INTEGER A_p, INPUT2_p, T_p, rnorms_p, indvec_p, indveci_p
INTEGER m, n, k, flag_fixed_k, flag_complex
REAL*8 INPUT2(1), acc
c Check that we have two inputs and two or three outputs
IF (NRHS .NE. 2) THEN
CALL mexErrMsgTxt('id_decomp requires two input arguments')
ELSEIF (NLHS .LT. 2) THEN
CALL mexErrMsgTxt('id_decomp requires 2 or 3 output arguments')
ELSEIF (NLHS .GT. 3) THEN
CALL mexErrMsgTxt('id_decomp requires 2 or 3 output arguments')
ENDIF
c Extract the problem dimensions from the first input argument.
m = MXGETM(PRHS(1))
n = MXGETN(PRHS(1))
c Assign a pointer to the second input argument.
INPUT2_p = MXGETPR(PRHS(2))
CALL mxCopyPtrToReal8(INPUT2_p,INPUT2,1)
c Check the nature of INPUT2:
c If INPUT2 < 1, then set acc = INPUT2 and use the "specified accuracy" version of id_idd.
c If INPUT2 >= 1, then set k = INPUT2 and use the "specified rank" version of id_idd.
IF (INPUT2(1) .LT. 1) THEN
flag_fixed_k = 0
k = min(m,n)
acc = INPUT2(1)
ELSE
flag_fixed_k = 1
k = min(int(INPUT2(1)), min(m,n))
END IF
c Check whether the input matrix A is complex.
flag_complex = mxIsComplex(PRHS(1))
IF (flag_complex .EQ. 1) THEN
CALL mexErrMsgTxt('id_decomp cannot yet handle complex input')
END IF
c Create the output matrix T and copy A onto T.
IF (flag_complex .EQ. 0) THEN
A_p = mxGetPr(PRHS(1))
PLHS(1) = mxCreateDoubleMatrix(m,n,0)
T_p = mxGetPr(PLHS(1))
CALL mxCopyPtrToReal8(A_p,%VAL(T_p),m*n)
END IF
c Create the vector "rnorms".
c If there are only 2 output arguments, then it is
c created simply as a temporary array, otherwise it
c is created as an output.
IF (NLHS .EQ. 2) THEN
rnorms_p = mxMalloc(8*n)
ELSE
PLHS(3) = mxCreateDoubleMatrix(1,n,0)
rnorms_p = mxGetPr(PLHS(3))
ENDIF
c Create an array for the index vector. This is only
c a temporary work array since the actual output has
c to consist of reals to follow matlab standards.
indveci_p = mxMalloc(4*n)
c Do the actual computations.
IF (flag_fixed_k .EQ. 0) THEN
CALL iddp_id(acc,m,n,%VAL(T_p),k,%VAL(indveci_p),%VAL(rnorms_p))
CALL mxSetM(PLHS(1),k)
CALL mxSetN(PLHS(1),n-k)
ELSE
CALL iddr_id(m,n,%VAL(T_p),k,%VAL(indveci_p),%VAL(rnorms_p))
CALL mxSetM(PLHS(1),k)
CALL mxSetN(PLHS(1),n-k)
ENDIF
c Create the REAL VALUED output index vector indvec.
c Then copy the integer vector indveci to the real valued output indvec.
PLHS(2) = mxCreateDoubleMatrix(1,n,0)
indvec_p = mxGetPr(PLHS(2))
CALL COPY_IND2REAL(%VAL(indveci_p), %VAL(indvec_p), n)
c Free the temporary work arrays.
CALL mxFree(indveci_p)
IF (NLHS .EQ. 2) THEN
CALL mxFree(rnorms_p)
ENDIF
RETURN
END

Iniciar sesión para comentar.

Respuestas (1)

James Tursa
James Tursa el 10 de Ag. de 2011
You need to strictly follow the API types. You don't get automatic argument type conversion in Fortran like you do in C. Change these lines:
INTEGER PLHS(*), PRHS(*)
INTEGER NLHS, NRHS
INTEGER mxCreateDoubleMatrix,mxMalloc
INTEGER mxGetPr,mxGetM,mxGetN,mxIsComplex
INTEGER A_p, INPUT2_p, T_p, rnorms_p, indvec_p, indveci_p
INTEGER m, n, k, flag_fixed_k, flag_complex
To these:
mwPointer PLHS(*), PRHS(*)
INTEGER*4 NLHS, NRHS
mwPointer, external :: mxCreateDoubleMatrix,mxMalloc
mwPointer, external :: mxGetPr
mwSize, external :: mxGetM,mxGetN
INTEGER*4, external :: mxIsComplex
mwPointer A_p, INPUT2_p, T_p, rnorms_p, indvec_p, indveci_p
mwSize m, n, k, p
INTEGER*4 flag_fixed_k, flag_complex
And change this line:
k = min(int(INPUT2(1)), min(m,n))
To these:
p = INPUT2(1)
k = min(p, min(m,n))
And change this line:
CALL mxCopyPtrToReal8(INPUT2_p,INPUT2,1)
To these:
p = 1
CALL mxCopyPtrToReal8(INPUT2_p,INPUT2,p)
And change this line:
PLHS(3) = mxCreateDoubleMatrix(1,n,0)
To these:
p = 1
PLHS(3) = mxCreateDoubleMatrix(p,n,0)
And change this line:
PLHS(2) = mxCreateDoubleMatrix(1,n,0)
To these:
p = 1
PLHS(2) = mxCreateDoubleMatrix(p,n,0)
As a side comment, you have some pretty strange code in there for copying mxArray variables and for changing the sizes of pre-existing mxArray variables.
  3 comentarios
Adrianna
Adrianna el 11 de Ag. de 2011
I figured out what was wrong. Thank you again for your help.
Urankhai
Urankhai el 14 de Feb. de 2018
Hi Adrianna, what was your problem? I have similar one

Iniciar sesión para comentar.

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by