使用Eigen的MEX文件中的分段错误

时间:2015-08-02 15:33:30

标签: matlab eigen eigen3

在构建预处理器时,使用Matlab 2015a在OS X Yosemite上的段错误下面的MEX代码:

#include <Eigen/Sparse>
#include <mex.h>
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
    const mxArray *mx = prhs[0];
    if ( !mxIsSparse(prhs[0]) ) mexErrMsgTxt("Not a sparse matrix");
    mwSize M = mxGetM(prhs[0]);
    mwSize N = mxGetN(prhs[0]);
    double *pr = mxGetPr(prhs[0]);
    mwIndex *ir = mxGetIr(prhs[0]);
    mwIndex *jc = mxGetJc(prhs[0]);
    mwIndex NNZ = jc[N];

    Eigen::SparseMatrix<double> A(M, N);
    A.reserve( (int) NNZ );
    for (int i=0; i<NNZ; i++) {
        A.valuePtr()[i] = pr[i];
        A.innerIndexPtr()[i] = (int) ir[i];
    }
    for (int i=0; i<=N; i++) {
        A.outerIndexPtr()[i] = (int) jc[i];
    }

    mexPrintf("building precond:\n");
    Eigen::IncompleteLUT<double > prec(A);
    mexPrintf("building precond done.\n");

}

这是我使用的MEX命令:

mex -g eigenFail.cpp -I/usr/local/include/eigen3 -largeArrayDims

在我独立的代码中,这很好用。

这是堆栈跟踪:

Abnormal termination:
Segmentation violation

Register State (from fault):
  RAX = 000000010f71ff90  RBX = 0000000000000001
  RCX = 000000010f71fde0  RDX = 00007fff9183fdd2
  RSP = 00007fac64f954f5  RBP = 0000000000001000
  RSI = 0000000000000005  RDI = 000000010900da00

   R8 = 0000000000000003   R9 = 000000000000002c
  R10 = 000000000f71fed0  R11 = 00000001017a5000
  R12 = ff80000000001004  R13 = 000000010f71ffe8
  R14 = 000000010f71fe90  R15 = 000000012624fb04

  RIP = 000000010f71fe30  RFL = 000000012624a4a0

   CS = 000000010f720d58   FS = 000000010f720410   GS = 000000010f71fe60

