forum.alglib.net
http://forum.alglib.net/

ALGLIB is thread-safe?
http://forum.alglib.net/viewtopic.php?f=2&t=767
Page 1 of 1

Author:  matthew_MP [ Fri Feb 01, 2013 8:15 pm ]
Post subject:  ALGLIB is thread-safe?

Briefly looking into the c++ source code for ALGLIB, it seems thread-safe to me. Are there any surprises? Can anybody confirm either way?

(I am looking to have different threads train different multinomial logistic models simultaneously...)

Author:  Sergey.Bochkanov [ Sat Feb 02, 2013 10:49 am ]
Post subject:  Re: ALGLIB is thread-safe?

As long as different threads work with different objects, it is thread-safe.

However, any way of sharing object with different threads is potentially risky - even when this object is used in "read-only mode". Sometimes seemingly "read-only" operations in fact modify internal state of the object. Say, processing data with neural network does not modify network weights and you may decide that it is "read only". But in fact it involves modification of internal temporary buffer. So you can not call mlpprocess() from two different threads with same network.

Author:  matthew_MP [ Wed Feb 13, 2013 4:24 pm ]
Post subject:  Re: ALGLIB is thread-safe?

Indeed, as you said, I did notice the modification of internal buffers of the "network" (multilayerperceptron) object within various functions. I am looking into the Multinomial Logsitc Regression training algorithm in detail (especially the gradient and Hessian functions called from mnltrainh) with the hope of multi-threading this training function, "mnltrainh".

Off the top of your head, can you say if any member objects of a "network" (multilayerperceptron) are modified other than the internal buffers? I am hoping that by replacing all instances of the internal buffers ("chunks" and "nwbuf") with local, temporary copies, then these algorithms will indeed be thread-safe. Can you offer any kind of reassurance or gut feeling either way?

Thank you!

Author:  Sergey.Bochkanov [ Thu Feb 14, 2013 7:51 am ]
Post subject:  Re: ALGLIB is thread-safe?

As for MultilayerPerceptron object, following fields can be modified by at least one "seemingly-read-only" function:

Quote:
Neurons: array of Real;
DFDNET: array of Real;
DError: array of Real;
X, Y: array of Real;
XY: array of array of Real;// Matrix buffer
XYRow: array of Real; // Row buffer for sparse matrix
Chunks: array of array of Real; // Buffer for batch processing
NWBuf: array of Real; // Buffer, array[0..max(wcount,2*nout)-1]
IntegerBuf: array of Integer; // Integer buffer, array[4]

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/