1function nthreads = threads (nthreads) 2%GRB.THREADS get/set the max number of threads to use in GraphBLAS. 3% 4% nthreads = GrB.threads ; % get the current maximum # of threads 5% GrB.threads (nthreads) ; % set the maximum # of threads 6% 7% GrB.threads gets and/or sets the maximum number of threads to use in 8% GraphBLAS. By default, if GraphBLAS has been compiled with OpenMP, it 9% uses the number of threads returned by omp_get_max_threads. Otherwise, 10% it can only use a single thread. 11% 12% Changing the number of threads with GrB.threads(nthreads) causes all 13% subsequent GraphBLAS operations to use at most the given number of 14% threads. GraphBLAS may use fewer threads, if the problem is small (see 15% GrB.chunk). The setting is kept for the remainder of the current MATLAB 16% session, or until 'clear all' or GrB.clear is used, at which point the 17% setting reverts to the default number of threads. 18% 19% MATLAB can detect the number of physical and logical cores via an 20% undocumented built-in function: ncores = feature('numcores'), or via 21% maxNumCompThreads. 22% 23% Example: 24% 25% feature ('numcores') ; % print info about cores 26% ncores = feature ('numcores') ; % get # of logical cores MATLAB uses 27% ncores = maxNumCompThreads ; % same as feature ('numcores') 28% GrB.threads (2*ncores) ; % GraphBLAS will use at most 2*ncores 29% % threads 30% 31% See also feature, maxNumCompThreads, GrB.chunk. 32 33% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 34% SPDX-License-Identifier: GPL-3.0-or-later 35 36if (nargin == 0) 37 nthreads = gbthreads ; 38else 39 nthreads = gbthreads (nthreads) ; 40end 41 42