How to use a variable value inside @tullio

I never thought to try this, but the reason it doesnโ€™t work is that values other than true/false are interpreted differently. The default behaviour does this:

@tullio y[j] = X[i,j] verbose=2
...
(Tullio.threader)(๐’œ๐’ธ๐“‰!, (Tullio.storage_type)(y, X), y, tuple(X), tuple(๐’ถ๐“j), tuple(๐’ถ๐“i), +, 262144, nothing)

where the argument 262144 is the macroโ€™s estimate of how big X must be to justify multi-threading, based on the function not containing log etc. Which threader then uses once the actual size of X is known.

The option threads=false replaces that with nothing, which disables threader completely. But anything else is assumed to be a different threshold:

@tullio threads=tf y[j] = X[i,j] verbose=2
...
(Tullio.threader)(๐’œ๐’ธ๐“‰!, (Tullio.storage_type)(y, X), y, tuple(X), tuple(๐’ถ๐“j), tuple(๐’ถ๐“i), +, tf, nothing)

So a possible hack would be to write threads=ts where ts == tf ? nothing : 100^2. But itโ€™s possible that this design ought to change.

Indeed, if you write @tullio threads=false at the top of the file, then all subsequent macro calls will use that. But these global macro options affect the parse-time behaviour, not the running of already-parsed code.

5 Likes