On 14 May 2025 at 15:18, smallepsilon wrote:
| Ben,
| 
| No need to apologize. I hope the following example helps clarify what I mean. 
Suppose that modify_matrix(mat, other_args) is a function that, among other 
things, applies eigen() to mat. For good reasons, other_args has no default 
value. It is sometimes convenient, though, to supply the user with default 
values. Therefore, there is another function, convenient_modify_matrix():
| 
| convenient_modify_matrix(mat) <- function(mat) modify_matrix(mat, other_args 
= default).
| 
| To help verify that the code is correct, I want to check the result from 
identical() below:
| 
| set.seed(20250514)
| A <- modify_matrix(mat, other_args = default)
| set.seed(20250514)
| B <- convenient_modify_matrix(mat)
| identical(A, B)
| 
| In an ideal world, the result would be TRUE. The results can differ, though, 
because of multithreading (synonymous with parallel computation, yes?) used by 
the code underlying eigen(). As I understand it, this occurs when calling 
LAPACK/BLAS routines on some systems (e.g., MKL). Can that multithreading be 
turned off? Searching online shows that there is a lot of interest in turning 
it on; not so much in turning it off.

Section 'A.3.1.3 Intel MKL' of the R Installation and Administration manual
covers that for the MKL case (and general OpenMP cases)

   The default number of threads will be chosen by the OpenMP software, but
   can be controlled by setting ‘OMP_NUM_THREADS’ or ‘MKL_NUM_THREADS’, and
   in recent versions seems to default to a sensible value for sole use of
   the machine.

The entire section makes for good reading, it mixes 'how to install MKL' with
'how to use MKL' and touches upon the parellism issue you have here.

Dirk

-- 
dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to