Re: [eigen] assembling a sparse matrix from multiple threads

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I think that one would have to be careful to avoid false sharing
	https://en.wikipedia.org/wiki/False_sharing
to make this efficient; i.e., the memory for each thread would need to be in separate cache.


On 07/05/2018 09:10 AM, Gael Guennebaud wrote:

Hi,

if you can guaranty that each column* is written by a single thread AND that you can predict a reasonable upper-bound for the number of non-zeros in each column*, then you can preallocate using reserve() and the subsequent writes within different columns will be thread safe.

* you can replace "column" by row if you use a row-majpr storage.

gael

On Thu, Jul 5, 2018 at 3:20 PM Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx <mailto:chtz@xxxxxxxxxxxxxxxxxxxxxxxx>> wrote:

    On 2018-07-05 14:37, Lorenzo Botti wrote:
     > 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?

    That would be true for a dense matrix, but for a sparse matrix that
    can't work (in general) since sometimes values are moved or memory gets
    re-allocated.

    To repeat it more clearly: An Eigen::SparseMatrix is _not_ inherently
    thread-safe (when values are inserted).


    Christoph



--   Dr.-Ing. Christoph Hertzberg

       Besuchsadresse der Nebengeschäftsstelle:
       DFKI GmbH
       Robotics Innovation Center
       Robert-Hooke-Straße 5
       28359 Bremen, Germany

       Postadresse der Hauptgeschäftsstelle Standort Bremen:
       DFKI GmbH
       Robotics Innovation Center
       Robert-Hooke-Straße 1
       28359 Bremen, Germany

       Tel.:     +49 421 178 45-4021
       Zentrale: +49 421 178 45-0
       E-Mail: christoph.hertzberg@xxxxxxx <mailto:christoph.hertzberg@xxxxxxx>

       Weitere Informationen: http://www.dfki.de/robotik
       -----------------------------------------------------------------------
       Deutsches Forschungszentrum fuer Kuenstliche Intelligenz GmbH
       Firmensitz: Trippstadter Straße 122, D-67663 Kaiserslautern
       Geschaeftsfuehrung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster
       (Vorsitzender) Dr. Walter Olthoff
       Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
       Amtsgericht Kaiserslautern, HRB 2313
       Sitz der Gesellschaft: Kaiserslautern (HRB 2313)
       USt-Id.Nr.:    DE 148646973
       Steuernummer:  19/672/50006
       -----------------------------------------------------------------------





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/