Cleaning information to solve multiple instances of a JuMP model

Hi all.
I created an extensive program using JuMP library, to solve a specific model. To solve instances, I did make a routine to run for each instance all at once, using a loop and include to run. But I notice that it becomes slower than running it once at time. Is there any way to clear the information and reset the julia to do this faster?

Best Regards.

Do you have an MWE ? Check: Please read: make it easier to help you)

Are you using:
include(SCRIPT_PATH) inside a loop?

Are you using:
include(SCRIPT_PATH) inside a loop?

yes!

here is an MWE:

for w in 1:16
   
    for k in 2:a+1

        i = readdlm(files_even[w])[k, 1]

        j = readdlm(files_even[w])[k, 2]

        i = Int(i)

        j = Int(j)

        c[i+1,j+1] = readdlm(files_even[w])[k, 3]

        c[i+1,j+1] = Int(c[i+1,j+1])

        c[j+1, i+1] = c[i+1, j+1]

    end

    include("main.jl")

end

I’m doing loops over the instances and calling main to solve it inside the loop

In order to reproduce we would actually need the script main.jl.
However,
The problem might be just that.
You should move what you are doing in main.jl to a function:

function main(w,i,j,k,c)
...
end

for instance.
In this case you only need to include("main.jl") once, and outside the loop.
In the loop you just call the main(w,i,j,k,c) function.

This section in the manual is very good for performance tips: Performance Tips · The Julia Language

Following performance tips, you might want to put your loops inside another function as well.

2 Likes