Menu

SIGSEGV allocating matrix

2013-05-23
2013-06-12
  • Peter Burka

    Peter Burka - 2013-05-23

    The following code causes a SIGSEGV on Linux:

    #include <iostream>
    #pragma GCC diagnostic ignored "-Wshadow"
    #include <viennacl/matrix.hpp>
    int main()
    {
        const size_t rows = 1;
        const size_t cols = 600;
        double foo[rows][cols] = { };
        viennacl::matrix<double> bar(rows, cols);
        viennacl::fast_copy(&foo[0][0], &foo[rows][cols], bar);
        std::cout << "OK" << std::endl;
    }
    

    The crash seems to depend on the size. Small matrices are ok (e.g. 1,32), but larger ones cause the SIGSEGV.

    I'm using gcc 4.4.1, which I know is a bit dated. Can other users reproduce this?

     
  • Peter Burka

    Peter Burka - 2013-05-23

    I'm 0 for 2 today. This is also my bug. It should be

    viennacl::fast_copy(&foo[0][0], &foo[rows[b]-1[/b]][cols], bar);
    
     
  • Karl Rupp

    Karl Rupp - 2013-05-23

    Hey,
    a great tool for finding any memory access violations is Valgrind, which would have complained about this right away. Also, switch on high warning levels, as compilers may also be able to complain in such case.

    On the other hand, keep in mind that multi-dimensional arrays may not represent a linear region or memory (if allocated as arrays of pointers to arrays), in which fast-copy will fail…

    Best regards,
    Karli

     
  • Peter Burka

    Peter Burka - 2013-05-23

    Valgrind is a great tool, but it wouldn't have helped me here. I already knew there was memory corruption; I just blamed the wrong component.

    A quick note about fast_copy(). The arguments to fast_copy() are SCALARTYPE *, where SCALARTYPE is float or double. Is there any reason these aren't const SCALARTYPE *?

     

Log in to post a comment.