compressed2D insertion

Burkhard Möller <[email protected]> Fri, 16 Oct 2009 12:52:10 +0200
Newsgroups gmane.comp.lib.mtl.devel
Message-ID <[email protected]>
Hi there,

I have an adjacency matrix of about 30000x30000 with ~200000 nonzero 
entries and I would like to use it with MTL. The matrix is in a file in 
matrix market format and I have slightly modified the first Matrix 
Insertion example to read it. The insertion of the first 100 elements 
already takes over 15 sec time, what am I doing wrong? I am using Visual 
Studio 2008 Express.

The source code is as follows:

// File: insert.cpp

#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

using namespace mtl;

template <typename Matrix>
void insval(Matrix& m, int index1, int index2, double val)
{
    // Matrices are not initialized by default
    m= 0.0;

    // Create inserter for matrix m
    matrix::inserter<Matrix> ins(m);
    
    // Insert value
    ins[index1][index2] << val;

}



int main(int argc, char* argv[])
{
    compressed2D<double>              A(30000, 30000);
    
    FILE* matrixfile;

    matrixfile=fopen("A_cpp.txt","r");

    int count=0, index1=0, index2=0;
    double value=0;

    clock_t start, finish;
    double duration;

    start = clock();

    while(fscanf(matrixfile, "%d %d %Lg", &index1, &index2, &value)!=EOF 
&& count<100){// insert first 100 values only
        count++;
        insval(A, index1-40360, index2-40360, value); // smallest index 
is 40360...
    }

    finish = clock();

    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    printf( "%2.1f seconds\n", duration );

    return 0;
}


Thanks for your time!

Rechnan
_______________________________________________
This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/