Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

How often does the CPLEX Callable Library access the CPLEX license?

  • 1.  How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/18/12 11:32 AM

    Originally posted by: BerkUstun


    I've been receiving weird segmentation violations with a MEX file that uses the CPLEX 12.4 Callable Library.

    After a lot of debugging, I have found out that the segmentation violation does not occur in the body of my C code but either before or after it launches. In addition, the segmentation violation only occurs when I run this MEX file in parallel, and it seems to occur more frequently when I use more cores. The violation does not occur when I run my program sequentially.

    One of the possible reasons that was suggested for the violation was that multiple cores may be trying to access the CPLEX license file at the same time - so I had a few questions about how this works. In particular, I'm wondering if I have to I need to access the CPLEX license everytime I run my MEX file (even after it is compiled)?
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/18/12 03:05 PM

    Originally posted by: BerkUstun


    After some further debugging, I have discovered that the segmentation violations originate from the "putenv" function in C, which appears to be used to set the CPLEX license file for other APIs. Some follow-up questions:
    • Seeing how the academic initiative only grants 12 CPLEX licenses, I'm wondering if I could get a segmentation violation when I have to run more than 12 instances of my MEX file at the same time.

    • I'm somewhat unfamiliar with how the license file works. What exactly happens to the license file when I open / close a CPLEX environment? Is there a counter on it that increments / decrements? Or are there 12 license files that can be used at the same time?

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/20/12 01:51 AM

    Originally posted by: SystemAdmin


    CPLEX accesses the license file when you call CPXopenCPLEX().
    It is a known problem with license management that this is may not work when called in parallel.
    In your MEX file, could you just put locks around the calls to CPXopenCPLEX()? That should fix the problems.
    On Linux/Unix this would be something like that:
    #include <pthread.h>
    static pthread_mutex_t openCPLEXLock = PTHREAD_MUTEX_INITIALIZER;
     
    void function_in_mex(...) {
       int status;
       CPXENVptr env;
       pthread_mutex_lock(&openCPLEXLock);
       env = CPXopenCPLEX(&status);
       pthread_mutex_unlock(&openCPLEXLock);
       /* Check status */
       ...
    }
    

    On Windows
    static CRITICAL_SECTION openCPLEXLock;
     
    /* openCPLEXLock should be initialized _once_ at startup */
     
    void function_in_mex(...) {
       int status;
       CPXENVptr env;
       EnterCriticalSection (&openCPLEXLock);
       env = CPXopenCPLEX(&status);
       LeaveCriticalSection (&openCPLEXLock);
       /* Check status */
       ...
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/21/12 08:59 PM

    Originally posted by: BerkUstun


    Thank you for this! The fix appears to work for now, though I will have to test it a few times to make sure.

    In any case, I had a quick follow-up question. Could I have avoided this by declaring env as a static variable in my MEX code, and calling CPXopenCPLEX() before and after all of my MEX runs? I've tried this in MATLAB but for some reason I cannot manage to keep env as a static variable - I'm wondering whether this is an issue with MATLAB / my code or something that you guys intended?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 02:04 AM

    Originally posted by: SystemAdmin


    If you want to do multiple solves in parallel you will need multiple instances of CPXENVptr. So a single static variable will not do, no matter whether the programming environment allows that or not.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 07:52 AM

    Originally posted by: BerkUstun


    Does that mean that you can you only have as many CPXENVptr open as the number of licenses that you have (i.e. 12 on the Academic Initiative license?)
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 01:16 PM

    Originally posted by: SystemAdmin


    The license file should not limit the number CPXENVptr instances that you can create simultaneously. You should be able to create as many CPXENVptr instances as you like (as long as the OS has resources, of course). Do you observe otherwise?
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 01:29 PM

    Originally posted by: BerkUstun


    Just curious. I am still getting segmentation violations linked to the putenv() function. Right now, I've changed all the declarations of

    
    
    
    void function_in_mex(...) 
    {   CPXENVptr env     = NULL; 
    
    int       status = 0; env               = CPXopenCPLEX (&status);   
    // my code    
    }
    


    to

    
    
    
    static            pthread_mutex_t openCPLEXLock = PTHREAD_MUTEX_INITIALIZER;   
    
    void function_in_mex(...) 
    { 
    
    int status        = 1; CPXENVptr env     = NULL;   
    
    while ( status ) 
    { 
    // this is not a good idea, though I've done it this way to ensure that CPLEX will open in the MEX file pthread_mutex_lock(&openCPLEXLock); env = CPXopenCPLEX (&status) pthread_mutex_unlock(&openCPLEXLock); 
    }   
    // my code    
    }
    


    Since I run the MEX file in parallel using a parfor loop in CPLEX, I've also made it a point to declare the openCPLEXLock as a global / static variable before the parfor loop.

    I think this makes sense, though please let me know if it sets off any alarm. Otherwise, it might just be an issue with MATLAB.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 01:36 PM

    Originally posted by: SystemAdmin


    A global/static lock sounds like the right thing to do, at least from a C point of view. I don't know about matlab and MEX :-(
    Do you have any chance to run the whole thing through valgrind and see if this gives more details? Or could you create a backtrace for the segmentation fault in a debugger and post that here?
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 01:42 PM

    Originally posted by: BerkUstun


    Hmm I will post on the MATLAB forums as well then. Meanwhile, here is a recent stack trace from the segmentation fault... Let me know if you guys can figure anything out.
    Segmentation violation detected at Mon Apr 23 13:06:41 2012


    Configuration:
    Crash Decoding : Disabled
    Current Visual : None
    Default Encoding: UTF-8
    GNU C Library : 2.14.90 development
    MATLAB Root : /home/software/matlab/matlab-2012a
    MATLAB Version : 7.14.0.739 (R2012a)
    Operating System: Linux 3.3.1-3.fc16.x86_64 #1 SMP Wed Apr 4 18:08:51 UTC 2012 x86_64
    Processor ID : x86 Family 6 Model 26 Stepping 4, GenuineIntel
    Virtual Machine : Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
    Window System : No active display

    Fault Count: 1
    Abnormal termination:
    Segmentation violation

    Register State (from fault):
    RAX = 0000000000000000 RBX = 0000000000000011
    RCX = 0000000000000030 RDX = 0000000000000011
    RSP = 00007f576e6aaf28 RBP = 00007f576e6aafa0
    RSI = 00007f576e6aafb0 RDI = 00007f5689596b80

    R8 = 000000000000ffff R9 = 0000000000000060
    R10 = 0000003b46489e20 R11 = 0000000000000011
    R12 = 00007f576e6aafb0 R13 = 00007f5689596b80
    R14 = 0000000000000050 R15 = 0000003b467b4598

    RIP = 0000003b46488acc EFL = 0000000000010283

    CS = 0033 FS = 0000 GS = 0000

    Stack Trace (from fault):
    0 0x00007f5786ae192e /home/software/matlab/matlab-2012a/bin/glnxa64/libmwfl.so+00370990 _ZN2fl4diag15stacktrace_base7captureERKNS0_14thread_contextEm+000158
    1 0x00007f5786ae47d0 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwfl.so+00382928
    2 0x00007f5786ae4b3b /home/software/matlab/matlab-2012a/bin/glnxa64/libmwfl.so+00383803 _ZN2fl4diag13terminate_logEPKcRKNS0_14thread_contextE+000171
    3 0x00007f57859c6203 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01253891 _ZN2fl4diag13terminate_logEPKcPK8ucontext+000067
    4 0x00007f57859c30fd /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01241341
    5 0x00007f57859c479d /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01247133
    6 0x00007f57859c4925 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01247525
    7 0x00007f57859c4f01 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01249025
    8 0x00007f57859c53f5 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01250293
    9 0x0000003b4700f500 /lib64/libpthread.so.0+00062720
    10 0x0000003b46488acc /lib64/libc.so.6+00559820
    11 0x0000003b4643915a /lib64/libc.so.6+00233818
    12 0x0000003b4643903d /lib64/libc.so.6+00233533 putenv+000109
    13 0x00007f56c0ffe676 /home/software/cplex/cplex-12.4/cplex/matlab/cplexlink124.mexa64+02860662
    14 0x00007f56c0e0a434 /home/software/cplex/cplex-12.4/cplex/matlab/cplexlink124.mexa64+00812084
    15 0x00007f56c0e09af4 /home/software/cplex/cplex-12.4/cplex/matlab/cplexlink124.mexa64+00809716
    16 0x00007f56c0e0930c /home/software/cplex/cplex-12.4/cplex/matlab/cplexlink124.mexa64+00807692
    17 0x00007f56c0dc2c09 /home/software/cplex/cplex-12.4/cplex/matlab/cplexlink124.mexa64+00519177
    18 0x00007f56c0dc2146 /home/software/cplex/cplex-12.4/cplex/matlab/cplexlink124.mexa64+00516422 mexFunction+000448
    19 0x00007f577fbfecca /home/software/matlab/matlab-2012a/bin/glnxa64/libmex.so+00109770 mexRunMexFile+000090
    20 0x00007f577fbfaf79 /home/software/matlab/matlab-2012a/bin/glnxa64/libmex.so+00094073
    21 0x00007f577fbfbde1 /home/software/matlab/matlab-2012a/bin/glnxa64/libmex.so+00097761
    22 0x00007f578566e063 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_dispatcher.so+00479331 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000515
    23 0x00007f5784f34476 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01987702
    24 0x00007f5784ee5426 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01664038
    25 0x00007f5784ee9be4 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01682404
    26 0x00007f5784ee6333 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01667891
    27 0x00007f5784ee7037 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01671223
    28 0x00007f5784f50690 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+02102928
    29 0x00007f578566e063 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_dispatcher.so+00479331 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000515
    30 0x00007f577e81ba6f /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01522287
    31 0x00007f577e7b7124 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01110308
    32 0x00007f577e7b7bab /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01113003
    33 0x00007f577e7b7ebe /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01113790
    34 0x00007f577e7b918d /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01118605
    35 0x00007f577e7b92ad /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01118893
    36 0x00007f577e7b954c /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01119564 _Z27omConstructObjectWithClientN4mcos9COSNameIDEiPPK11mxArray_tagPKNS_9COSClientE+000476
    37 0x00007f577e8241bd /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01556925
    38 0x00007f577e89e563 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+02057571
    39 0x00007f57856286a1 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_dispatcher.so+00194209 _ZN13Mfh_MATLAB_fn11dispatch_fhEiPP11mxArray_tagiS2_+000481
    40 0x00007f5784f34476 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01987702
    41 0x00007f5784ee5426 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01664038
    42 0x00007f5784ee9be4 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01682404
    43 0x00007f5784ee6333 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01667891
    44 0x00007f5784ee7037 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01671223
    45 0x00007f5784f50690 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+02102928
    46 0x00007f578566e063 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_dispatcher.so+00479331 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000515
    47 0x00007f577e816388 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01500040
    48 0x00007f577e7b7c22 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01113122
    49 0x00007f577e7b7ebe /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01113790
    50 0x00007f577e7b9c7c /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01121404
    51 0x00007f577e802236 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01417782 _Z19omCallLoadobjMethodRN4mcos15COSInterfacePtrENS_8COSValueENS_14COSDataTypePtrE+000694
    52 0x00007f577e802937 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01419575
    53 0x00007f577e73c676 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+00607862
    54 0x00007f577e7f40eb /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01360107
    55 0x00007f577e7e5f41 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01302337
    56 0x00007f577e7e63fe /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01303550
    57 0x00007f577e7e73f8 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcos.so+01307640
    58 0x00007f5786833654 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00419412
    59 0x00007f578683557a /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00427386
    60 0x00007f5786835017 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00426007
    61 0x00007f5786834b18 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00424728
    62 0x00007f5786835017 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00426007
    63 0x00007f5786835017 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00426007
    64 0x00007f5786835017 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00426007
    65 0x00007f5786835017 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00426007
    66 0x00007f5786835a23 /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00428579 miGetCurrentItem+000387
    67 0x00007f57868181db /home/software/matlab/matlab-2012a/bin/glnxa64/libmx.so+00307675 mxDeserializeWithTag+000315
    68 0x00007f56d8bea1e0 /home/software/matlab/matlab-2012a/toolbox/distcomp/distcomp/distcompdeserialize.mexa64+00008672 mexFunction+000080
    69 0x00007f577fbfecca /home/software/matlab/matlab-2012a/bin/glnxa64/libmex.so+00109770 mexRunMexFile+000090
    70 0x00007f577fbfaf79 /home/software/matlab/matlab-2012a/bin/glnxa64/libmex.so+00094073
    71 0x00007f577fbfbde1 /home/software/matlab/matlab-2012a/bin/glnxa64/libmex.so+00097761
    72 0x00007f578566e063 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_dispatcher.so+00479331 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000515
    73 0x00007f5784f34476 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01987702
    74 0x00007f5784ee5426 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01664038
    75 0x00007f5784ee9be4 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01682404
    76 0x00007f5784ee6333 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01667891
    77 0x00007f5784ee7037 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01671223
    78 0x00007f5784f50690 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+02102928
    79 0x00007f578566e063 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_dispatcher.so+00479331 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000515
    80 0x00007f5784f1365f /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01853023
    81 0x00007f5784f12d49 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01850697
    82 0x00007f5784e742ec /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01200876 inCallFcnWithTrap+000092
    83 0x00007f5784ed9b6b /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01616747
    84 0x00007f5784e73438 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwm_interpreter.so+01197112 _Z28inCallFcnWithTrapInDesiredWSiPP11mxArray_tagiS1_PKcbP15inWorkSpace_tag+000104
    85 0x00007f5780267d79 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwiqm.so+02485625 _ZN3iqm15BaseFEvalPlugin7executeEP15inWorkSpace_tagRN5boost10shared_ptrIN14cmddistributor17IIPCompletedEventEEE+000457
    86 0x00007f575d07909d /home/software/matlab/matlab-2012a/bin/glnxa64/libnativejmi.so+00696477 _ZN9nativejmi14JmiFEvalPlugin7executeEP15inWorkSpace_tagRN5boost10shared_ptrIN14cmddistributor17IIPCompletedEventEEE+000173
    87 0x00007f575d0ab6e5 /home/software/matlab/matlab-2012a/bin/glnxa64/libnativejmi.so+00902885 _ZN3mcr3mvm27McrSwappingIqmPluginAdapterIN9nativejmi14JmiFEvalPluginEE7executeEP15inWorkSpace_tagRN5boost10shared_ptrIN14cmddistributor17IIPCompletedEventEEE+000629
    88 0x00007f5780250482 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwiqm.so+02389122
    89 0x00007f5780241264 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwiqm.so+02327140
    90 0x00007f5785c32afc /home/software/matlab/matlab-2012a/bin/glnxa64/libmwbridge.so+00125692 _Z10ioReadLinebP8_IO_FILEPcS1_iPbRKN5boost8optionalIKP15inWorkSpace_tagEEb+000508
    91 0x00007f5785c33165 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwbridge.so+00127333
    92 0x00007f5785c37d0a /home/software/matlab/matlab-2012a/bin/glnxa64/libmwbridge.so+00146698
    93 0x00007f5785c38165 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwbridge.so+00147813
    94 0x00007f5785c389ce /home/software/matlab/matlab-2012a/bin/glnxa64/libmwbridge.so+00149966 mnParser+000702
    95 0x00007f57859aade2 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01142242 _ZN11mcrInstance30mnParser_on_interpreter_threadEv+000034
    96 0x00007f578598d51a /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01021210
    97 0x00007f578598d598 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01021336
    98 0x00007f57861c0053 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwservices.so+00823379
    99 0x00007f57861c0315 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwservices.so+00824085
    100 0x00007f57861bebc1 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwservices.so+00818113
    101 0x00007f577c328605 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwuix.so+00505349
    102 0x00007f57862449a1 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwservices.so+01366433 _ZSt8for_eachIN9__gnu_cxx17__normal_iteratorIPN5boost8weak_ptrIN4sysq10ws_ppeHookEEESt6vectorIS6_SaIS6_EEEENS4_8during_FIS6_NS2_10shared_ptrIS5_EEEEET0_T_SH_SG_+000081
    103 0x00007f5786245aab /home/software/matlab/matlab-2012a/bin/glnxa64/libmwservices.so+01370795
    104 0x00007f57862435f9 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwservices.so+01361401 _Z25svWS_ProcessPendingEventsiib+000665
    105 0x00007f578598c76f /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01017711
    106 0x00007f578598cc3b /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01018939
    107 0x00007f578598cd97 /home/software/matlab/matlab-2012a/bin/glnxa64/libmwmcr.so+01019287
    108 0x0000003b47007d90 /lib64/libpthread.so.0+00032144
    109 0x0000003b464f0f5d /lib64/libc.so.6+00986973 clone+000109
    This error was detected while a MEX-file was running. If the MEX-file
    is not an official MathWorks function, please examine its source code
    for errors. Please consult the External Interfaces Guide for information
    on debugging MEX-files.

    If this problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/

    A technical support engineer might contact you with further information.

    Thank you for your help.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 02:41 PM

    Originally posted by: SystemAdmin


    The stacktrace suggests that the crash happens when a new Cplex instance is created in matlab .
    Is it possible that you create Cplex instances concurrently in your matlab code?
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 02:45 PM

    Originally posted by: BerkUstun


    Yes actually! I am using the CPLEX API for MATLAB, and the CPLEX Callable library in the MEX file.
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/23/12 02:58 PM

    Originally posted by: BerkUstun


    Sorry should have added more detail:

    Right now my experiment (an m-file) uses the CPLEX MATLAB API as well as a MEX function that uses the CPLEX Callable Library.

    I'm guessing that the segmentation violation occurs when one experiment creates Cplex() objects in MATLAB while another experiment is using the MEX file?

    Would this result in an error because the MATLAB API also uses the putenv() function (and is not thread safe)? And if so, is there any way around this that does not involve "timing" the experiments so that I do not create a Cplex() object?

    Thank you so much for the insight so far! I feel like I'm finally getting somewhere.
    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/24/12 01:51 AM

    Originally posted by: SystemAdmin


    What really puzzles me is that CPXopenCPLEX() calls putenv(). How do you setup your licensing? Do you just point ILOG_LICENSE_FILE to the location of the license file or do you use a different sort of licensing setup?
    The only way to serialize the various ways in which CPXopenCPLEX() may be called is to protect all of them by the same lock. Can you write two MEX functions that result in pthread_mutex_lock(&openCPLEXLock) and in pthread_mutex_unlock(&openCPLEXLock) respectively and call them before/after instantiating CPLEX objects in matlab?
    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/24/12 10:17 PM

    Originally posted by: BerkUstun


    Sorry - will get back to you soon about the licensing since all of this is set up on a computing cluster. I will also have to try the MEX functions, though I'm a little confused about what exactly I should do. Basically the idea is to replace any command in MATLAB such as

    LP = Cplex()
    


    with

    mutexLock()
    LP = Cplex()
    mutexUnLock()
    


    where mutexLock and mutexUnLock are the MEX files that call pthread_mutex_lock(&openCPLEXLock) and in pthread_mutex_unlock(&openCPLEXLock) respectively right?

    Also another tidbit: I recently started to instantiate the LP objects outside of the parfor loop and have not experienced a segmentation violation since. I'm wondering whether this instantiating the objects within MATLAB may have been the issue all along?
    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/25/12 12:26 AM

    Originally posted by: SystemAdmin


    >
    > mutexLock()
    > LP = Cplex()
    > mutexUnLock()
    >
    

    >
    > where mutexLock and mutexUnLock are the MEX files that call pthread_mutex_lock(&openCPLEXLock) and in pthread_mutex_unlock(&openCPLEXLock) respectively right?
    >
    Yes, that is what I meant to suggest.

    > Also another tidbit: I recently started to instantiate the LP objects outside of the parfor loop and have not experienced a segmentation violation since. I'm wondering whether this instantiating the objects within MATLAB may have been the issue all along?
    >
    Our best guess so far was that parallel invocation of CPXopenCPLEX() (which is called implicitly by the Cplex() constructor in matlab) was the cause for your troubles. Any code change that avoids calling this function in parallel should fix the problem.
    I guess you still have the locking in your MEX file for the cases in which you call CPXopenCPLEX() directly from the MEX file? If you instantiate Cplex outside the parfoor loop, can it happen that an instantiation of Cplex and a call to CPXopenCPLEX() from the MEX file may overlap? Or is the MEX file only invoked from inside the parfor loop? If the MEX file is called only from inside the parfor loop, the MEX file uses locks around explicit calls to CPXopenCPLEX() and you instantiate Cplex only outside the parfor loop in matlab then it looks to me as if you have eliminated parallel invocations of CPXopenCPLEX().
    #CPLEXOptimizers
    #DecisionOptimization


  • 17.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 04/27/12 11:06 AM

    Originally posted by: BerkUstun


    Thanks for all your help on this.

    Using the mutexLock() and mutexUnlock() functions as described above avoids the segmentation errors. Alternatively, creating the Cplex() objects before the parfor loop also works (mainly because it avoids constructing Cplex() objects within the parfor loop where the MEX file is running) also avoids the segmentation errors.

    Just FYI about the licensing setup. I don't quite understanding how it works, but I asked our admins and it turns out that my computing cluster just sets an environmental variable that points to the ILOG_LICENSE_FILE - so I guess it's the standard setup. I suppose something weird may be going on with the way that parfor works?

    If there's anything else you'd like to know let me know!
    #CPLEXOptimizers
    #DecisionOptimization


  • 18.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 05/01/12 11:40 AM

    Originally posted by: SystemAdmin


    I have no clue why CPLEX would call putenv() if you use the ILOG_LICENSE_FILE environment variable to point CPLEX to the license file. But there is probably no way to figure what exactly is going on without me logging onto your cluster :-)
    So if you agree I will not pursue this any further as it seems your code is working without problems right now.
    #CPLEXOptimizers
    #DecisionOptimization


  • 19.  Re: How often does the CPLEX Callable Library access the CPLEX license?

    Posted 05/01/12 12:05 PM

    Originally posted by: BerkUstun


    Of course! Thank you again for all your help. Everything runs very smoothly now.
    #CPLEXOptimizers
    #DecisionOptimization