# Is it possible to use BLAS if I have a function rather than a matrix?

My matrix sizes have grown beyond what can fit on the RAM but I have a function which defines each element cheaply.

Is it possible use BLAS (in Fortran or even in MATLAB) in such cases?

If I had a matrix in memory, I could use dgemv or dgemm or whatever and pass my matrix as one of the arguments. Now, I have no matrix. How do I tackle that?

I could write my own codes, but no matter what I do, I doubt my programming will be as thorough as the guys up at Intel MKL. There is simply too much to keep track of in such kind of programming.

EDIT: My matrix is dense. Almost full dense. I have a function in terms of indices $(i,j)$ and a $10^{6} \times 1$ vector. Like : $$f(i,j) = \frac{|a(i) + a(j)|}{(i-j)^2}$$

Also, I'm not saying I must use BLAS. I can use anything similar as long as it gets my job done. But as far as I know, there isn't any other library.

• BLAS is designed for dense matrices with explicit entries; I do remember that there are a number of sparse libraries that allow for a rule-based specification of entries, but I don't have my notes with me at the moment... – J. M. Feb 3 '12 at 6:33
• What do you want to do with this matrix? If you just want to multiply with a vector or another matrix, you should write that cod e yourself. If you want to factor the matrix, you will have to find the memory. If you want to solve systems or eigenvalue problems, you could use PETSc with MatShell. Depending on the problem, you might need a preconditioner. – Jed Brown Feb 3 '12 at 13:59
• I want DGEMV. I think, I'll write my own code then. – Inquest Feb 3 '12 at 14:04
• What will be the next step? Will you be able to hold the resulting vector in RAM as explicit entries? If not, I can see two options for what the result might look like: either as a function that can compute entries of the resulting product on demand (a lazy approach) or a function that writes results to disk. If the algorithm using your result reuses the same entries frequently, you could even construct a cache for entries requested frequently in the past. – Erik P. Feb 3 '12 at 18:10
• @JedBrown, do you mind restating your comment as answer? I don't want it to be missed by the community. – Aron Ahmadia Feb 4 '12 at 19:33

What do you want to do with this matrix? If you just want to multiply with a vector or another matrix, you should write that code yourself. If you want to factor the matrix, you will have to find the memory to store it. If you want to solve systems or eigenvalue problems, you could use PETSc with MatShell. Depending on the problem, you might need a preconditioner (which you might also be able to implement without assembling, if you like).
A famous example is the DFT (Discrete Fourier Transform) matrices which are dense, but if you factor them you can get a matrix representation for the FFT (Fast Fourier Transform) where each factor ideally has only 2 nonzero elements each row and there are only $\log(N)$ such matrices where $N$ is the data size.