Parallelization of Sum in JuMP

Btw, this is my first post here

Welcome! It’s a little easier to provide feedback if you can produce a minimal working example: Please read: make it easier to help you. Without one, we have to make some guesses. What are a and b? What is term_idxs? Are there lots of (i, j) with the same i? How many terms are we talking about?

I did not really find any approaches to parallelizing a sum in JuMP models.

There is no way to use parallelism to make problem construction faster.

One suggestion I would try is to factor out the terms that do not depend on j. Assuming I didn’t make a mistake (I didn’t run the code because I don’t have the data):

I = unique(first.(term_idxs))
@expression(model, term_i[i=I], sum(x[(i, j)] for j in dict_j[i]))
@expression(model, sum((a[i] - b[i] * term_i[i]) * term_i[i] for i in I))

This should greatly reduce the number of loop iterations. Otherwise you’re looping over all term_idxs and for each term you’re looping over dict_j[I].

You should also read the Julia performance tips if you haven’t already: Performance Tips · The Julia Language. I assume you aren’t using global variables, etc?

2 Likes