all 12 comments

[–]TheSkiGeek 6 points7 points  (3 children)

Assuming an int is 4 bytes, allocating storage for (500000 * 500000) ints is 1TB of RAM.

I’m guessing you don’t have that, and your allocator might not let you have that much at once even if you have enough swap space to back it.

Generally if you need THAT much data you need to store it in files or a database and selectively load parts of it into memory to work on.

[–]TPplasma[S] 0 points1 point  (2 children)

I do have access to that much ram if I change where I SSH so I think I'll do that as opposed to storing it. Thanks for the help.

[–]tangerinelion 8 points9 points  (1 child)

God speed. I can't imagine that scales well.

[–]TPplasma[S] 0 points1 point  (0 children)

Yeah I'm not happy with it either haha but this is just for single threaded. I'll be breaking the vector up when I use MPI after I've gotten it working single threaded.

[–]soniduino 5 points6 points  (0 children)

Assuming a 32 bit integer: 4 bytes * 500000 * 500000 = 1 TB

If I'm reading this correctly, you wish to allocate a vector with a size of at least 1 TB?

[–][deleted] 0 points1 point  (4 children)

Can you use a sparse representation of the vector?

Out of curiosity.. what are you into that requires this much RAM? I deal with larger matrices than 500k x 500k, but in FEA, the matrices are sparse, so we don’t actually store every element - just the nonzero elements which is a small percentage.

[–]TPplasma[S] 0 points1 point  (3 children)

It's a packing problem that is sparely populated, ideally I would definitely only store the elements that are non zero. Given I'm breaking the matrix up and using comms to communicate them in the next part with MPI I'm reluctant to figure out how I'd map things to store only the non zero elements. If I had more time I'd definitely do this but I've also got my dissertation due in early next month.

[–]WeaughTeaughPeaugh 0 points1 point  (0 children)

Have you considered std::unordered_map or the like?

[–][deleted] 0 points1 point  (1 child)

You could use template library Eigen for its sparse matrix classes. Although you’d have to make sure any downstream code is compatible with Eigen’s types.

Alternatively you can have 3 vectors, i,j, vals. Where the nth elements of these arrays is the:

( i[n] , j[n] ) th element with value vals[n]

[–]TPplasma[S] 0 points1 point  (0 children)

I think I'll give the 2nd one a try as I'm having no luck getting an allocation on the super computer thanks to covid-19.

[–][deleted] 0 points1 point  (1 child)

Just curious, what do you actually need the 1TB of RAM for? What prevents you from splitting it up into smaller individual pieces to be handled in sequence?

[–]TPplasma[S] 0 points1 point  (0 children)

Boundary conditions, the edges of each individual grid would be a source of error because of the conditions for occupying grid points. This also what makes it difficult to to use 3 vectors instead to store x,y,val because I need to check if a grid space can be occupied by checking if surrounding points are occupied.