简体   繁体   中英

Matrix multiplication in java for large size 2 dimensional matrix

I am currently doing be project on sound processing, in this it requires to multiply the matrices, which contains data of the sounds,ie amplitudes, i have to process the matrix, mainly perform multiplication,but the number of elements in the matrix are too high...it goes near about 120000 elements from 600kb .wav file.

So when i perform multiplication it gives me an exception as...

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

Please suggest me a solution...

Sounds like you are doing something wrong. Its quite common to use more memory than the original data file but its rare to need more than 10x (Only compressed imagines come to mind)

I would suggest you use VisualVM to see why you are using so much memory. You may find the problem just by looking at the method which triggers the error (ie look at the stack trace)

Say you were to use 120,000 float for your amplitude, that is 480 KB which would fix on most mobile phones. BTW: Are you doing this on a phone?

There are two possibilities:

  1. You are trying to create a large matrix by accident. For example, matrix multiplication is not commutative and A*B can have very different size than B*A . The location of the exception should give a strong clue as to where to look for errors in your code.
  2. Your algorithm does actually need to create a huge matrix. There are several ways to try and tackle this:
    • give more RAM to the JVM;
    • instead of storing the entire huge matrix in memory at once, change the code so that you only store a part of it at any given time;
    • try to exploit the structure of the matrix (eg sparsity).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM