Skip to content

Run in different threads #11

Description

@saswat0

Can I run separate mvp solver instances in different threads simultaneously? I tried using python's multiprocessing module for this. Every time I keep the number of processes/threads as 1, it works as expected but when I increase the number of threads, I get this error:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpp105vrd2/1.tmp'

Here's the code for reference:

from pyvpsolver import VPSolver, MVP

def func(i):
    instance = MVP.from_file('demo.mvp')
    out, solution = VPSolver.script(
        "vpsolver_gurobi.sh", instance, verbose=False, options="Threads=12"
    )
    print(solution)

from multiprocessing import Pool

def run_parallel():
    
    list_ranges = [i for i in range(2)]

    pool = Pool(processes=len(list_ranges))
    pool.map(func, list_ranges)
  
if __name__ == '__main__':
    run_parallel()

MVP file (demo.mvp)

4
5
8 4 50 10 1 1
16 8 50 20 1 1
32 16 100 50 1 1
64 32 128 50 1 1
128 64 130 100 1 1
5
1 1
2 2 25 5
1 1
6 8 40 5
1 1
10 16 40 20
1 1
10 16 120 50
1 1
15 12 90 50

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions