This can be done tacitly with modifier trains

 v2c =: 1 : '[. u ].'
Ft =: {{(t.'') u&> v2c (t. '')}}
Ftl =: {{]: u&> v2c (t. '')}}


 +/ % Ftl #
+/ %&> #t.''

+/ % Ft #
+/t.'' %&> #t.''


But, it seems like forks need to be tailored to domain, unless we'd escape some 
operations.  There is a high "copy data" overhead to starting a thread.  So, 
with t =: t. ''

@] t and @]~ t would always benefit from t @] or t@]~

monads # $ [ ] , ; ,. ,: {. {: |.|:.  and potentially others should probably 
never run on a thread due to instant result.  

Or if form  u@v@v t for any/all v's in above list, expression should be 
transformed as u t @v@v




On Monday, May 23, 2022, 09:48:47 p.m. EDT, Elijah Stone <[email protected]> 
wrote: 





I suggest using f (g >) h t.'' instead of f t.'' g&:> h t.'', as it is 
somewhat faster.

On Sun, 22 May 2022, Jan-Pieter Jacobs wrote:

> I've had some fun with parallel primitives and forks, and came up with two
> approaches that result in the exact same result, but have different sytax.
>
> The first converts to AR and replaces the verbs by applying (t.'') and (&>)
> to the outer and inner tines of the fork, respectively:
>
> NB. parallel single fork
> psf =: {{
> 'cod dat' =. > u toar
> if. '3'=cod do. NB. if fork
>  dat =. pf dat
> end.
> (< cod ,&< dat) 5!:0
> }}
>
> pf =: {{
> NB. Parallelise outer tines
>  y =. ((0 { y) 5!:0 t.''  toar) 0 } y
>  y =. ((2 { y) 5!:0 t.''  toar) 2 } y
> NB. Open to wait for tines to finish
>  y =. ((1 { y) 5!:0 &>  toar) 1 } y
> }}
>
> NB. adverb: convert u to atomic representation
> toar =: {{
> vb =. u f.
> ar =. 5!:1<'vb' }}
>
>  (+/%#) psf
> +/t.'' %&:> #t.''
>
> Of course, in this simplistic example, the parallel version is slower,
> because the outer tines are so simple, but on more complicated verbs, I can
> imagine it gains some speed. Note that any side-effects the outer tines
> would have would become evidently unreliable as to their execution order.
>
> The second approach uses a tie and `:6 to create a conjunction to be
> applied between middle and last tine, that returns an adverb that will take
> the left tine, and combine it into a fork. Likely it can be written
> tacitly, but I did not yet spend enough time learning tacit modifiers
> trains.
>
> NB. parallel fork, conjunction.
> pfr=: {{ (t.'')(`(u&:>))(`(v t.''))(`:6)}}
>
> +/ % pfr #
> +/t.'' %&:> #t.''
>
> This luckily works fine for combinations in other verbs and even nested
> application, e. g. the hypothetical (sorry, couldn't come up with an
> example that made sense)
>
> $ +/ % prf # ?
> $ (+/t.'' %&> #t.'') ?
>
>  $ +/ % prf # prf ?
> $t.'' (+/t.'' %&> #t.'')&> ?t.''
>
> I guess there's something to say for both approaches. The first is certaily
> more wordy, but I think it could be extended to recursing through an AR and
> parallelising where it makes sense (based on some yet-to-be-defined metric).
> The second one requires the user to be aware of parallelisation (also
> allowing more targeted application), and adapt their code to make use of
> it. It also has a lot less moving parts.
>
> I hope someone finds this useful.
>
> Jan-Pieter
> ----------------------------------------------------------------------
> 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

Reply via email to