Hello J-beta team,

A brief setup below explores the interaction between multi-threaded
primitives, threads, and pools. There are two points and associated
questions.


As additional background for this, adding threads across pool 0 behaves as
expected: timing monotonically decreases with the addition of threads.


NB. 1) =========================================================

NB. Setup and a timing function for matrix multiplication primitive.


NB. Pool setup

syspools =. (8&T.)@(''&[)

delpools =. ([(55&T.))^:(1&T.)@(''&[) NB. pool clear: delpools y clears all
worker threads and pools

getpools =. ((2&T.)"0)@i. NB. pool stats: 'getpools 6' means get stats on
first six pools

setpools =. getpools@((#@;)"_)@:({{([(0&T.))^:({: y)
({.y)}}"1)@(,.~(i.@#))@([delpools)
NB. pool threadcount: 'setpools 0 2 2 3' creates 0 threads in pool 0, 2
thread in pool 1, ...

fmf =. {{1.01 * (y,y) $ ? (y^2) $ 2^62}}"0

'A B' =: fmf 2 # 1024

f =. {{(20) 6!:2 'A +/ . * B'}} NB. Matrix multiplication timing

uf =. {{u t. (y) ''}}"0 NB. Run u in threadpool y


NB. =========================================================

NB. Demonstrate multi-threading on primitives is oddly cyclical.

setpools 4

4 0 4

res =. > (((f uf)@0:))"0 (100 # 0)

syspools '' NB. 6 threads, 12 hyperthreads, in case this is related. Seems
like it shouldn't be.

12 63

(+/%#) _6 ]\ res NB. Only every 6th run appears to use multi-threaded
primitives

0.121716 0.121377 0.121108 0.121901 0.11124 0.0308138

*NB. Questions: What's the underlying behavior? Is this intended?*




NB. 2) =========================================================

NB. Docs say: "Parallelizable primitives use threadpool 0."


NB. Neither pool 0 or 1 appear to use multi-threaded primitives

setpools 0 5

0 0 0

5 0 5

> (f uf) 0,1 NB. Run timing for matrix multiplication in pools 0 and 1

0.118203 0.11434

NB. Both pools 0 and 1 appear to use multi-threaded primitives

setpools 4 1

4 0 4

1 0 1

> (f uf) 0,1 NB. Run timing for matrix multiplication in pools 0 and 1

0.0609 0.062134


NB. The docs seem to describe the threadpool model completely, but this
seems like an add model.

*NB. Questions:*

NB. Why wouldn't each pool use its own threads for multi-threaded
primitives?

NB. What's the point of creating a second pool with multiple threads,
rather than separate pools?

NB. How is resource contention between pools adjudicated?



Best,

John
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to