NB. par.ijs - Parallel execution utilities for J NB. Provides 'par' and 'parr' for easy parallel map operations NB. NB. Uses threadpool 1 (separate from pool 0 used by J primitives) NB. to avoid interference with other threaded operations. NB. ========================================================= NB. Configuration (in z locale for global access) NB. ========================================================= NB. Threadpool number for par operations (1 = separate from primitives) par_POOL_z_ =: 1 NB. Get number of CPU cores (8 T. '' returns corecount,maxthreads) par_cores_z_ =: {. 8 T. '' NB. ========================================================= NB. Thread pool management NB. ========================================================= NB. Initialize threadpool with n workers par_init_z_ =: 3 : 0 for_i. i. y do. 0 T. < par_POOL end. par_workers'' ) NB. Get worker count in our pool par_workers_z_ =: 3 : '{: 2 T. par_POOL' NB. Get pool statistics (idle, pending, total) par_status_z_ =: 3 : '2 T. par_POOL' NB. ========================================================= NB. Parallel execution adverbs/conjunctions NB. ========================================================= NB. par - Parallel map at rank _1 (items) NB. Usage: verb par array NB. Example: *: par i.100 NB. +/ par matrix NB. sum each row par_z_ =: 1 : '>@(u t. par_POOL "_1)' NB. parr - Parallel map conjunction with configurable rank NB. Usage: verb parr rank array NB. Example: *: parr 0 i.100 NB. each atom NB. +/ parr 1 matrix NB. each row parr_z_ =: 2 : '>@(u t. par_POOL " n)' NB. ========================================================= NB. Auto-initialize on load NB. ========================================================= NB. Initialize with cores-1 workers in pool 1 par_init par_cores - 1 smoutput 'par.ijs loaded: ', (": par_workers''), ' workers in pool ', (": par_POOL), ' (', (": par_cores), ' cores)'