Page 1 of 1

Threads=x?

PostPosted: Mon Jun 24, 2019 8:34 am
by j.harv3y
Hi,
I'm not sure if I've missed this in the handbook, but I can't seem to find an explanation to the threads= command? I've gathered its something to do with the processing in MARK, but am unsure what number I need to put after threads. Could someone explain please?

Code: Select all
e.g model.1=mark(crdms.data,ddl=crdms.ddl,
   model.parameters=list(S=S.dot,
      p=p.session,
      Psi=Psi.markov),threads=2)


Thanks a million!

Jess

Re: Threads=x?

PostPosted: Mon Jun 24, 2019 8:55 am
by cooch
The threads command line defaults to 0, which means it uses all the threads available to run. Meaning, using the default will run fastest, but at the expense of tying up the CPU for other tasks. If you want to use fewer than the maximum number of threads, you debit from the default:

--threads=0 <-- use all possible threads (i.e., the debit from maximum is 0)

--threads=-1 <-- use one thread less than maximum

--threads=-2 <-- use two threads less than maximum

and so on. The maximum number of threads is determined by the architecture of the CPU -- some chips have more threads than others (note: more threads does not always make things run faster -- it only benefits routines that are coded to take advantage of multi-threaded execution. For MARK, there is definitely a gain in using more threads, but generally the gain is only noticeable for bug data sets anbd complex models).

Re: Threads=x?

PostPosted: Mon Jun 24, 2019 3:21 pm
by jlaake
Every argument to a function in RMark is documented in the help to the function. See ?mark. That is the case with any R package on Cran. I had to use thread=2 in the examples to satisfy Cran requirements.

Re: Threads=x?

PostPosted: Mon Jun 24, 2019 4:04 pm
by cooch
Jeff -- just for completeness -- the CLI syntax for threads is

mark.exe --threads=-2 etc. etc.

In other words, the --threads argument is either 0 (use all the threads) or negative (being the number ,less than all threads). So, --threads=-2 would be 2 less than maximum number of threads.

In your example, you have threads=2, (i.e., positive 2) which actually wouldn't be interpreted correctly by mark.exe. Is the RMark threads argument a wrapper that changes things to the right thing to pass to mark.exe?

Re: Threads=x?

PostPosted: Mon Jun 24, 2019 4:19 pm
by jlaake
Okay. What I thought Gary told me was 0 for all CPUs, positive to specify the number to use and negative to set aside a set of CPUs. Are you saying a positive value doesn't work? Because I believe I checked that.

Re: Threads=x?

PostPosted: Mon Jun 24, 2019 4:45 pm
by cooch
jlaake wrote:Okay. What I thought Gary told me was 0 for all CPUs, positive to specify the number to use and negative to set aside a set of CPUs. Are you saying a positive value doesn't work? Because I believe I checked that.



You're correct. From the MARK helpfile:

A value of 0 tells MARK to use all possible threads, a positive value says to use that many threads <= the maximum available, and a negative value says to use that many less than the maximum number of threads possible. The default value is zero, i.e., use all the threads available on a machine.


I was basing my 'insight' (or lack thereof, it seems) on an earlier incarnation of threading in MARK. So, if your CPU has 4 threads, then using --threads=2 or threads=-2 would amount to the same thing. OTOH, --threads=1 would mean...1 thread, whereas --threads=-1 would mean (4-3)=3 threads.

Re: Threads=x?

PostPosted: Tue Jul 02, 2019 5:02 am
by j.harv3y
Amazing, thanks so much