To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
Engine: j9.8.0-beta2/j64avx2/windows
Build: commercial/2026-05-08T16:41:51/clang-19-1-5/SLEEF=1
Library: 9.8.2
Qt IDE: 2.6.3/6.10.3(6.10.3)
OS Ver: Windows 11 Version 25H2 10.0.26200
Platform: Win 64
Installer: j9.8 install
InstallPath: d:/programs/j9.8
Contact: www.jsoftware.com
]'corecount maxthreads' =: 8 T. ''
16 63
Sample Code [1] runs with one line commented out:
NB. anchor 'resarea' NB. anchor it
Follow-up questions:
1/ allthreads=: t. (< 'locales' ; 16bff) What value should I pass for running on 16 cores?
2/ Domain error - how can I fix it? What is the consequence of not fixing resarea?
anchor 'resarea'
|domain error in anchor, executing monad 1&(15!:24)
| anchor'resarea'
|[-1]
3/ All smoutput calls are buffered and written after the program exits. How can I get J to output progress as the execution proceeds?
4/ What is a pyx that is referenced in the https://code.jsoftware.com/wiki/Vocabulary/tcapdot wiki?
Thanks,
Yuva
[1] Handwritten using image from video - may have errors
NB. Library definitions
smoutput 'Library functions'
amv =: 16&T. NB. Create AMV with starting value y
NB. AMV stands for Atomically Modifiable Value (AMV)
amvadd =: 17 T. (,<) NB. add y to AMV x, return old x
delth =: {{while. 1 T. '' do. 55 T. '' end. EMPTY }} NB. delete all worker threads anchor=1&(15!:24)
anchor =: 1&(15!:24) NB. Indicate that y~ is not to be moved or aliased
ts =: 6!:2 NB. time sentence
NB. Machine-dependent one-time thread initialization
22 T. 0;1 NB. Run the master thread in core 0
NB. Clear threads, then allocate one thread for each P core, plus 4 others
(0 T. [: < 'coremask';2&^)"0 (2 4 6 8 10 12 14) [ delth''
NB. coremask is not supported for Mac or OpenBSD
NB. Adverb to run on 8 cores
allthreads=: t. (< 'locales' ; 16bff)
NB. The code:
resarea =: 1000$00 NB. Allocate result area
NB. anchor 'resarea' NB. anchor it
smoutput 'Test functions'
NB. y is number, result is # Collatz iterations required to finish
collatz =: {{
t =. 0
while. 1 < y do.
t=. >: t NB. increment loop count
if. 2 | y do. NB. Test even/odd
y=. 1 3 p. y NB. odd, replace y by 3y+1
else. y =. y % 2x NB. even, replace y by y/2
end.
end.
t}} NB. Return loop count when y goes to 1
NB. x is start of collatz interval, y is AMV of #values to calculate
NB. Repeatedly take a value, run collatz, store the result in (resarea)
NB. Result is empty
colint =: {{
while. 0 <: i =. <: y amvadd _1 do. NB. Get next # to try in descending sequence
resarea =: (collatz x+i) i} resarea NB. store its Collatz count into the result
end.
''}} NB. return empty
NB. Single thread compute
smoutput 'Single Thread Compute'
smoutput ts '(3x ^ 10) colint amv # resarea' NB. init # results and run
NB. x in 3x stands for extended precision
smoutput ts '(3x ^ 1000) colint amv # resarea' NB. init # results and run
smoutput +/resarea
NB. Multi-thread compute
smoutput 'Multi-Thread Compute'
smoutput ts '(3x ^ 1000) colint allthreads amv # resarea' NB. init # results and run
If you don't want to trouble looking up your core details you could create 15 worker threads with
0 T."1 i. 15 0 [ delth''
and let the OS assign them to cores.
Here is what I get on my machine
22 T.0
65535
1/ Does this mean 'coremask' on my machine is 65535?
(0 T. [: < 'coremask';2&^)"0 (2 4 6 8 10 12 14) [ delth''
3/ And how is this expression a simplification of the above for 16 cores?
0 T."1 i. 15 0 [ delth''