Boost logo

Ublas :

Subject: Re: [ublas] thread safety of matrix multiplication
From: James C. Sutherland (James.Sutherland_at_[hidden])
Date: 2009-11-25 17:11:51


On Nov 25, 2009, at 1:36 PM, Gunter Winkler wrote:

> Am Wednesday 25 November 2009 schrieb James C. Sutherland:
>> If I have a ublas matrix object, is it thread safe w.r.t. matvec
>> operations? In other words:
>>
>> typedef boost::numeric::ublas::compressed_matrix< double,
>> boost::numeric::ublas::row_major > MatType;
>>
>> MatType mat; // both threads use the same matrix object.
>> VecType a1, b1, a2, b2;
>>
>> // ... assemble matrix and vectors ...
>> // ...
>>
>> // thread 1 code:
>> axpy_prod( mat, a1, b1, true );
>>
>> // thread2 code:
>> axpy_prod( mat, a2, b2, true );
>>
>> Should this be thread safe? My observation is that it is NOT. I am
>> getting memory corruption somewhere.
>
> This is quite strange because axpy_prod only reads from the matrix and
> a1. The only write access is to b1. Can you try to build a small test
> program that shows the memory corruption?
>

Gunter, thanks for this confirmation. As it turns out, I think I was on the wrong path, and I think that the memory corruption may be coming from elsewhere. I will continue to investigate and let you know if anything turns up.

However, given that my interface to uBLAS ensures that the matrix object is const when axpy_prod is called, it is unlikely that uBLAS is corrupting memory unless there are mutable members or some const_cast going on internally.

Thanks again,

James