OllieBoyne / sslap

Auction Algorithm for Sparse Linear Assignment Problems
MIT License
11 stars 6 forks source link

Possible memory leak issue #8

Open ArvinKhoshboresh opened 1 month ago

ArvinKhoshboresh commented 1 month ago

I've been trying to use this package to solve a very large (1M x 1M cost matrix, though very sparse) linear assignment problem. doing this causes a segmentation fault even when passing cardinality_check=False.

To get around this, I cut up my problem into many smaller problems of varying sizes (10kx10k to 300x300) because this is suboptimal but feasible for my use-case. My program will start to solve the smaller problems, but will eventually crash, but never at one particular problem.

To isolate the problem, I wrote the following code to remove the other elements of my code:

import numpy as np
from scipy.sparse import random as sparse_random
import sslap

size = 1000
density = 0.01
loop_count = 100

for i in range(loop_count):
    dense_matrix = sparse_random(size, size, density=density, format='coo', data_rvs=np.random.rand).todense()
    result = sslap.auction_solve(dense_matrix, cardinality_check=False, fast=True)
    print(f"Loop {i + 1} completed")

When this is done, memory usage climbs very quickly. Our compute has 200gb ram and a larger swap, and it quickly exceeds this.

Notably this only happens when passing a sparse matrix, and not a dense matrix. I believe it still happens with the dense matrix but it appears to be much much slower.

OllieBoyne commented 1 month ago

Hi! I haven't looked at this project for a few years - I'd imagine the malloc in auction_.pyx are not being freed properly.

I won't be able to have a look at it for a little while - will post any updates here when I am able to fix it.

ArvinKhoshboresh commented 1 month ago

Hi! No issue, thanks for writing it in the first place. Its been very useful up to now regardless.

I'm not a very experienced C or Cython programmer but I'll clone the project and see if I can fix it myself as well.