Problem with Matrix very very big m [1000000] [1000000]. How to implement?

Greetings, I'm trying to implement a very large matrix with the following line of code:

int M [1000000] [1000000]

But it does not work for the million.

Can anyone explain the implementation: Add, Edit and Delete.

Thank you.
Last edited on
4*1000000*1000000 bytes ≈ 3725 GB

I doubt you have that amount of memory.
Last edited on
... and it's twice that on 64bit architecture.
Not necessarily. sizeof(int) is often 4 even with 64bit compilers.
What would be the implementation?. Someone there told me:

# include <iostream>
# include <vector>

using namespace std;

int main ()
{
FIL int = 10;
int COL = 10;
typedef vector <vector <int>> MATRIX;
MATRIX M;
<int> vector fil;
     for (int i = 0; i <FIL, i + +)
     {
         fil.clear ();
         for (int j = 0; j <COL, j + +)
             fil.push_back (COL + i * j +1);
         M.push_back (fil);
     }
}
but as added, modified and show. I am very clear. I also spoke of maps.
> Greetings, I'm trying to implement a very large matrix with the following line of code:
> int M [1000000] [1000000]

Isn't your matrix very sparse? Store it as a sparse matrix.

For instance, using boost uBlas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <boost/numeric/ublas/matrix_sparse.hpp>
#include <iostream>

int main ()
{
    constexpr std::size_t N = 1000000 ;
    boost::numeric::ublas::compressed_matrix<int> matrix( N, N );

    constexpr std::size_t stride = N / 100 ;
    for( std::size_t i = 0 ; i < N ; i += stride )
        for( std::size_t j = stride ; j < N ; j += stride )
            matrix(i,j) = i + j ;

    std::cout << matrix( 900000, 990000 ) << '\n' // 1890000
              << matrix( 900123, 990000 ) << '\n' ; // 0
}
NO USER --#include <boost/numeric/ublas/matrix_sparse.hpp>
You have to install Boost. It's a 3rd party C++ library.
http://www.boost.org/
Topic archived. No new replies allowed.