Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run in different threads #11

Open
saswat0 opened this issue Nov 18, 2022 · 0 comments
Open

Run in different threads #11

saswat0 opened this issue Nov 18, 2022 · 0 comments

Comments

@saswat0
Copy link

saswat0 commented Nov 18, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant