AngouriMath
GenTensorGuard
Description
Summary
Makes the matrix operations that go through GenericTensor safe to call from more than one
thread, which Multithreading documents as supported.
thread, which Multithreading documents as supported.
Remarks
GenericTensor 1.0.4 keeps two process-wide mutable statics, and neither fails loudly.
Reported upstream as https://github.com/asc-community/GenericTensor/issues/40 with a fix in
https://github.com/asc-community/GenericTensor/pull/41; this type is what stands in until a
release carrying that fix exists, and it should be deleted when one does.
The two need opposite treatments, because only one of them can be closed without a lock:
The scratch-matrix pool behindDeterminantLaplace and Adjoint hands
every caller the same tensor for a given size, and the caller writes into it. There is
nothing to warm and no way to avoid it from out here, so those calls take
ScratchPool. Measured on GenericTensor's own suite, sixty 5x5 matrices
computed sequentially and then again in parallel: 53 of 60 Laplace determinants and 60 of
60 adjugates came back with different values. Serialising them is the cost of not doing
that.
The compiled-operation cache behind the piecewise operators is an unsynchronised
Dictionary , so it is only unsafe while it is being filled -- once an entry is there
the reads are pure. That one needs no lock at all, because the set of entries this library
can ever ask for is fixed and tiny: Matrix rejects any tensor that is
not rank 2, and every call here uses the default single-threaded mode, so the only keys
reachable are addition, subtraction and multiplication at rank 2. Filling all three once,
under Lazy`1, leaves the dictionary read-only from then on.
Reported upstream as https://github.com/asc-community/GenericTensor/issues/40 with a fix in
https://github.com/asc-community/GenericTensor/pull/41; this type is what stands in until a
release carrying that fix exists, and it should be deleted when one does.
The two need opposite treatments, because only one of them can be closed without a lock:
The scratch-matrix pool behind
every caller the same tensor for a given size, and the caller writes into it. There is
nothing to warm and no way to avoid it from out here, so those calls take
ScratchPool. Measured on GenericTensor's own suite, sixty 5x5 matrices
computed sequentially and then again in parallel: 53 of 60 Laplace determinants and 60 of
60 adjugates came back with different values. Serialising them is the cost of not doing
that.
The compiled-operation cache behind the piecewise operators is an unsynchronised
the reads are pure. That one needs no lock at all, because the set of entries this library
can ever ask for is fixed and tiny: Matrix rejects any tensor that is
not rank 2, and every call here uses the default single-threaded mode, so the only keys
reachable are addition, subtraction and multiplication at rank 2. Filling all three once,
under Lazy`1, leaves the dictionary read-only from then on.
Members
ScratchPool
Field
Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 4378 pages online