views:

1350

answers:

10

Hi, I'm working on a Java application that needs working on very large matrices. For example multiplying two 10 million * 10 million matrices! Of course the Java heap does not have enough space even for storing one of these matrices. What should I do? Should I use databases to store my matrices and bring to memory every needed part and multiply it part after another?

Please help me :)

+2  A: 

consider using a memory db like http://hsqldb.org/

Tobiask
This is a RDB. You mean I can use any RDB for this mean... for example MySQL?Is it efficient to use a DB? I mean is there any better solution (using disk space or ...).
I'd say "embedded" DB, because HSQLDB can do a lot more than pure in-memory databases.
Joachim Sauer
@unknown: yes, a RDB is probably a good idea for this, since it's designed to handle massive amounts of data. Depending on your exact needs, you might need more specialized software, but from what you wrote, I'd suggest a relational database.
Joachim Sauer
i would use a rdb, sth that runs in memory will be fast as well
Tobiask
+2  A: 

Well if you are forced to use Java and can't write the code that deals with this as native methods (that is, by telling Java to call some C code instead) then the most efficient thing to do would properly be to use a simple binary file. I would stay away from databases in this case because they are slower than direct file access and you don't need the features they offer.

tomjen
I see. Thank you. I think this works for my application :)
using a in-memory db wouldn´t been slow...
Tobiask
+3  A: 

The complexity of matrix multiplication, if carried out naively, is O(n^3), but more efficient algorithms do exist. Anyway for a 10 millions * 10 millions matrix this is going to take a very long time and you may will face the same heap probelm but with recursivity.

If you're into complex maths you may find tool to help you in this article.

MarmouCorp
+2  A: 

Have a look at hadoop.

pgras
A: 

Thank you all. Do you think there is any other solution or suggestion?

+2  A: 

Since this is such a huge calculation, I think you're going to run into performance problems alongside your storage problems. So I would look at parallelising this problem, and getting mutliple machines/cores to process a subset of data.

Luckily a matrix multiplication solution will decompose naturally. But I would be looking at some form of grid or distributed computing solution.

Brian Agnew
+2  A: 

Use whatever sparse matrix algorithm applies to your data. ( on the assumption that you don't have 2.4 PB of disk space to hold 3 off 10^8 square non-sparse matrices of doubles, let alone that much RAM for an in-memory database - Blue Gene/Q 'only' has 1.6 PB .)

Pete Kirkham
A: 

Have a look at CGL-MapReduce http://www.cs.indiana.edu/~jekanaya/cglmr.html#Matrix_Multiplication

martinus
A: 

Try using Memory Mapped File by storing all your data in an external file and access it via FileChannel object.

Check out this article for a brief introduction to MMF.

instcode
+1  A: 

First off, a 10 million x 10 million matrix is simply enormous. Assuming doubles for each cell and no storage overhaed, each one of these things is going to be 800 terabytes. Just reading each cell once over from main memory (should it somehow magically fit there, which clearly isn't happening), would take days. Doing it from any sort of plausible SAN (we'll put it on 10GbE) is more likely to be months. And no matrix multiply has O(n) complexity - the normal approaches are O(n^3). So... you aren't doing this with memory mapped files, common databases, or anything of that sort.

Code doing something like this is going to live or die on cache efficiency, where "cache" includes making good use of main memory, local disk drives. Since any storage interface holding more than one 800 terabyte matrix is bound to be a SAN of some sort, you almost certainly involve multiple servers reading and working on different parts of it, too.

There are lots of well-known ways to parallelise matrix multiplication (essentially multiply various-sized sub-matrices and then combining the results), and shift layout so that the access patterns have reasonable cache locality by organizing the data around space-filling curves instead of row/column arrangements. You're certainly going to want to look at the classic LAPACK interfaces and design, Intel's MKL, GotoBLAS as implementations of the BLAS functions tuned to specific modern hardware, and after that you're probably venturing into unexplored territory :-)

puetzk