|Re: [eigen] assembling a sparse matrix from multiple threads|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] assembling a sparse matrix from multiple threads
- From: Lorenzo Botti <bottilorenzo@xxxxxxxxx>
- Date: Thu, 5 Jul 2018 14:37:54 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=gAelyWzbgo/7lvdjGQyoBzLacCgWlpv3acSyB2dKIsA=; b=eRmPmigu+OHPU5BUm26hhAs7zfaL9HQTy5T90xqbuBgWve0aEFlZFmadEGEsZ8RJXA 6qVdi/dLVc+ChpJmDJxR2jz9/7ckKq0zaqTCn+OSd4AU7SwrLHIVWjHcWqGgMKD0muQK wooH2XH84Rrd7SACbjXmC4gO0r26VOijUEBIqh1bFqgUZWBdaNKD+ysy2+yR/thgVOUm UlVuc4fvIs2SFpJ80PqLnhLeLgVnLyW2DGc2SFvhz6b7thQ3qk2EkAbZP9xeAc4v41zf 3S12S4yFrvkxZVq866pi/wHX0sSs+o+Niqby6kAAwmI6+U5KWOlngJzYdGa0xQXGRcxn mHmw==
However, there is no synchronization happening. If you insert from
multiple threads, you need to lock the access to the matrix, which most
certainly is less efficient than inserting from a single thread.
You have the same problem when inserting values into a std::vector from
The point here is that I know that the code is thread safe, that is no more than one thread will try write in position row i col j.
Accondingly performing the assembly in parallel should not required to lock the insertion operation, am I wrong?
Inserting into a single std::vector has similar synchronization
problems, so maybe collecting a vector for each thread is an option
(which then need to be concatenated, ideally without actually copying
Yes, exactly. If I do that the code works just fine.