Skip to main content

Gurobi parallel load COBRA (.mat) model

Comments

1 comment

  • Igor Ganapolsky

    The bottleneck is very likely not Gurobi but what you send back through the Pool.

     

    1) You return result['model'], a live Gurobi model object. Gurobi Model/Env objects are not picklable, and even when a wrapper makes them serializable, each one must be pickled in the worker, streamed over a pipe, and unpickled in the parent. The parent unpickles one result at a time, so it becomes the serial bottleneck and the whole run looks serial even though workers do run in parallel. Return only numbers you need (v_max_row, phenotype, sample_id, fname) and rebuild/re-read models in the parent only for the few you actually need.

     

    2) chunksize=1 with large payloads maximizes IPC overhead. If tasks are short, raise chunksize. If each task is dominated by the .mat read, that is disk I/O and 16 workers on one disk serialize on it regardless of Gurobi. Time one worker call to see how much is scipy.io.loadmat vs the LP solve.

     

    3) Make sure _pool_initializer creates one gurobipy.Env per process, and that no Env is created at module import before the fork. An env created pre-fork and inherited by children is a classic cause of contention. Create it in the initializer with Threads=1 and OutputFlag=0 and reuse it for all models in that worker.

     

    4) On Linux the default start method is fork; if any parent-level Gurobi env exists, use multiprocessing.set_start_method("spawn") so workers start clean.

     

    5) Verify parallelism independently of Gurobi: print os.getpid() and a timestamp at the top of _load_and_compute_one. If 16 distinct PIDs start at once, the workers are fine and the problem is the result-handling path in point 1.

    0

Please sign in to leave a comment.