Ask Your Question
0

Parralel creation of cv::Mat crashes? Bug?

asked 2015-05-25 07:59:40 -0600

TobiasNoell gravatar image

Hi there,

I'm using OpenCV 3.0rc1 and Windows 7 (Visual Studio 2010) My problem is that the following code crashes randomly when using OpenMP for parallization. If I remove the OpenMP loop parallelization everything works fine.

#pragma omp parallel for
for(int i = 0; i < 100; i++)
{
    cv::Mat blub;
    blub.create(3456, 5184, 16);
    cout << ".";
}

The following exception is thrown OpenCV Error: Assertion failed (u != 0) in cv::Mat::create, file src\matrix.cpp, line 412

Can anyone reproduce / confirm this behavior?

edit retag flag offensive close merge delete

Comments

That line is inside a catch (...) and is not handling the exception. If you remove the try/catch you will be able to see what type of exception is thrown during run-time. Maybe some memory allocation failure? Does it work with a create() of smaller dimensions?

boaz001 gravatar imageboaz001 ( 2015-05-26 04:34:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-06-02 11:13:16 -0600

TobiasNoell gravatar image

Meanwhile I was digging a little bit further into the problem and I really think there is a bug in OpenCV.

In Mat::create the following code is executed

MatAllocator *a = allocator, *a0 = getStdAllocator();

which calls getStdAllocator. This is implemented as:

MatAllocator* Mat::getStdAllocator()
{
    static MatAllocator * allocator = new StdMatAllocator();
    return allocator;
}

i.e. returning a static local variable. When getStdAllocator() is executed in parallel this may crash (in my case it simply sometimes returns NULL).

I can get my example running by ensuring that the static local variable is initialized first, i.e.

cv::MatAllocator *a0 = cv::Mat::getStdAllocator();

#pragma omp parallel for
for(int i = 0; i < 100; i++)
{
    cv::Mat blub;
    blub.create(3456, 5184, 16);
    cout << ".";
}

But it seems to be fixed here already: http://code.opencv.org/issues/4189

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-05-25 07:59:40 -0600

Seen: 1,258 times

Last updated: Jun 02 '15