Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
I am not sure. But you can check the number of thread created. On Thu, 22 Dec 2022 at 2:28 PM Ak O wrote: > Thank you Bill, > > Are these two lines equivalent? > > T.&''"0 (|change)#(*change){1 0 55 > > 0''0^:(0 < #)1$~(1>. (<:MAXTHREADS)-1 T.'') > > > Raul's example: > > setthreadcount=: {{ > change=. y-1 T.'' > T.&''"0 (|change)#(*change){0 0 55 > 1 T.'' >}} > > > Ak. > > > On Wed., Dec. 21, 2022, 19:20 bill lam, wrote: > > > create thread pool: > > MAXTHREADS_z_=: {: 8 T.'' > > echo 'MAXTHREADS: ',": MAXTHREADS > > 3 : 0'' > > if. 1 > 0"0^:(0 < #) 0$~ (1 >. (<:9!:56'cores') <. (<:MAXTHREADS)- 1 T. '') > > echo 'thread pool#0: ', ": n1=. 1 T. '' > > 0"0^:(0 < #) 1$~ (1 >. (<:MAXTHREADS)- 1 T. '') > > echo 'thread pool#1: ', ": (1 T. '') - n1 > > end. > > ) > > > > for cpu intensive tasks > > f1 t.(0;<'worker';1)"0 foo > > > > for i/o bound tasks > > g t.(1;<'worker';1)"0 bar > > > > > > > > > > On Thu, Dec 22, 2022 at 9:53 AM Ak O wrote: > > > > > Hi Bill, > > > > > > How is a threadpool assigned? > > > For clarity, can you please show two sample commands? > > > The command that creates threads in threadpool 0. > > > The command that creates threads in threadpool 1. > > > > > > Thank you for your help. > > > > > > Ak > > > > > > > > > > > > > > > > -- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > -- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > -- > For information about J forums see http://www.jsoftware.com/forums.htm > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
Thank you Bill, Are these two lines equivalent? T.&''"0 (|change)#(*change){1 0 55 0''0^:(0 < #)1$~(1>. (<:MAXTHREADS)-1 T.'') Raul's example: setthreadcount=: {{ change=. y-1 T.'' T.&''"0 (|change)#(*change){0 0 55 1 T.'' }} Ak. On Wed., Dec. 21, 2022, 19:20 bill lam, wrote: > create thread pool: > MAXTHREADS_z_=: {: 8 T.'' > echo 'MAXTHREADS: ',": MAXTHREADS > 3 : 0'' > if. 1 0"0^:(0 < #) 0$~ (1 >. (<:9!:56'cores') <. (<:MAXTHREADS)- 1 T. '') > echo 'thread pool#0: ', ": n1=. 1 T. '' > 0"0^:(0 < #) 1$~ (1 >. (<:MAXTHREADS)- 1 T. '') > echo 'thread pool#1: ', ": (1 T. '') - n1 > end. > ) > > for cpu intensive tasks > f1 t.(0;<'worker';1)"0 foo > > for i/o bound tasks > g t.(1;<'worker';1)"0 bar > > > > > On Thu, Dec 22, 2022 at 9:53 AM Ak O wrote: > > > Hi Bill, > > > > How is a threadpool assigned? > > For clarity, can you please show two sample commands? > > The command that creates threads in threadpool 0. > > The command that creates threads in threadpool 1. > > > > Thank you for your help. > > > > Ak > > > > > > > > > > > -- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > -- > For information about J forums see http://www.jsoftware.com/forums.htm > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
Oh, wait.. I guess I'm ignorant of the thread grouping issues. Please ignore this previous email. Thanks, -- Raul On Wed, Dec 21, 2022 at 10:55 PM Raul Miller wrote: > > Note that you could have used the 'setthreadcount' implementation for this: > > setthreadcount <:{:8T.'' > > However, I'm not sure that creating the maximum number of threads is > going to be the most efficient approach. (In some cases it might be.) > > Also, I'm realizing that I should have included that decrement > operation in settheadcount. (It makes more sense to talk about the > total number of threads than the number of worker threads.) > > Thanks, > > -- > Raul > > On Wed, Dec 21, 2022 at 9:20 PM bill lam wrote: > > > > create thread pool: > > MAXTHREADS_z_=: {: 8 T.'' > > echo 'MAXTHREADS: ',": MAXTHREADS > > 3 : 0'' > > if. 1 > 0"0^:(0 < #) 0$~ (1 >. (<:9!:56'cores') <. (<:MAXTHREADS)- 1 T. '') > > echo 'thread pool#0: ', ": n1=. 1 T. '' > > 0"0^:(0 < #) 1$~ (1 >. (<:MAXTHREADS)- 1 T. '') > > echo 'thread pool#1: ', ": (1 T. '') - n1 > > end. > > ) > > > > for cpu intensive tasks > > f1 t.(0;<'worker';1)"0 foo > > > > for i/o bound tasks > > g t.(1;<'worker';1)"0 bar > > > > > > > > > > On Thu, Dec 22, 2022 at 9:53 AM Ak O wrote: > > > > > Hi Bill, > > > > > > How is a threadpool assigned? > > > For clarity, can you please show two sample commands? > > > The command that creates threads in threadpool 0. > > > The command that creates threads in threadpool 1. > > > > > > Thank you for your help. > > > > > > Ak > > > > > > > > > > > > > > > > -- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > -- > > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
Note that you could have used the 'setthreadcount' implementation for this: setthreadcount <:{:8T.'' However, I'm not sure that creating the maximum number of threads is going to be the most efficient approach. (In some cases it might be.) Also, I'm realizing that I should have included that decrement operation in settheadcount. (It makes more sense to talk about the total number of threads than the number of worker threads.) Thanks, -- Raul On Wed, Dec 21, 2022 at 9:20 PM bill lam wrote: > > create thread pool: > MAXTHREADS_z_=: {: 8 T.'' > echo 'MAXTHREADS: ',": MAXTHREADS > 3 : 0'' > if. 1 0"0^:(0 < #) 0$~ (1 >. (<:9!:56'cores') <. (<:MAXTHREADS)- 1 T. '') > echo 'thread pool#0: ', ": n1=. 1 T. '' > 0"0^:(0 < #) 1$~ (1 >. (<:MAXTHREADS)- 1 T. '') > echo 'thread pool#1: ', ": (1 T. '') - n1 > end. > ) > > for cpu intensive tasks > f1 t.(0;<'worker';1)"0 foo > > for i/o bound tasks > g t.(1;<'worker';1)"0 bar > > > > > On Thu, Dec 22, 2022 at 9:53 AM Ak O wrote: > > > Hi Bill, > > > > How is a threadpool assigned? > > For clarity, can you please show two sample commands? > > The command that creates threads in threadpool 0. > > The command that creates threads in threadpool 1. > > > > Thank you for your help. > > > > Ak > > > > > > > > > > > -- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > -- > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
On Wed, Dec 21, 2022 at 8:07 PM Ak O wrote: > setthreadcount=: {{ > change=. y-1 T.'' > T.&''"0 (|change)#(*change){0 0 55 > 1 T.'' > }} > > To accomplish this, you might use a routine like > setthreadcount=: {{ >change=. y-1 T.'' > -NB. Does this set 'change' to a maximum of one less than the number of > cores? Yes. This would typically be done in a one time setup, perhaps best done in your profile.ijs >T.&''"0 (|change)#(*change){0 0 55 > -NB. Does this provide (pass) the attributes to each thread created by > execution of this routine? I do not understand your question. > -NB. What does 0 0 55 specify? 0 T. '' creates one thread 55 T.'' disposes of one thread (scheduled for the future if that thread is still busy). *changes produces a _1 if there's currently more threads than requested, a 1 if there's currently less threads than requested and a 0 if there's the right amount. So (*changes){0 0 55 produces a 55 if there's too many threads, and otherwise produces a 0. This result is replicated to match the number of threads which need to be added or discarded. (|7)#(*7){0 0 55 0 0 0 0 0 0 0 (|_4)#(*_4){0 0 55 55 55 55 55 > -NB. (Aside) How are tasks passed to a thread that's what (t.) does. >1 T.'' > -NB. Does this return the number of threads created by execution of this > routine? It returns the total number of "worker threads" (which I think is all threads except for the master thread which always runs -- though it's possible that there's a temporary condition after 55 T. '' where some other thread might be running but not classified as a worker thread. (I was not aware of this possibility when I wrote the message you were responding to here.)) > setthreadcount <:{.8T.'' > -NB. Does this create less than or equal to the number of cores on the > executing system? If you have four cores, this would set the number of worker threads to 3. <:4 NB. decrement 3 > -NB. How about cases where operations might lean on boxing? > Overhead (maybe unnecessary)can quickly accumulate with boxing. Overhead is not the only issue here (though it is an issue). Communication times (including cache invalidation) and synchronization comes into play in threading contexts. Anyways, measurement winds up being important, and J's timex routine measures the time it takes to execute a sentence. > I appreciate your help. Thanks, -- Raul -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
create thread pool: MAXTHREADS_z_=: {: 8 T.'' echo 'MAXTHREADS: ',": MAXTHREADS 3 : 0'' if. 1. (<:9!:56'cores') <. (<:MAXTHREADS)- 1 T. '') echo 'thread pool#0: ', ": n1=. 1 T. '' 0"0^:(0 < #) 1$~ (1 >. (<:MAXTHREADS)- 1 T. '') echo 'thread pool#1: ', ": (1 T. '') - n1 end. ) for cpu intensive tasks f1 t.(0;<'worker';1)"0 foo for i/o bound tasks g t.(1;<'worker';1)"0 bar On Thu, Dec 22, 2022 at 9:53 AM Ak O wrote: > Hi Bill, > > How is a threadpool assigned? > For clarity, can you please show two sample commands? > The command that creates threads in threadpool 0. > The command that creates threads in threadpool 1. > > Thank you for your help. > > Ak > > > > > > -- > For information about J forums see http://www.jsoftware.com/forums.htm > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
Hi Bill, How is a threadpool assigned? For clarity, can you please show two sample commands? The command that creates threads in threadpool 0. The command that creates threads in threadpool 1. Thank you for your help. Ak > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
Hi Ed, I hope you are well. If you are willing, do you mind sharing a comparison of the routine that you improved (with some commentary)? Ak > > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
It would be sufficient to create threadpool when starting an application. No need to bother how many threads are available inside the application. Eg if your machine has 8 CPU, then create 7 threads for pool 0 (for CPU bounded tasks) and 56 threads for pool 1 (for I/O bounded tasks) On Thu, Dec 22, 2022, 9:07 AM Ak O wrote: > Thank you Raul, > > > Conceptually, the primitives are simple. T. is for configuration and > setup. You always have one thread (the master thread), and you > probably should have one additional thread for each cpu "core" (which > you might think of as a register set -- a small set of variables that > represent the machine itself). > -NB. This is important know. Thank you. > > setthreadcount=: {{ > change=. y-1 T.'' > T.&''"0 (|change)#(*change){0 0 55 > 1 T.'' > }} > > To accomplish this, you might use a routine like > setthreadcount=: {{ >change=. y-1 T.'' > -NB. Does this set 'change' to a maximum of one less than the number of > cores? >T.&''"0 (|change)#(*change){0 0 55 > -NB. Does this provide (pass) the attributes to each thread created by > execution of this routine? > -NB. What does 0 0 55 specify? > -NB. (Aside) How are tasks passed to a thread >1 T.'' > -NB. Does this return the number of threads created by execution of this > routine? >}} > setthreadcount <:{.8T.'' > -NB. Does this create less than or equal to the number of cores on the > executing system? > > > * > > > ...That said, I haven't found any good candidates for > threading, yet. (By this I mean: simple code which gets improved > performance using (t.'') (or (t.{{)n}})) vs using (<@) > > -NB. How about cases where operations might lean on boxing? > Overhead (maybe unnecessary)can quickly accumulate with boxing. > > I appreciate your help. > > Ak. > > > > > > > > > > -- > For information about J forums see http://www.jsoftware.com/forums.htm > -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Thread Primitives -> Execute as task (t.)
Thank you Raul, Conceptually, the primitives are simple. T. is for configuration and setup. You always have one thread (the master thread), and you probably should have one additional thread for each cpu "core" (which you might think of as a register set -- a small set of variables that represent the machine itself). -NB. This is important know. Thank you. setthreadcount=: {{ change=. y-1 T.'' T.&''"0 (|change)#(*change){0 0 55 1 T.'' }} To accomplish this, you might use a routine like setthreadcount=: {{ change=. y-1 T.'' -NB. Does this set 'change' to a maximum of one less than the number of cores? T.&''"0 (|change)#(*change){0 0 55 -NB. Does this provide (pass) the attributes to each thread created by execution of this routine? -NB. What does 0 0 55 specify? -NB. (Aside) How are tasks passed to a thread 1 T.'' -NB. Does this return the number of threads created by execution of this routine? }} setthreadcount <:{.8T.'' -NB. Does this create less than or equal to the number of cores on the executing system? * ...That said, I haven't found any good candidates for threading, yet. (By this I mean: simple code which gets improved performance using (t.'') (or (t.{{)n}})) vs using (<@) -NB. How about cases where operations might lean on boxing? Overhead (maybe unnecessary)can quickly accumulate with boxing. I appreciate your help. Ak. > > -- For information about J forums see http://www.jsoftware.com/forums.htm