Stack Trace (from fault):
[  0] 0x0000000102268964 /Applications/MATLAB_R2015a.app/bin/maci64/libmwfl.dylib+00031076 _ZN2fl4diag15stacktrace_base7captureERKNS0_14thread_contextEm+00000052
[  1] 0x000000010226c02b /Applications/MATLAB_R2015a.app/bin/maci64/libmwfl.dylib+00045099 _ZN2fl4test17terminate_handledEv+00000763
[  2] 0x000000010226bac7 /Applications/MATLAB_R2015a.app/bin/maci64/libmwfl.dylib+00043719 _ZN2fl4diag13terminate_logEPKcPK17__darwin_ucontext+00000119
[  3] 0x0000000101d90f9b /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00380827 _Z32mnRunPathDependentInitializationv+00002875
[  4] 0x0000000101d91217 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00381463 _Z32mnRunPathDependentInitializationv+00003511
[  5] 0x0000000101d8f3a6 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00373670 mnFatalSignalHandler+00000262
[  6] 0x00007fff958b2f1a           /usr/lib/system/libsystem_platform.dylib+00020250 _sigtramp+00000026
[  7] 0x00000001101c3c10 /Applications/MATLAB_R2015a.app/sys/java/jre/maci64/jre/lib/./server/libjvm.dylib+07785488 _ZTV23JNI_ArgumentPusherVaArg+00000016
[  8] 0x000000012624fb04 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00064260 _ZN5Eigen8internal46sparse_cwise_binary_op_inner_iterator_selectorINS0_13scalar_sum_opIdEEKNS_12SparseMatrixIdLi0EiEES6_NS_17CwiseBinaryOpImplIS3_S6_S6_NS_6SparseEE13InnerIteratorES8_S8_EppEv+00000100
[  9] 0x0000000126250cc2 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00068802 _ZN5Eigen8internal46sparse_cwise_binary_op_inner_iterator_selectorINS0_13scalar_sum_opIdEEKNS_12SparseMatrixIdLi0EiEES6_NS_17CwiseBinaryOpImplIS3_S6_S6_NS_6SparseEE13InnerIteratorES8_S8_EC2ERKNS_13CwiseBinaryOpIS3_S6_S6_EEi+00000114
[ 10] 0x0000000126250c43 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00068675 _ZN5Eigen17CwiseBinaryOpImplINS_8internal13scalar_sum_opIdEEKNS_12SparseMatrixIdLi0EiEES6_NS_6SparseEE13InnerIteratorC2ERKS8_i+00000051
[ 11] 0x000000012624f863 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00063587 _ZN5Eigen17CwiseBinaryOpImplINS_8internal13scalar_sum_opIdEEKNS_12SparseMatrixIdLi0EiEES6_NS_6SparseEE13InnerIteratorC1ERKS8_i+00000035
[ 12] 0x000000012624ffa0 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00065440 _ZN5Eigen16SparseMatrixBaseINS_12SparseMatrixIdLi0EiEEE13assignGenericINS_13CwiseBinaryOpINS_8internal13scalar_sum_opIdEEKS2_S9_EEEEvRKT_+00000400
[ 13] 0x000000012624f62e /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00063022 _ZN5Eigen16SparseMatrixBaseINS_12SparseMatrixIdLi0EiEEE6assignINS_13CwiseBinaryOpINS_8internal13scalar_sum_opIdEEKS2_S9_EEEERS2_RKT_+00000622
[ 14] 0x000000012624f3b0 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00062384 _ZN5Eigen16SparseMatrixBaseINS_12SparseMatrixIdLi0EiEEEaSINS_13CwiseBinaryOpINS_8internal13scalar_sum_opIdEEKS2_S9_EEEERS2_RKNS0_IT_EE+00000048
[ 15] 0x000000012624f2c4 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00062148 _ZN5Eigen12SparseMatrixIdLi0EiEaSINS_13CwiseBinaryOpINS_8internal13scalar_sum_opIdEEKS1_S7_EEEERS1_RKNS_16SparseMatrixBaseIT_EE+00000100
[ 16] 0x000000012624f232 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00062002 _ZN5Eigen12SparseMatrixIdLi0EiEC2INS_13CwiseBinaryOpINS_8internal13scalar_sum_opIdEEKS1_S7_EEEERKNS_16SparseMatrixBaseIT_EE+00000114
[ 17] 0x000000012624bfcd /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00049101 _ZN5Eigen12SparseMatrixIdLi0EiEC1INS_13CwiseBinaryOpINS_8internal13scalar_sum_opIdEEKS1_S7_EEEERKNS_16SparseMatrixBaseIT_EE+00000029
[ 18] 0x0000000126241ae6 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00006886 _ZN5Eigen13IncompleteLUTIdE14analyzePatternINS_12SparseMatrixIdLi0EiEEEEvRKT_+00000166
[ 19] 0x000000012624176f /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00005999 _ZN5Eigen13IncompleteLUTIdE7computeINS_12SparseMatrixIdLi0EiEEEERS1_RKT_+00000047
[ 20] 0x00000001262416b2 /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00005810 _ZN5Eigen13IncompleteLUTIdEC2INS_12SparseMatrixIdLi0EiEEEERKT_RKdi+00000290
[ 21] 0x000000012624153b /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00005435 _ZN5Eigen13IncompleteLUTIdEC1INS_12SparseMatrixIdLi0EiEEEERKT_RKdi+00000043
[ 22] 0x000000012624118d /Users/weissman/GIT_WORKING/PRIMME_CPP/PRIMME_EIGEN3/eigenFail.mexmaci64+00004493 mexFunction+00000653
[ 23] 0x0000000106ec31db /Applications/MATLAB_R2015a.app/bin/maci64/libmex.dylib+00070107 mexRunMexFile+00000091
[ 24] 0x0000000106ebf9f1 /Applications/MATLAB_R2015a.app/bin/maci64/libmex.dylib+00055793 _ZN7Mfh_mex30runMexFileWithSignalProtectionEiPP11mxArray_tagiS2_+00000113
[ 25] 0x0000000106ebfbcd /Applications/MATLAB_R2015a.app/bin/maci64/libmex.dylib+00056269 _ZN7Mfh_mex13dispatch_fileEiPP11mxArray_tagiS2_+00000285
[ 26] 0x0000000106f4a4bd /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_dispatcher.dylib+00386237 _ZN8Mfh_file16dispatch_fh_implEMS_FviPP11mxArray_tagiS2_EiS2_iS2_+00000621
[ 27] 0x0000000106f4a5f3 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_dispatcher.dylib+00386547 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00000035
[ 28] 0x000000010734203d /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01552445 _Z19inDispatchFromStackiPKcii+00001581
[ 29] 0x00000001072a5a88 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+00912008 inCallFcnFromReference+00000776
[ 30] 0x00000001072ea6c7 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01193671 inPcodeWalker+00006807
[ 31] 0x00000001072e676b /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01177451 inInterPcode+00000875
[ 32] 0x00000001072e7886 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01181830 _Z26inExecuteMFunctionOrScriptP6Mfh_mpb+00000886
[ 33] 0x000000010737d819 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01796121 _Z10inRunMfileiPP11mxArray_tagiS1_P6Mfh_mpP15inWorkSpace_tag+00003401
[ 34] 0x0000000106f4a4f2 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_dispatcher.dylib+00386290 _ZN8Mfh_file16dispatch_fh_implEMS_FviPP11mxArray_tagiS2_EiS2_iS2_+00000674
[ 35] 0x0000000106f4a5f3 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_dispatcher.dylib+00386547 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00000035
[ 36] 0x0000000107324ebd /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01433277 _Z23inEvalPcodeHeaderToWordP15_memory_contextiPP11mxArray_tagP12_pcodeheaderP6Mfh_mpj+00000141
[ 37] 0x00000001072dfadb /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01149659 _Z25in_local_call_with_setjmpIN5boost3_bi6bind_tIvPFvP15_memory_contextPiPP11mxArray_tagP12_pcodeheaderjENS1_5list5INS1_5valueIS4_EENS0_3argILi1EEENSG_ILi2EEENSE_ISA_EENSE_IiEEEEEEEN6mlutil14cmddistributor17inExecutionStatusET_S5_S8_b+00000171
[ 38] 0x00000001072dadc0 /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01129920 _Z12inEvalStringP15_memory_contextRKNSt3__112basic_stringIDsNS1_11char_traitsIDsEENS1_9allocatorIDsEEEE8EvalTypeiPP11mxArray_tag12inDebugCheckP12_pcodeheaderPib+00002608
[ 39] 0x00000001072db3dd /Applications/MATLAB_R2015a.app/bin/maci64/libmwm_interpreter.dylib+01131485 _ZN12InterpBridge22EvalCmdWithLocalReturnERKNSt3__112basic_stringIDsNS0_11char_traitsIDsEENS0_9allocatorIDsEEEEPibb+00000141
[ 40] 0x0000000106e5db0d /Applications/MATLAB_R2015a.app/bin/maci64/libmwbridge.dylib+00068365 _Z28evalCommandWithLongjmpSafetyRKNSt3__112basic_stringIDsNS_11char_traitsIDsEENS_9allocatorIDsEEEE+00000093
[ 41] 0x0000000106e5e06c /Applications/MATLAB_R2015a.app/bin/maci64/libmwbridge.dylib+00069740 _Z8mnParserv+00000700
[ 42] 0x0000000101d7b132 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00291122 _ZN11mcrInstance30mnParser_on_interpreter_threadEv+00000034
[ 43] 0x0000000101d55021 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00135201 _ZN3mcr7runtime17InterpreterThread4Impl22TypedInvocationRequestIvE29doNotRethrowMxArrayExceptionsERKN5boost8functionIFvvEEE+00000033
[ 44] 0x0000000101d55ae9 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00137961 _ZN5boost6detail11task_objectIvNS_3_bi6bind_tIvPFvRKNS_8functionIFvvEEEENS2_5list1INS2_5valueIS6_EEEEEEE6do_runEv+00000025
[ 45] 0x0000000101d55476 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00136310 _ZN5boost6detail9task_baseIvE3runEv+00000182
[ 46] 0x0000000101d55217 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00135703 _ZN3mcr7runtime17InterpreterThread4Impl22TypedInvocationRequestIvE3runEv+00000023
[ 47] 0x0000000101d514e3 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00120035 _ZN3mcr7runtime17InterpreterThread4Impl26invocation_request_handlerEl+00000035
[ 48] 0x00000001017d688d /Applications/MATLAB_R2015a.app/bin/maci64/libmwservices.dylib+00182413 _ZN10eventqueue18UserEventQueueImpl5flushEv+00001053
[ 49] 0x0000000107cdb5f5 /Applications/MATLAB_R2015a.app/bin/maci64/libmwuix.dylib+00038389 _Z25isHandleUserEventCallbackPFvPvE+00000469
[ 50] 0x000000010189ef8d /Applications/MATLAB_R2015a.app/bin/maci64/libmwservices.dylib+01003405 _Z40svWS_ProcessPendingEventsWithLimitedRateb+00017149
[ 51] 0x000000010189a372 /Applications/MATLAB_R2015a.app/bin/maci64/libmwservices.dylib+00983922 _Z25svWS_ProcessPendingEventsiib+00000866
[ 52] 0x000000010189a06b /Applications/MATLAB_R2015a.app/bin/maci64/libmwservices.dylib+00983147 _Z25svWS_ProcessPendingEventsiib+00000091
[ 53] 0x0000000101d51737 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00120631 _ZN3mcr7runtime17InterpreterThread4Impl14process_eventsERKN5boost10shared_ptrIS2_EE+00000135
[ 54] 0x0000000101d51a6a /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00121450 _ZN3mcr7runtime17InterpreterThread4Impl3runERKN5boost10shared_ptrIS2_EEPNS2_12init_contextE+00000346
[ 55] 0x0000000101d3a156 /Applications/MATLAB_R2015a.app/bin/maci64/libmwmcr.dylib+00024918 _Z26run_init_and_handle_eventsPv+00000054
[ 56] 0x00007fff91662268            /usr/lib/system/libsystem_pthread.dylib+00012904 _pthread_body+00000131
[ 57] 0x00007fff916621e5            /usr/lib/system/libsystem_pthread.dylib+00012773 _pthread_body+00000000
[ 58] 0x00007fff9166041d            /usr/lib/system/libsystem_pthread.dylib+00005149 thread_start+00000013

0 个答案:

没有答案