coin-or / Clp

COIN-OR Linear Programming Solver
Other
408 stars 85 forks source link

(Barrier + C interface + large LP) results in segfault #151

Open mtanneau opened 4 years ago

mtanneau commented 4 years ago

I am trying to solve some of the H Mittelmann benchmark instances with Clp's interior-point algorithm. The following occurs when trying to solve neos3.

Running Clp's command line executable works fine

clp neos3.mps -barr

and I obtain a log similar to this one.

However, when calling Clp through its C interface (see code below), I get a segmentation fault.

The big question is: why segfault when using the C interface and not when using the executable?

FWIW, the executable correctly detects that it should solve the dual problem, and things run smoothly. When using the C interface, Clp just dies out (see the log below).

Here is the code I am running

#include "Clp_C_Interface.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

int main(int argc, const char *argv[])
{

    if (argc < 2) {
        fprintf(stdout, "Do not know where to find sample MPS files.\n");
        fprintf(stderr, "Do not know where to find sample MPS files.\n");
        exit(1);
    }

    /* Get default model */
    Clp_Simplex * model = Clp_newModel();
    int status;

    /* Keep names when reading an mps file */
    status = Clp_readMps(model, argv[1], 1, 0);

    if (status) {
        fprintf(stderr, "Bad readMps %s\n", argv[1]);
        fprintf(stdout, "Bad readMps %s\n", argv[1]);
        exit(1);
    }

    // Use barrier algorithm, no crossover
    Clp_Solve * options = ClpSolve_new();
    ClpSolve_setSolveType(options, 4, false);

    status = Clp_initialSolveWithOptions(model, options);  // seg fault here

    if (status) {
        fprintf(stderr, "Clp exited with status %d\n", status);
        fprintf(stdout, "Clp exited with status %d\n", status);
        exit(1);
    }

    return 0;
}

The output is

Coin0001I At line 1 NAME          neos3
Coin0001I At line 2 ROWS
Coin0001I At line 512213 COLUMNS
Coin0001I At line 1283910 RHS
Coin0001I At line 1283912 ENDATA 
Coin0002I Problem neos3 has 512209 rows, 6624 columns and 1542816 elements
Clp0027I Model was imported from /home/mtanneau/Git/LPBenchmarks/dat/plato/neos3.mps in 0.4375 seconds 
Coin0506I Presolve 512209 (0) rows, 6624 (0) columns and 1542816 (0) elements
2.0729e+08 elements in sparse Cholesky, flop count 3.4653e+16
Segmentation fault (core dumped)

Version info:

Note: I originally ran into this issue while using Clp via Julia; see https://github.com/JuliaOpt/Clp.jl/issues/81. The sequence of C calls to Clp is exactly the one I reproduced above.

jjhforrest commented 4 years ago

I have modified Clp/master so that it recognizes that barrier will use too much memory and switch to simplex. Looking at the flop count, barrier would have taken several years! If I run clp with -dualize 0 -barrier then it switches to dual and takes an hour but does solve (just running clp takes a minute).

The dualize option is not available in the C interface.