On Wed, Dec 21, 2022 at 8:07 PM Ak O <akin...@gmail.com> 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

Reply via email to