Floating point exception in dense vector even when not doing calculations

19 views
Skip to first unread message

tom murtha

unread,
Mar 24, 2018, 1:56:22 PM3/24/18
to linbox-use
Hello,

I'm trying to run the code appended to the bottom, but I receive a floating point exception at certain times when dealing with the vector "dummy", even when not doing calculations. In this code the error pops up during a print statement. I tried calculating a few of the vectors that mess up by hand, but there's no obvious patterns. It doesn't even have to contain zeros or something that might commonly cause a floating point exception. Do you know what may be causing this error?

Thanks,
-Tom

#include <linbox/linbox-config.h>

#include <iostream>
#include <time.h>
#include <stdlib.h>

#include <givaro/modular.h>
#include <givaro/zring.h>
#include <linbox/matrix/sparse-matrix.h>
#include <linbox/solutions/solve.h>
#include <linbox/util/matrix-stream.h>
#include <linbox/solutions/methods.h>

using namespace LinBox;
using namespace std;
/* This program should hopefully generate a random sparse matrice with controlled
density and use linbox to solve it. Mostly its just going to be a frankensteins
monster of copy pasted linbox example code with some prayers it compiles and runs*/


int main (int argc, char **argv)
{
    srand(time(NULL));
    int entry = 0;
    int value;
    bool notentered = true;
    Timer timing;
    Givaro::ZRing<Integer> ZZ;
    Givaro::ZRing<Integer>::Element d;
    for(int width = 0; width < 10; width++)
    {
        for(int density = 0; density < 10; density++)
        {
            timing.clear();
            for(int runs = 0; runs < 15 - width; runs++)
            {
                DenseVector<Givaro::ZRing<Integer>> vect(ZZ, 1 << (width+2)), dummy(ZZ, 1 << (width+2));
                SparseMatrix<Givaro::ZRing<Integer>> matrx(ZZ, 1 << (width+2), 1 << (width+2) );
                for(int row = 0; row < (1 << (width+2)); row++)
                {
                    for(int entries = 0; entries < (1 << density); entries++)
                    {
                        entry = (rand()%(1 << (width+2)));//Error not with this line
                        notentered = true;

                        while(notentered)//Error not in this while
                        {
                            if(matrx.getEntry(row, entry) == 0)
                            {
                                value = (rand()%20 - 10);
                                if(value == 0) value++;//make sure it aint 0

                                matrx.setEntry(row, entry, value);
                                notentered = false;
                            }
                            else
                            {
                                entry = (rand()%(1 << (width+2)));
                            }
                        }//After this while there's a matrix with random entries
                       
                        //Error not in this loop
                        for(DenseVector<Givaro::ZRing<Integer>>::iterator it=vect.begin(); it != vect.end(); ++it)
                        {
                            *it = (rand()%20 - 10);
                        }//Now we have a RHS vector

                        matrx.apply(dummy, vect); //Error not here
                       
                    }//end entries for
                }//end row for
                timing.start();

                cout <<"in\n";//somehow the error occurs
                cout << dummy;//between these two lines
                solve (vect, d, matrx, dummy, Method::SparseElimination());
                cout <<"Hello\n";

                timing.stop();
            }//end runs for
            cout << (1 << (width+2)) << " " << (1 << density) << " " << timing.usertime()/(15 - width) << endl;
        }//end density for
    }//end width for


    return 0;
}
LinboxIntTimes.C
Reply all
Reply to author
Forward
0 new messages