- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am using the latest release of TBB for parallelizong my c++ finite element analysis application. I am facing trouble with the matrix assembly part, where each thread calculates a component of the global matrix and adds it to the global matrix (i.e., each thread is writing to a global variable). To facilitate this, I am using a spin_mutex lock. Unfortunately, every once in a while I miss one of the thread's contributions to the matrix, and the numerical computations blow-up.
Following is the structure of my code. I think I am using the spin_mutex correctly, but the the problem is random. Sometimes it happens after two iterations, and sometimes it takes 100 or so (and all possibilities in between). I would appreciate if someone could comment on whether there is an error in my use of the mutex, or if this is a known issue and there is a workaround.
I am using this on Mac OS 10.8.2. The hardware is: MacBook Air with 1.7 GHz Intel Core i5 with 4GB 1333 MHz DDR3 RAM.
Thanks,
Manav
Update: Found this to be an error in my code. Fixed and working fine now!
tbb::spin_rw_mutex assembly_mutex;
class AssembleElementMatrices
{
public:
AssembleElementMatrices(const std::vector<FESystem::Mesh::ElemBase*>& e,
FESystem::Numerics::VectorBase<FESystemDouble>& r,
FESystem::Numerics::MatrixBase<FESystemDouble>& stiff):
elems(e),
residual(r),
global_stiffness_mat(stiff)
{ }
void operator() (const tbb::blocked_range<FESystemUInt>& r) const
{
FESystem::Numerics::DenseMatrix<FESystemDouble> elem_mat;
FESystem::Numerics::LocalVector<FESystemDouble> elem_vec;
for (FESystemUInt i=r.begin(); i!=r.end(); i++)
{
// code to calculate elem_vec and elem_mat
{
tbb::spin_rw_mutex::scoped_lock my_lock(assembly_mutex, true);
dof_map.addToGlobalVector(*(elems[i]), elem_vec, residual); // adds elem_vec to appropriate locations in residual vector
dof_map.addToGlobalMatrix(*(elems[i]), elem_mat, global_stiffness_mat); // adds elem_mat to appropriate locations in the global_stiffness_mat matrix
}
}
}
}
protected:
const std::vector<FESystem::Mesh::ElemBase*>& elems;
FESystem::Numerics::VectorBase<FESystemDouble>& residual;
FESystem::Numerics::MatrixBase<FESystemDouble>& global_stiffness_mat;
};
void calculateQuantities()
{
const std::vector<FESystem::Mesh::ElemBase*>& elems = mesh.getElements();
tbb::parallel_for(tbb::blocked_range<FESystemUInt>(0, elems.size()), AssembleElementMatrices(elems, residual, global_stiffness_mat));
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page