The mechanism here is presumably common knowledge,  but might be worth sharing.
Here's what I use to allocate half of the laptop's cores for use by J:

NB. Processor Affinity
coclass 'affin'
require'dll'

GetCurrentProcess=: >@{.@('kernel32 GetCurrentProcess i'&(15!:0))
GetProcessAffinityMask=: ('kernel32 GetProcessAffinityMask i i * *'&(15!:0))
SetProcessAffinityMask=: ('kernel32 SetProcessAffinityMask i i i'&(15!:0))

setproc =: 3 : 0
'rc tid pam sam'=.GetProcessAffinityMask (GetCurrentProcess'');(,2-2);(,2-2)
ppr=. ,I. (8#2)#: sam
NB. choose random half of cores
cores =. ((?~ <.@-: ) # ppr )
SetProcessAffinityMask tid;0{,(8#2)#. 1 cores }8#0
)

So the number of cores is
   # #: sam
and you only need GetProcessAffinityMask and GetCurrentProcess for that
information.

Cheers,

Mike

On 10/04/2022 23:49, Raul Miller wrote:
There's currently no rush for deciding this kind of thing.

We need some experience with this mechanism, first. And, before that,
we need to support Henry's efforts to sort out the rough edges.

But counting cpu cores is a relatively simple task, if slightly
obscure. So I thought I should leave a note here about that.

Thanks,

-- Raul On Sun, Apr 10, 2022 at 6:34 PM Hauke Rehr <hauke.r...@uni-jena.de> wrote:
why not have a command line argument providing a default number?
$USER may know better what they consider a good default

Am 11.04.22 um 00:31 schrieb Raul Miller:
It would be nice, I imagine, if we eventually had a mechanism like

https://www.cprogramming.com/snippets/source-code/find-the-number-of-cpu-cores-for-windows-mac-or-linux

to set up a default number of threads.

--
----------------------
mail written using NEO
neo-layout.org
----------------------------------------------------------------------
For information about J forums seehttp://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums seehttp://www.jsoftware.com/forums.htm


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to